I was polishing the modules code during the holidays and I thought it was time to get a feeling of how using these modules in practice feels. So I set out to build a simple CO2 sensor that exposes the latest reading through a ReST HTTP interface.
The idea is to have one node, based on an Arduino, to measure the CO2 and send the readings to another node that provides the ReST HTTP interface. The first node would access the network trough a low power RF link while the second node would run on a Raspberry PI.
For the hardware I just hooked up an Arduino Nano, an NRF24L01+ breakout board and an analog CO2 sensor. The result can be seen in the picture. It’s not a work of beauty but that was not my aim. Also it’s powered from a USB wall-wart as I didn’t go and tweak the code for low power consumption for now.
As far as code is concerned I adapted the “ardunode” code to read the sensor and add the reading to the sent message. I didn’t make a specific application for the node in the “examples” folder has the “ardunode” code is still in need of lot of development. I then copied the skeleton python node “pynode” and implemented the message handling to parse the CO2 level from the message. I then added the ReST HTTP resource using “flask”. “flask” is a great library, with few lines of code the ReST HTTP server was up and running. The code is in Github in the examples folder under CO2_ReST_endpoint, in the development branch (here)
Overall the experience was positive, it took under one hour to wrap up the hardware and adapt the existing modules to a working contraption that is now reporting regularly CO2 readings from my room and can be accessed trough a ReST HTTP query.
Too bad the scheduler code in the Access Point is not ready yet, so I cannot run more than one node using the RAN as they would both end up in the same radio slot. But that’s work in progress! I was positively surprised anyway at the NRF24L01+ handling of the concurrent transmissions when I attempted to run two nodes, I always got consistently either the traffic from one node or another depending on which one was more near to the receiver. I haven’t found a spot where they would totally block each other or messages would be corrupted.