random hax

AREXX TL-500 logger on Linux - contributed fixes

Users at the german AREXX forum have contributed fixes for the simple logger program posted here a year ago. The program has now been tested with the following sensors:

- TL-3TSN temperature sensor
- TSN-EXT44 temperature sensor with external probe
- TSN-33MN waterproof temperature sensor
- TSN-TH70E temperature/humidity sensor

Fixes include support for sub-zero temperatures and accurate humidity values above 60 RH%, as well as improved start-up time and libusb API usage. The program has been reported stable on FriendlyARM Mini2440 (ARM9) and Marvell SheevaPlug (ARM5) boards.

Refer to this post for download and installation instructions.

AREXX has released a libusb based rf_usb_http Linux utility on their download page. Unfortunately the distribution only includes a i386 binary without source code so it is of little value to users with embedded systems.

FriendlyARM Mini2440 + AREXX TL-500 temperature logger on Linux

Some notes on how to connect the AREXX TL-500 temperature logger system to Linux hosts. Example includes instructions for use with the FriendlyARM Mini2440 ARM9 development board.

As AREXX only provides Windows drivers for the TL-500, accessing it from Linux is not quite straightforward. The TL-500 does not use a generic transfer protocol like FTDI, so we are left with a plain and undocumented USB protocol.

Kornelius Rohmeyer analyzed the USB traffic and wrote up an usblib based example for accessing the TL-500 on Linux, read up on it here:

http://algorithm-forge.com/techblog/2010/01/linux-usb-driver-for-the-arexx-tl-500-part-ii/

Based on his work it was easy enough to write up a crude but usable data collecting program polling and logging TL-3TSN, TSN-33MN and TSN-TH70E temperature and humidity sensor values. Includes support for hot (un)plugging of the TL-500 as well as output formatting and timestamping.
$ wget http://m68k.org/ul/tl-500-0.7.tar.gz
$ tar xfvz tl-500-0.7.tar.gz
$ cd tl-500-0.7
$ make
gcc -Wall -g -c -o tl-500.o tl-500.c
gcc -lusb-1.0 -g -o tl-500 tl-500.o 
$ ./tl-500
Found AREXX TL-500 on USB bus.
2010-03-04 00:40:43 11600 3447 26.9 C
2010-03-04 00:41:13 11807 3431 26.8 C
2010-03-04 00:41:33 11639 3439 26.8 C
..
The diagnostics line goes to STDERR, the output format on STDOUT is:

yyyy-mm-dd hh:mm:ss <sensor id> <raw value> <temperature> C

The latest sample of each sensor is stored in /tmp/tv-500_<sensor id> files.

Use with the FriendlyARM Mini2440 board and the default qtopia linux installation requires crosscompiling and installing libusb 1.0. Example using the GNU Toolchain sgpp compiler.

Extract toolchain into /usr/src/mini2440/arm-2008q3 and set up the build environment.
$ TOOLCHAIN=/usr/src/mini2440/arm-2008q3
$ PATH=$PATH:$TOOLCHAIN/bin
$ CC='arm-none-linux-gnueabi-gcc -march=armv4t -mtune=arm920t'
$ CROSS_COMPILE=arm-none-linux-gnueabi-
$ export CC CROSS_COMPILE
Grab a copy of the usblib source, crosscompile and install the ARM library into toolchain.
$ tar xfv libusb-1.0.6.tar
$ cd libusb-1.0.6
$ ./configure --host arm-linux
$ make
$ cd libusb
$ cp libusb.h $TOOLCHAIN/arm-none-linux-gnueabi/libc/usr/include/
$ cp .libs/libusb-1.0.so $TOOLCHAIN/arm-none-linux-gnueabi/libc/armv4t/usr/lib/
Now rebuild tl-500 to crosscompile and copy the ARM binary along with the fresh libusb-1.0.so to the FriendlyARM board and you got yourself a nifty thermometer. The TL-3TSN and TSN-33MN sensors appear to be quite accurate and well calibrated for the price.

Combined with 3G connectivity for the board the logger data can be accessed over the net.

FriendlyARM Mini2440 + Huawei E160 HSDPA USB modem

Brief description of how to hook up a Huawei E160 HSDPA USB modem to the FriedlyARM Mini2440 ARM9 development board without breaking a sweat.

The Linux kernel preinstalled on the board does not have the ppp driver, so the first order of business is to recompile and replace the kernel. Fetch the prepared kernel source package:

linux-2.6.32.2-mini2440_20100113.tgz

