Arduino: Serial Chargen  

I wanted to test serial on my BeagleBone Black, so I need a source that would spit out a bunch of serial data. I wrote up a quick serial chargen script for Arduino. Now I have an endless source of serial traffic.

void setup() { Serial.begin(9600); } int offset = 0; void loop() { // Whatever string we want to spit out char* str = "abcdefghijklmnopqrtuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()"; int len = strlen(str); for (int i = 0; i < len; i++) { int char_num = i + offset; char_num = char_num % len; // Roll around the end if we go to far char c = str[char_num]; Serial.print(c); } Serial.print("\n"); offset++; if (offset >= len) { offset = 0; } }
Leave A Reply

BeagleBone Black: Barrel Connector Polarity  

The BeagleBone Black has a barrel connector to power the board if you don't want to use USB. Power input should be 5v, anything higher will fry your board.

It's not documented very well, but the polarity of the connector is positive in the middle, and negative around the edges. Look for this pictogram on your power supply:

power_supply_polarity_positive.jpg
Leave A Reply

BeagleBone Black: GPIO Pinout  

The BeagleBone Black has a lot of pins, and a lot of features. Of interest to me are the 65 user controllable GPIO pins, 8 PWM pins, 4.5 serial ports, and 7 analog pins.

bbb_gpio_pinout.png bbb_pwm_pinout.png.png bbb_serial_pinout.png.png
Leave A Reply

BeagleBone Black: USR Leds  

The BeagleBone Black includes four user controllable LEDs: USR0 through USR3. They can be controlled by going to:

/sys/class/leds/

In that directory are four directories, one for each LED. If you want to see what even triggers each LED look at the trigger file:

# cat /sys/class/leds/beaglebone\:green\:usr0/trigger
none nand-disk mmc0 mmc1 timer oneshot [heartbeat] backlight gpio cpu0 default-on transient

Note the brackers around heartbeat. The usr0 LED blinks a heartbeat to let you know the board is alive. You can disable this behavior and use it for something else:

echo none > /sys/class/leds/beaglebone\:green\:usr0/trigger

This sets the trigger to "none", and then you can turn on/off that LED with your own scripts:

echo 0 > /sys/class/leds/beaglebone\:green\:usr0/brightness # Off
echo 1 > /sys/class/leds/beaglebone\:green\:usr0/brightness # On

The BeagleBone Black has four user controllable LEDs that can be used in this fashion. More information can be found at elinux.org.

Leave A Reply

BeagleBone Black: Serial Login  

You can view the BeagleBone Black boot process, and login via a serial connection (with a TTL adapter) by connecting to the serial debug header. The pinout is as follows:

J1 = Ground
J2 = Not connected
J3 = Not connected
J4 = TXD
J5 = RXD
J6 = Not connected

Your serial port should be set for 8N1, with hardware flow control disabled.

I'm using a PL2303HX based USB to TTL converter, units like this can be purchased very inexpensively.

Leave A Reply

Fedora/RedHat persistent multicast route  

I needed to add a persistent (after a reboot) route for multicast. I created a file called /etc/sysconfig/network-scripts/route-eth0 and put this in it:

224.0.0.0/4 dev eth0

This says route the entire multicast section of IPV4 through eth0. This ensures that your IGMP requests go out the appropriate port.

Leave A Reply

Remove files created more than 30 days ago  

I wanted to find all the files in a certain directory that were created more than 30 days ago. I started with:

find /path/to/dir -ctime +30

This was finding directories also, so I added -type

find /path/to/dir -ctime +30 -type f

This listed all the files I wanted, so I just passed -exec

find /path/to/dir -ctime +30 -type f -exec rm {} +

The {} in the -exec is replaced with the file names found, so all the files are removed.

Leave A Reply

Perl: Increment a number in a text file  

I have a manifest file that contains a build_version=XX number field (among a lot of others) that I want to automatically increment. I found a simple Perl one liner that searches a file and does a search and replace that can perform some math.

perl -pi -e 's/(build_version)=(\d+)/"build_version=" . ($2 + 1)/e' manifest

In this example the /e in the regexp says that the replace value is an expression. In this case the replace value is some math that add adds one to the current value.

Leave A Reply

Vim: Launch Vim with a predefined search string  

I wanted to launch Vim with a search string already set. That way I could load my file, and just hit N to jump to that location.

vim myfile.txt +/search_text

Whatever you set search_text to, will pre-fill the search buffer.

Leave A Reply

Setting and reading file xattrs  

If your filesystem supports xattrs you can set metadata to be saved with your files:

touch foo
setfattr -n user.fave_food -v hotdogs foo
getfattr -n user.fave_food foo

You must save everything in the user. namespace though.

Leave A Reply

Using rsync to backup files as a non-root user  

I'm using rsync over SSH to do backups between two systems. When you run your backup as non-root user, you cannot save the files owner or group (uid/gid) because only root is allowed to change ownership. You can however tell rsync to store the owner/group in the file's xattrs. This requires that you mount your filesystems with user_xattr:

/dev/sdb1 /backup ext4    defaults,user_xattr        1 2

Then you tell the writing rsync to use --fake-super

rsync -avP --rsync-path='/usr/bin/rsync --fake-super' /src/dir backup-user@domain.com:/dst/dir

This example is a push backup, if it were a pull you'd put --fake-super on the local side. Then to do a restore you'd do the same thing in reverse with the reading side (where the xattrs are stored) getting --fake-user:

rsync -avP --rsync-path='/usr/bin/rsync --fake-super' backup-user@domain.com:/src/dir /dst/dir

You can see the attributes for a given file with getfattr:

getfattr -d *

# file: dovecot.index
user.rsync.%stat="100600 0,0 89:89"

If you don't get any output, there are no xattrs for that file.

Leave A Reply

MySQL Complicated subquery joins  

We needed to do two complicated (group by/having) queries, and find the common CustIDs between them. Easy way is to create a temporary table with the CustIDs from the first table, and then do an INNER JOIN against that temporary table on the select for the second table.

DROP TABLE IF EXISTS CustID;
CREATE TEMPORARY TABLE CustID (CustID Integer);

INSERT INTO CustID (CustID)
   SELECT CustID
   FROM ViewCircuitServices
   WHERE SvcID = 3 AND CircuitType = 'dsl'
   GROUP BY CustID
   HAVING count(SvcID) >= 2;

SELECT CustID, SvcID
FROM ViewCircuitServices
INNER JOIN CustID USING (CustID)
WHERE SvcID IN (2,9,25) AND CircuitType = 'dsl'
GROUP BY CustID;
Leave A Reply

Enable background consistency check with arcconf  

To enable the (recommended) background consistency check on an Adaptec card run:

arcconf datascrub 1 period 30

Where 30 is the amount of days you want the adapter to scan the entire driveset.

Leave A Reply

Interfacing with Oracle on the command line  

I wanted a command line client to access an Oracle server. sqlplus64 is the stock Oracle client. Connect to your server with the following command:

sqlplus64 username/password@//1.2.3.4/database_name

If you want to see all the tables in the current DB:

select table_name from user_tables;

If you want to see the field names/types of a given table

desc tablename
Leave A Reply

Linux: Determine the type of memory in your machine  

I needed to find out what type of memory I had in a server, without shutting it down and opening the case.

dmidecode --type memory
Leave A Reply