Yesterday’s post showed how to receive packets sent out by the “bmp085demo.pde” sketch, and report them back to the serial port. By reporting in the same format as the sender, this makes it possible to easily switch between a local direct-connect setup and a two-node wireless setup.
But there’s a bit of unnecessary complexity in there.
Note that I’m using the Easy Transmission mechanism, which is indeed easy to use – only four lines of C code is all it takes to turn a local node into a wireless node.
If you try out this setup, you’ll see that the receiver doesn’t always report packets, i.e. not every second. That’s not because it’s missing packets, but because the Easy Transmission mechanism includes logic to avoid sending anything if the data hasn’t changed.
There is a way to force sending packets with rf12_easySend.
But there’s another issue with this setup. The Easy Transmission mechanism uses acknowledgements and timers to make sure that all data arrives at its destination. If no ACK is received within one second, the data will be resent.
Trouble is, this is a bit silly: we’re sending out fresh readings every second anyway, in this setup! Why use timeouts and a retransmission mechanism, just to resend potentially outdated information in the first place?
This setup doesn’t need a retransmission mechanism, it adds no value.
In fact, we don’t even need ACKs: what’s the point of an ACK if the proper arrival at the receiver end doesn’t really matter to the sender? In this setup, the sender is going to send updated readings once a second anyway.
This is a clear case of overkill, so let’s simplify. Here is the improved sender:
It’s not shorter than before, because the rf12_easy* functions really are indeed quite easy and compact. But the code size is reduced a fair bit:
(Much of the remaining code size is due to the code needed for the BMP085 pressure calculations)
And here’s the receiver, which no longer sends ACKs:
The difference in size is due to no longer loading any transmit code:
More importantly perhaps, the receiver now reports readings once a second, including unchanged ones:
… and of course, that – without the ACKs – there will be about half as many packets flying through the air.
The moral of this story is: don’t include functionality if it doesn’t serve a need!