Extract and add the following options to the configuration matching your device, say config_mini2440_t35 for the common 3.5" display model:
CONFIG_PPP=y
CONFIG_PPP_MULTILINK=y
CONFIG_PPP_ASYNC=y
CONFIG_PPP_SYNC_TTY=y
CONFIG_PPP_DEFLATE=y
CONFIG_PPPOL2TP=y
Configure and compile the kernel using the GNU Toolchain sgpp compiler:

arm-2008q3-72-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2

Extract into /usr/src/mini2440/arm-2008q3 and set up the build environment.
$ PATH=$PATH:/usr/src/mini2440/arm-2008q3/bin
$ CC='arm-none-linux-gnueabi-gcc -march=armv4t -mtune=arm920t'
$ CROSS_COMPILE=arm-none-linux-gnueabi-
$ export CC CROSS_COMPILE
Configure by loading your modified configuration file into menuconfig, then build the lot.
$ make ARCH=arm menuconfig
$ make ARCH=arm -j4
Copy the new kernel/arch/arm/boot/zImage kernel image to the board. This can be done by writing a raw image over the old one using the "[k] Download linux kernel" BIOS option. No need to format the NAND or fiddle with u-boot.
Enter your selection: k
USB host is connected. Waiting a download.

Now, Downloading [ADDRESS:30000000h,TOTAL:2562214]
RECEIVED FILE SIZE: 2562214 (500KB/S, 5S)
Downloaded file at 0x30000000, size = 2562204 bytes
Found block size = 0x00280000
Erasing...    ... done
Writing...    ... done
Written 2562204 bytes
At this point the board should boot just as happily as before, now with a fresh kernel with both /dev/ppp and /dev/ttyUSB0 support.

Connect the E160 to the USB hub of the board and check that the kernel says something like:
usb 1-1: New USB device found, idVendor=12d1, idProduct=1003
usb 1-1: Product: HUAWEI Mobile
usb 1-1: Manufacturer: HUAWEI Technology
usb 1-1: GSM modem (1-port) converter now attached to ttyUSB0
The preinstalled qtopia does not include any userspace tools for dialing or mangaging ppp connections. Rather than compiling all of wvdialer you can pretend it's 1993 all over and just use pppd + chat compiled from source:
$ wget ftp://ftp.samba.org/pub/ppp/ppp-2.4.5.tar.gz
$ tar xf ppp-2.4.5.tar.gz
$ cd ppp-2.4.5
$ ./configure
$ make
$ file pppd/pppd
pppd/pppd: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.14
Copy the pppd and chat binaries to /usr/sbin/ on the board, and create the /etc/ppp/ directory for the configuration and control scripts. Use the defaults from the pppd scripts/ directory and modify to match your ISP. These work for the finnish Saunalahti operator:

/etc/ppp/ppp-on:
#!/bin/sh

DIALER_SCRIPT=/etc/ppp/ppp-on-dialer

route del default 2>/dev/null
exec /usr/sbin/pppd debug lock modem crtscts /dev/ttyUSB0 9600 \
    asyncmap 20A0000 escape FF kdebug 0 0.0.0.0:0.0.0.0 \
    noauth noipdefault netmask 255.255.255.0 defaultroute connect $DIALER_SCRIPT
/etc/ppp/ppp-on-dialer:
#!/bin/sh

exec chat -v \
        TIMEOUT       5 \
        ABORT         'BUSY' \
        ABORT         'NO ANSWER' \
        ''            'ATZ' \
        'OK'          'ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0' \
        'OK'          'AT+CGDCONT=1,"IP","internet.saunalahti"' \
        'OK'          'ATDT*99#' \
        'CONNECT'     ''
Replace internet.saunalahti and *99# with whatever your ISP requires, add CPIN to the initialization if needed. Execute /etc/ppp/ppp-on and check /var/log/messages for output like this:
Sep 17 16:43:59 pppd[773]: pppd 2.4.5 started by root, uid 0
..
Sep 17 16:44:02 chat[775]: ATDT*99#^M^M
Sep 17 16:44:02 chat[775]: CONNECT
Sep 17 16:44:02 chat[775]:  -- got it
..
Sep 17 16:44:02 pppd[773]: Connect: ppp0 <--> /dev/ttyUSB0
For manually testing and debugging the chat script you might want to install a terminal like picocom:
$ wget http://picocom.googlecode.com/files/picocom-1.4.tar.gz
$ tar xf picocom-1.4.tar.gz
$ cd picocom-1.4
$ make
That's it.