foto Petr Bravenec

Petr Bravenec
Twitter: @BravenecPetr
+420 777 566 384

Last week I wrote an article about thermometer connected to BeagleBone.

BeagleBone is not very powerful computer and even it is possible, installing PGP and Apache for one simple page is overkill like sharpening toothpick with a chainsaw. So what web server should we choose?

Such simple tasks can be successfully performed with Swiss's army knife of small Linux distributions: Busybox. Busybox is used here as shell interpreter for all scripts and as a http server. Busybox is 100% sufficient for all reading, processing and publishing measured values.

The function is very simple. At first the content of file is read and the values are extracted, formatted and then strings XXX1 and XXX2 are replaced in the html template with real values. Resulted text is saved to ram disk. Why ram disk? Stay tuned on this channel, article about SD cards problems is already written and awaiting to be published (see: How to setup SD card for embedded system).

#!/bin/busybox sh

SED="busybox sed"
AWK="busybox awk"
SLEEP="busybox sleep"

while true
        XXX1=$($AWK -F "=" '$0 ~ /t=/ {printf("%1.1f\n",($2)/1000);}' \
                < /sys/bus/w1/devices/28-0000027d912e/w1_slave )

        XXX2=$($AWK -F "=" '$0 ~ /t=/ {printf("%1.1f\n",($2)/1000);}' \
                < /sys/bus/w1/devices/28-00000294d39a/w1_slave ) 

        $SED "s/XXX1/$XXX1/g; s/XXX2/$XXX2/g" \
                < /root/teplomer/index.html \
                > /dev/shm/teplomer/index.html

        $SLEEP 15


I have Gentoo distribution installed in my Beaglebone. I have all needed utilities here (sed, awk, grep and sleep) in their full version. But busybox contains functionality of all these utilities. In smaller systems (routers, book readers) the busybox is usually the only shell available and all utilities are emulated by busybox. No additional utilities are installed except the busybox. Only symbolic link with utility's name links to busybox binary. If I want to call the busybox's utility in my Beaglebone, I have to call busybox directly and as a first argument I have to write the name of the utility. In systems where only the busybox is installed and all other utilities are only links to busybox, the required utility can be called directly with its name.

Value reading is started in simple init script /etc/init.d/thermometer:


depend() {
    use logger

start() {
    ebegin "Starting thermometer"
    start-stop-daemon --start --quiet --pidfile /var/run/thermometer.pid \
        --background --make-pidfile --exec /root/thermometer/thermometer
    eend ${?}

stop() {
    ebegin "Stopping thermometer"
    start-stop-daemon --stop --quiet --pidfile /var/run/thermometer.pid
    eend ${?}

Busybox is so universal tool that it can work as a simple http server, too. Settings and start is made in other simple init script /etc/init.d/httpd-termometer:


depend() {
    use logger dns

start() {
    ebegin "Starting httpd-thermometer"
    mkdir -p /dev/shm/thermometer
    start-stop-daemon --start --quiet \
        --pidfile /var/run/httpd-thermometer.pid \
        --background --make-pidfile \
        --exec /bin/busybox -- httpd -f -p 80 -h /dev/shm/thermometer
    eend ${?}

stop() {
    ebegin "Stopping httpd-thermometer"
    start-stop-daemon --stop --quiet \
        --pidfile /var/run/httpd-thermometer.pid
    eend ${?}

The web server is started at the line:

/bin/busybox --httpd -f -p 80 -h /dev/shm/thermometer

I have to tell my Gentoo to start the scripts at system startup:

rc-update add thermometer default
rc-update add httpd-thermometer default

And that's all.

Hobrasoft s.r.o. | Contact