Measuring temperature using OpenWRT

See my x86 solution for measuring temperature here!

I’m using USB Temper devices again, but this time they are a newer revision, so the previous app with the source code I modified doesn’t work anymore. I downloaded this source code from here (look at the comments) and modified that so I can define from which USB bus and dev I want the temperature readings from. I had to cross compile this for the router (TP-Link MR3220) running OpenWRT. You can download my modified pcsensor source from here. UPDATE (2013/10/13): here’s an updated, cleaner code with a rewritten webpage.

First I needed the OpenWRT toolchain, which you can get by compiling the OpenWRT buildroot. Here’s a good tutorial how you can compile buildroot. There are also some notes in the OpenWRT wiki about cross compilation.

For the pcsensor app to work, I needed libusb 0.1. I downloaded the source code of v0.1.12, extracted it and created a script called doconfig in the libusb source code directory:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/bash
TOOLCHAIN_PATH=/home/nonoo/Work/openwrt/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.5-linaro_uClibc-0.9.32
export CC=$TOOLCHAIN_PATH/bin/mips-openwrt-linux-gcc
export LD=$TOOLCHAIN_PATH/bin/mips-openwrt-linux-ld
export NM=$TOOLCHAIN_PATH/bin/mips-openwrt-linux-nm
export CXX=$TOOLCHAIN_PATH/bin/mips-openwrt-linux-c++
export AR=$TOOLCHAIN_PATH/bin/mips-openwrt-linux-ar
export OBJDUMP=$TOOLCHAIN_PATH/bin/mips-openwrt-linux-objdump
export RANLIB=$TOOLCHAIN_PATH/bin/mips-openwrt-linux-ranlib
export STRINGS=$TOOLCHAIN_PATH/bin/mips-openwrt-linux-strings
export STRIP=$TOOLCHAIN_PATH/bin/mips-openwrt-linux-strip
export AS=$TOOLCHAIN_PATH/bin/mips-openwrt-linux-as
export CFLAGS=-I$TOOLCHAIN_PATH/include
export LDFLAGS=-L$TOOLCHAIN_PATH/lib
export STAGING_DIR=$TOOLCHAIN_PATH
./configure --host mips-openwrt-linux --prefix=/home/nonoo/Work/openwrt/opt

After running it, I created a domake file also:

1
2
3
4
#!/bin/bash
TOOLCHAIN_PATH=/home/nonoo/Work/openwrt/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.5-linaro_uClibc-0.9.32
export STAGING_DIR=$TOOLCHAIN_PATH
make $*

I ran domake; domake install and then I got the libusb libs under /home/nonoo/Work/openwrt/opt/lib. The STAGING_DIR variable you see above is needed for the toolchain compiler. I already added these cross compiling stuff to pcsensor’s Makefile. If you want to compile it on x86, just use my older Temper app’s Makefile.

libusb is needed on the router as well, so install it with opkg install -d pendrive libusb and run ldconfig.