With the RF12Demo sketch running on a TinySensor permanently hooked to my Raspberry Pi, my next step was to be able to capture the RFM12B packets that are being sent by various remote sensors in my home. Using the minicom terminal program on the Pi allows me to even send data packets with whatever content I want to other nodes from the serial console.
So what we have on the serial console when the RF12Demo sketch is running is a series of numbers whenever a packet is received. The meaning of these numbers depends on the data structure that the remote sensor is sending, here is a good post by JCW describing that.
I decided to do the capturing, decoding and posting to emoncms with PHP, not an optimal solution, but I am familiar with it. I’d rather do this with a perl script, but I need some more self-educating to do. The PHP script uses the PHP serial library available here to do its job. I have found that the library works good for receiving and not so good with sending data. The TinySensor works just fine with the minicom terminal program, but I can’t make it send data with the PHP serial library yet.. So my solution will be just to read from the RFM12b, decode and post to emoncms for the moment.
The code for that is pretty much trivial, we scan the serial port for incomming messages. The first byte of the message identifies the sending node, so we can expect what the rest of the bytes mean knowing who is sending them. Using the pack/unpack PHP functions we put back a data structure based on the incoming bytes and make a HTTP get to emoncms with the values extracted from the incomming message.
To have the script run in the background as a deamon, I use “sudo nohup php serial.php &”. To stop it, you must find the processID with “ps -A” and “kill” it.
The PHP code is available on github here
Here is a screenshot of it running
As a to-do remains that I re-write the gateway script in PERL and make it bi-directional i.e. the Pi will send the current time to remote nodes upon receiving a data packet from them.
This setup makes a complete in-house monitoring system, including storing the data.
Page views: 5755