Saving power on an ESP8266 web server using delays
tablix.org
tablix.org
The `delay(1)` triggers the "Automatic Modem Sleep" mode, which keeps the WiFi connection alive. It should draw about 15-16 mA, which is pretty close to the 18-24 mA measured in the TFA.
The WiFi radio consumes a lot of power. During initialization, I believe it can consume 500 mA or more. In normal usage, WiFi apparently has a continuous drain of ~70 mA. If WiFi is not needed, the ESP8266 can be placed into "Forced Deep Sleep" mode, with an idle current of 0.02 mA. Using a ~2000 mAh battery (e.g. 3xAA NiMh, or 1x18650 Li-Ion), that means over 11 years on battery, if no other work is performed. The lowest current that I have measured personally is 0.04 mA on various ESP-01 modules. But that still means about 5.5 years on a single charge.
If the WiFi is needed only intermittently, the ESP8266 can be placed into "Forced Deep Sleep" mode, with the internal RTC configured to wake it up after a certain time, e.g. 15-30 minutes. It can then connect to WiFi, transmit the data payload, then go back to Deep Sleep again. Unfortunately, the ESP-01 module does not support this (without hardware hacking), because it does not expose the GPIO16/D0 pin necessary to trigger the RESET.
Other ESP8266 dev boards (e.g. D1 Mini, NodeMCU) do support waking up from Deep Sleep. But these dev boards often contain a voltage regulator which consumes a quiescent current. On my D1 Mini boards, I get about 0.22 mA in Forced Deep Sleep mode. In theory, that's enough for 1 year of life on a single charge of a 2000 mAh battery. But waking it up every 15 minutes, for 5-6 seconds of WiFi time, reduces the battery life to about 4-5 months. At this point, the active power usage during the 5-6 seconds of WiFi is already 2X the power consumption of the 15 minutes of Deep Sleep, so I have not attempted to reduce the idle consumption any further.
Average less than 4 seconds.
If rssi is extremely low then it will def take longer.
Yea the voltage regulator is very important and the ones on the nodemcu have very high quiecient current. Also on the top end you have to look for regulators that can handle the ~500mA peak current too.
Otti Arc or Nordic PPk2 is an invaluable tool!
I think I remember measuring the NodeMCU with a higher Deep Sleep current than the D1 Mini, but I don't remember what that value was.
The other thing I forgot to mention that consumes current is the USB-Serial converter on boards like the D1 Mini and NodeMCU, but not present on the ESP-01. I don't know which consumes more, the voltage regulator or the USB-Serial converter.
I do recall the d1 mini having a really low quiescent current.
Yea the converters can also take up power I separate that and place it on a jig.
Anyone trying to do wireless with low power should be using other protocols. Zigbee, Bluetooth, Z-Wave, ANT... anything but WiFi. I mean, WiFi just wasn't designed for low-power like these other protocols.
Hell, you might do better with LoRa (long-range, ~3-miles) signals than WiFi.
> Other ESP8266 dev boards (e.g. D1 Mini, NodeMCU) do support waking up from Deep Sleep. But these dev boards often contain a voltage regulator which consumes a quiescent current. On my D1 Mini boards, I get about 0.22 mA in Forced Deep Sleep mode. In theory, that's enough for 1 year of life on a single charge of a 2000 mAh battery. But waking it up every 15 minutes, for 5-6 seconds of WiFi time, reduces the battery life to about 4-5 months. At this point, the active power usage during the 5-6 seconds of WiFi is already 2X the power consumption of the 15 minutes of Deep Sleep, so I have not attempted to reduce the idle consumption any further.
Have you tried going even slower? You can cut your current usage in half by going every 30-minutes, and then in a quarter by connecting every 60-minutes (etc. etc.) until your current consumption is as low as you want.
There are practical limits (is one connection per day sufficient?), but 15 minutes still has some leeway depending on the application.
If you need low-power but still wireless and more updates than that... having a faster-to-initialize and lower power usage to boot (10mA for those 30ms, rather than for 100mA for 2000mS), you'll grossly cut down your power consumptions.
With WiFi, I don't need any other technology stack, no hubs, no bridges. I can use my existing network infrastructure. The data packets from the ESP8266 devices get delivered directly to the MQTT broker over TCP/IP over WiFi. It's cheap (~$3 for a D1 Mini), dead simple, and good enough.
Every 15 minutes seems about right for temperature/humidity sensors. Increasing it beyond 15-30 minutes becomes a diminishing return, because at that point, the Deep Sleep power usage becomes greater than active WiFi usage.
Still though, WiFi's specs are pretty awful. It bothers me to see such huge numbers whenever people talk about WiFi. And since we're in tiny microcontroller land, its not like any of us are actually tranferring GBs or MBs of data. We're all just passing a few kB, so much slower protocols (ex: Zigbee) are very reasonable.
Things start to get silly below the 500uA levels anyway. You start worrying about aluminum capacitors with 22uA leakage current and such... and realizing you need to upgrade to Tantalum capacitors with specified 2uA or 1uA leakage.
If you want higher time resolution, there are several fully integrated hall effect current measurement ICs out there, like for example the ACS723.
If you need even better accuracy or resolution and you can spare 100 bucks, just buy one of the Nordic Power Profiler Kits.
There are special resistors for this purpose that are very low in resistance.
Hell, that's actually very easy way to make ADC, just start counting, charge cap to pre-determined value then trigger counter stop. There are few improvements to that technique (like dual slope ADC, where you use reference voltage to discharge the cap to get the ratio between reference and input signal) but in general it can be very accurate way to measure.
The data acquisition is kinda a bitch if you want to measure accurately over long time, small IoT device can take microamps when idle and tens of even hundred+ mA when transmitting and that's 4-5 orders of magnitude of dynamic range and that's kinda hard to deal with accuracy
https://www.joulescope.com/ handles most of that edgecases but it's a pricy piece of kit if you just want to do some measurements and are not using it to make actual product.
Most of the time you care about the current only. Now if you actually want power over time, that is energy. in that case you would need some logging, and sampling
If you're off of battery power or USB power instead, you'll need to build a current-sense circuit. Analog wise, its very simple: a small 0.01 ohm resistor (called a "current sense resistor") is placed in series, and you measure the voltage drop across it. 0.0001 V across a 0.01 ohm resistor -> V / R -> 0.0001 / 0.01 == .01 Amps == 10 mA being drawn.
Now the question is "how do I measure 0.0001V accurately" ?? And that's a trivial op-amp problem. So trivial, that people sell cheap chips that already do this for you, called current-sensing amplifiers. They just multiply the voltage by 200 accurately. (so 0.0001V into the amplifier comes out as 0.02V), and 0.02V can be measured by pretty much anything.
https://www.digikey.com/en/products/detail/ohmite/MCS1632R01...
https://www.digikey.com/en/products/detail/onsemi/NCS199A3RS...
Voltage-multipliers though are a trivially easy OpAmp circuit, and I'd recommend that beginners actually try to build their own current-sense amplifiers from scratch. Its good to learn how to use OpAmps, and learn all the issues (ex: Rail to Rail, positive / negative voltages, etc. etc.). I'd recommend you do a 9V project with the LM358.
Staying in the analog world alone, you can output the voltage into a 555 Timer, and then have it flash an LED every time the capacitor filled up (and the discharge would also dump the capacitor). For example.
Or you could just wire it up to a microcontroller and busy-loop ADC-convert the input. So you can perform the "integral / summation" in microcontroller / in C-code rather than circuit magic.
The important tidbit is that we've turned 10mA current into a value we can "touch" and use. Hell, maybe the easiest solution is to just hook up a wire somewhere and shove an oscilloscope there to finish things off, depending on how lazy you wanna get.
-------
I know one professional chip did Opamp Integral -> Comparator (if integral is full, dump the charge to ground. If +V, do register++. If integral was full of negative voltage, do register--).
Then, whenever the register overflowed, it'd generate an interrupt edge on its output (for both overflow or underflow). Alas, I forgot which chip did this. But this way, you could build all your stuff out of 100kOhm resistors, 10nF capacitors, tiny digital logic circuits with micro-amps of power usage that wakes up your microcontroller out of sleep for just a "Current_Reading++" statement on overflow and you go back to sleep. (or current_reading-- on underflow)
But that's all advanced stuff that probably doesn't matter for a student making their first practical OpAmp circuit :-)
Then we repeat it using resistors instead, until we match the discharge rate exactly.
Then measure the resistor and do I=V/R, using the midpoint V. That accounts for all the surges and eliminates most error sources, giving you a nice and extremely realistic average current draw.
Like others mentioned it is a about measuring voltage*current.
I found this video for low power DC measurements helpful as well https://www.youtube.com/watch?v=LUB8RWzzLWc&t=15s or for AC Power Meter https://www.youtube.com/watch?v=QXNlsawaYEg&t=868s