Always Write or Check & Write (For Digital Pins)? Energy Conservation

I’m issuing commands on a timer, but there’s no “event trigger” on my server when it’s time to issue the next command, and no verification that commands were received (aka “byzantine generals” problem). There’s just a “Right now it should be set to X” variable that is sent to the imp every 10 seconds.

I have two working solutions, and I’m wondering which one is more energy/battery efficient:

if( != desired_value)



I’m wondering if the overhead of the extra .read() is “costing” me anything, and how it’s cost would compare to writing a value that’s already been written.

In short: On a hardware level, does writing a 1 still cost me an electron if it was already a 1, and how many electrons does .read() cost me by comparison?

Just writing is fine - however, either case is totally dwarfed by the amount of power required to run wifi, tcp, tls and so on, ie it’s totally in the noise.

“Read and write if different” will be taking many more squirrel cycles (I’d say 3x) but when you’re doing this once every 10 seconds it’s hardly an efficiency concern.

If you’re trying to save energy, and don’t mind a latency impact, then setting wifi powersave mode (imp.setpowersave(true)) often gets you a 90% power saving on a quiet network.