Freitag, 20. Januar 2012

A package for sensor data

As mentioned earlier, i thought on how to transport the sensor data my wireless nodes gather.

As i want the nodes to be able to run from battery power, they should consume as few energy for transmitting data as possible. While my former experiments with TCP/IP were pretty exciting (its awesome that you can run a website wirelessly off an 10€ battery driven uC!) its hard to get a node to become a low power device once you have to take care of all the TCP/IP protocol stack.

So i switched to a very basic network layer, based on the RFM12 lib. When there is data to transmit, it is packed to a simple protocol structure and transmitted over the air as bytestream. I wrote a little class to do all the packing and unpacking work named RadioNodePdu.

Each measurement is represented as the following datastructure:


So for each measurement reading, we have its type (as 8 Bit int) and its value (as 16 Bit int). As a header we then just add the ID of the sending node and pack all to a compact linear bytestream:


This bytestream then is transmitted to the accesspoint, which then decodes it and translates it back to the sensor data. As the length of each channel structure stays the same, we can very easily get the number of channels from the received bytestream:


The single channels then can be accessed very easily by their offsets:


After the data is received by the accesspoint, its receive is acknowledged and then it is converted to a JSON string and posted to my monitoring server via a HTTP POST request. Then a PHP skript jumps in and does the further processing of the data.

The nice thing about this is, that with the type of data transmitted, my monitoring system can automatically "learn" the new channels, once a new node goes online. It creates a new "datafeed" and automatically assigns the correct physical unit and scaling factors to the measurement data, so you just have to name the channel.

Next processing steps can follow!

1 Kommentar:

  1. Zerbreche mir da auch gerade den Kopf - Dein Ansatz gefällt mir gut. Das Format sollte auch für viele Aktoren geeignet sein.

    Ich hatte zusätzlich eine CRC und ein Byte für die Paketgröße vorgesehen. Später wollte ich noch eine Signatur zum Schutz gegen absichtliche und unabsichtliche Störer einbauen. Das scheint mir noch wichtiger als Verschlüsselung zu sein.

    Freue mich auf Deine weiteren Berichte!

    Viele Grüße, Matthias

    AntwortenLöschen