Wednesday, March 28, 2012

Modem fails to respond at long intervals

The Option Icon 322 USB modem fails to respond to at commands at long intervals, and causes timeouts when waiting for a response to an at command, which are detected using the 'catch' command and causing my program to exit. When this happens, stopping and restarting the program does no good. The second restart always fails at the open() call, and by using 'fuser' ('fuser /dev/ttyHS0) it appears that the program has opened the modem, but gets stuck at a tcsetattr() call, according to the stack trace when I attach 'gdb' to the process. But, running minicom seems to restore correct operation. What does minicom do that the program does not do? If I can find out I can at least restart the program successfully. I would of course like to be able to reset the modem to restore it, but I can't figure out what does that, other than somehow (modprobe -r) deactivating the usbserial module and reactivating it.

To find out I ran both ('tclsh beaglegsm.tcl' and minicom) using 'strace' to trace system calls. Except for the open call, both do the same things regarding protocol in sending 'at' commands. The open call for minicom uses the switches:

 open("/dev/ttyHS0", O_RDWR|O_NOCTTY|O_NONBLOCK) = 3


while beaglegsm.tcl uses:

 open /dev/ttyHS0 RDWR

I programmed the open in tcl to use these same flags as minicom, and I'm now testing this arrangement:

open /dev/ttyHS0 {RDWR NOCTTY NONBLOCK}

Wednesday, March 21, 2012

Starting my Program as a Daemon

As an interim test, to run a monitor program as a daemon so I can log off and disconnect the Beaglebone from the net without killing the program, I used the start-stop-daemon command as follows:

root@beaglebone:~/tcl-from-beaglebone/tcl# start-stop-daemon -S -b \
         -x /usr/bin/tclsh -- beaglegsm.tcl

The program is a Tcl script, beaglegsm.tcl,  in a subdirectory of root. I give the full path to the tclsh command, but only the relative path to the script. The -b switch runs the program in the background. The -S switch says start the program. It seems to know whether one is already running and does not start a new one if so.

To stop the daemon use the -K switch:

root@beaglebone:~/tcl-from-beaglebone/tcl# start-stop-daemon -S -b \
         -x /usr/bin/tclsh -- beaglegsm.tcl

So I can start the daemn at boot time so it runs without needing to log on, I'll either put it in a cron entry (use @bootup for the time specification) or as a script in the /etc/init.d directory.

The program quits sometimes, without complaining, so I added a &>beaglegsm.out to the end to try and capture stdout and stderr for later analysis.

Terminal (sh) Sessions on Beaglebone from PC

Here are two ways to get a terminal shell (sh) session going on the Beaglebone board.without using the USB-based serial interface.

Ethernet or Network Via USB 

If you don't have a spare ethernet port on a router, you can establish a network connection between the Beaglebone and a PC using a network simulator over a USB connection.

Simply plug the beaglebone in to the PC using the USB cable using the USB client (mini USB connector on the board.) Let it boot up. It will appear as a mass storage device on the PC. The network interface will automatically be established after unmounting (ejecting) this Beagleboard mass storage device under Windows.

Method 1: This is fast

From Linux use ‘ssh root@192.168.7.2
Password is not set, so just hit enter when asked. Here’s an example:

john@john-ThinkPad-T42:~$ ssh root@192.168.7.2
root@192.168.7.2's password:
root@beaglebone:~#

From Windows, use the PuTTY client.

Method 2: This is very slow
.

Using Gate One server on board, accessed from web browser as url 192.168.7.2, at https://192.168.7.2/, at prompt enter 192.168.7.2. Then hit enter at ‘port 22’ question, then enter ‘root’ at user question. You should get a normal terminal session prompt.

Beaglebone Cost and Source

The board I received is marked “A5”, and the microSD card with the software is dated 2-14-2012. Cost was around $89 from Digi-Key. Came with USB data and power cables, microSD card with software, Altoids box.

What this is About

I bought a Beaglebone embedded Linux single board computer for use with my SMS-based home monitor, which has its own blog. That monitor originally used a combination of an ancient Asus netbook and an Arduino single board computer, along with an Option Icon 322 GPRS GSM modem. I hope by using the Beaglebone for both these functions I can reduce power and cost, while increasing reliability.

Here's a picture of a Beaglebone from the website:



The home monitor was designed to communicate strictly using text (SMS) messages, so it is useful where there is no internet service, and low-cost if used with large quantity text message plans, such as the AT&T 1000 messages for $10/month. Since it can send and receive text messages, it can tweet (which it currently does), and can reply to emails with commands to set up monitor functionality, such as reporting period and alarm actions, as well as turn on and off external appliances.

This blog is where I'll log my experiences with the Beaglebone.