It’s time to start putting the pieces together now: sensor readout, scheduling of measurements and packet sends, and low-power mode. Looks like the code in the Ports and RF12 libraries is now making this easier than ever.
There’s a new roomNode.pde sketch which illustrates the whole shebang. At 145 lines, it’s a bit too long to include here in full, but I’ll show some of the interesting pieces.
Note that this version implements everything except motion reporting, which is a bit more complex.
Following the good ol’ top-down tradition, first the setup() and loop() code:
It starts the measurement loop, which then keeps itself running periodically. The report activity is started every once in a while. Note also the “now” variable, which will make it easier to use 2-byte ints in the logic which will decide later about when to report motion, etc.
The measurement code depends completely on what sensors are supported, and is pretty straightforward:
No surprises, we just have to be careful to do things in an energy-efficient manner. All the readings end up in the “payload” struct.
And here’s the reporting code:
Here’s some sample output on the serial port:
I still need to add the logic for motion detection, but with the new scheduling capabiltities, I expect that extra complexity to stay within a small portion of the code – unlike the current rooms.pde sketch, where everything seems to affect everything else.
The best part? My multimeter stays mostly under 60 µa, i.e. the low-power logic is automatically kicking in!