Guys,
I've spent most of today implementing an idea I've had ready for some time. This solves a big issue for me so I thought I'd share it.
My battery driven nodes sleep most of the time. Once in a while they become active, measure and send the results to the gateway. The gateway ack's back potentially with a command which allows me to manage these nodes even though they're mostly asleep.
Some of my nodes measure very slow data - for example the sewage pit level or the lake water temperature. For the pit one measurement per hour is more than enough and for the water thermometer once every 10 minutes is sufficient. This allows the battery to last pretty much indefinitely - the estimated battery life for the sewage pit Moteino is around 20 years on 4x AA
.
Now the downside is I need to wait for an hour to send commands to the sewage pit - no fun for an impatient person. So I'd like these nodes to actively listen for commands instead of only using ack's from the server. But I don't want to spend battery on that.
Enter the Listen mode of the RFM69HW - a topic that's been discussed a bit here. I combined this with some of the lessons I've learned in my wireless boot project:
The listen mode uses a duty cycle that can be defined over a broad range. Naturally I wanted a very low duty cycle to save power. On the other hand you don't want the process to take forever. So the client should never miss a packet that gets sent.
That requires that there be no gap in the transmission to the node which can be achieved using the same method I've used in the bootloader: not switching back to standby mode after transmitting packets. In that case the radio stays on leaving a continuous signal the client node can detect.
I'm now using a duty cycle of 0.64ms : 2620ms which means that the incremental power use of this scheme is largely negligible.
This mode (not switching to standby from tx) is a bit tricky. For one thing it doesn't work with encryption. Additionally PACKETSENT stays true after the first packet is sent successfully - so it requires hand tuned delays for additional packets.
But the end result is very nice: Within 3 seconds I can now access any node and it's pretty much free in terms of power budget. Check out the code attached and let me know what you think.
Usage:
Client:
call startListening to enter listen mode.
sleep the moteino
on wake up call receivedBytes to see if anything arrived
call clearBuffer to be ready for the next transmit
call endListening to end listening mode. Afterwards reinitialize the RFM69 library to restore its settings.
Server:
call send to transmit to the client
Afterwards reinitialize the RFM69 library.
Joe