RaspberryPi

domke edited this page Jun 29, 2013 · 19 revisions
Clone this wiki locally

The Raspberry Pi is a nice platform for running the host part of HexaBus on an energy-efficient system. Assuming that you have a working installation of Raspbian, perform these steps to compile the host software (Hint: The speed of your SD Card matters. Get at least a class 6 card.):

$ sudo apt-get install libboost1.48-all-dev git build-essential libsqlite3-dev cmake

Now delete the file /etc/modprobe.d/ipv6.conf. This will enable IPv6.

Install libklio

libklio is necessary for logging values. At the moment, you cannot compile the HexaBus host software without libklio.

$ git clone https://github.com/mysmartgrid/libklio.git
$ cd libklio
$ make release # This will build a deb package, suitable for installing with dpkg
$ sudo dpkg -i build/libklio-<VERSION>.deb

Install libhexabus

The libhexabus installation is similar to the libklio one:

$ git clone https://github.com/mysmartgrid/hexabus
$ cd hexabus/hostsoftware/libhexabus
$ make release
$ sudo dpkg -i build/libhexabus-<VERSION>.deb

Use the Raspberry Pi as a data logger

It is straighforward to use the RPi as a data logger. The hexaswitch package provides the hexalog tool, which can be used as an event logger.

TODO: Basic usage

Using the Daemontools to run hexalog automatically

You can follow the instructions of Robin and the documentation found at the Ubernauten (German) to get the daemontools up and running. In short:

$ apt-get install daemontools daemontools-run

Then, edit /etc/service to add the services you want under daemontool's supervision. I added a directory hexalog:

$ mkdir /etc/service/hexalog
$ cat <<__EOF__ > /etc/service/hexalog/run
#!/bin/sh
exec hexalog -s <STOREFILE> 2>&1 
__EOF__
$ chmod 1755 /etc/service/hexalog
$ chmod +x /etc/service/hexalog/run

TODO: Use setuidgid to drop privileges.

And for continuous logging:

$ mkdir /etc/service/hexalog/log
$ cat <<__EOF__ > /etc/service/hexalog/log/run
#!/bin/sh
exec multilog t /var/log/hexalog
__EOF__
$ chmod +x /etc/service/hexalog/log/run
$ mkdir -p /var/log/hexalog

Then, you can start the hexalog service using

$ svc -u /etc/service/hexalog

For each process, the daemontools process forks a supervisor, which takes care of restarting the service in the case where it fails. The process list looks like this:

$ ps faxu
22536  0.0  0.2   1720   532 ?        Ss   15:51   0:00 /bin/sh /usr/bin/svscanboot
22538  0.0  0.1   1672   372 ?        S    15:51   0:00  \_ svscan /etc/service
22688  0.0  0.1   1512   324 ?        S    16:25   0:00      \_ supervise hexalog
23410  0.2  0.8   4920  2240 ?        S    16:35   0:00      |   \_ hexalog -s /scratch/itwm.db
22689  0.0  0.1   1512   324 ?        S    16:25   0:00      \_ supervise log
23408  0.0  0.1   1524   312 ?        S    16:35   0:00          \_ multilog t /var/log/hexalog

The log file is then stored in /var/log/hexalog/current and rotated automatically:

$ tail /var/log/hexalog/current 
@4000000050251ede34f5461c Received a reading from fe80::ceb5:5a0b:200:0%usb0-3, value 25.0625
@4000000050251ee22a88fc14 Received a reading from fe80::b5:5aff:fe0b:20a%usb0-3, value 24.5438
@4000000050251eef113b9d0c Received a reading from fe80::b5:5aff:fe0b:20a%usb0-6, value 992.74

The @4000.... foo is a TAI64N timestamp. To convert it to an human-readable format, you can do something like this:

$ tail /var/log/hexalog/current | tai64nlocal 
2012-08-10 16:48:45.608689500 Received a reading from fe80::2ce:4200:70:428f%usb0-3, value 23.4375
2012-08-10 16:48:57.333629500 Received a reading from fe80::b5:5aff:fe0b:20a%usb0-6, value 992.7
2012-08-10 16:48:59.737227500 Received a reading from fe80::ceb5:5a0b:200:0%usb0-3, value 25.125

TAI64N timestamps are more exact than ordinary POSIX timestamps.