Description
Basic Infos
- This issue complies with the issue POLICY doc.
- I have read the documentation at readthedocs and the issue is not addressed there.
- I have tested that the issue is present in current master branch (aka latest git).
- I have searched the issue tracker for a similar issue.
- If there is a stack dump, I have decoded it.
- I have filled out all fields below.
Platform
- Hardware: [ESP-12E|ESP-12F]
- Core Version: [2/26/19]
- Development Env: [Arduino IDE]
- Operating System: [Windows 10]
Settings in IDE
- Module: [Nodemcu v2]
- Flash Size: [4MB]
- lwip Variant: [v2 Higher Bandwidth]
- Flash Frequency: [40Mhz]
- CPU Frequency: [80Mhz]
- Upload Using: [SERIAL]
- Upload Speed: [2000000]
Problem Description
Hi Everyone,
I guess that i found a bug on the wifi related to power usage.
After few hours of testing multiple NodeMCU's i noticed that every code that not uses wifi has around 50mA/h power usage.
But to my surprise, one of my MQTT codes with WIFI_NONE_SLEEP hovers between 20 to 40mA/h, while the others had the same 50mA/h behavior.
The only difference was a delay(1); in the main loop, and yes, it was it.
First i thought it had something to do with the delay lowering the loop count, but then i came up with this test code:
MCVE Sketch
#include <ESP8266WiFi.h>
void setup()
{
WiFi.setSleepMode(WIFI_NONE_SLEEP);
WiFi.begin("network-name", "pass-to-network");
Serial.begin(2000000, SERIAL_8N1, SERIAL_TX_ONLY); //change if needed
while (!Serial);
}
void loop()
{
static uint32_t t;
t++;
static uint32_t timer_1 = millis();
if ((millis() - timer_1) > 1000)
{
Serial.print("LOOPS PER SECOND:");
Serial.println(t);
t = 0;
timer_1 = millis();
}
for (uint64_t i = 0; i < 5e4; i++); //simulate a big task (~62 ms)
delay(1);
}
With or without delay(1); the loop count is around 16/s, which is pretty low, and yet the same problem appears, 20-40mA/h with delay, 50mA/h without it.
delayMicroseconds and yield make no difference in this case.
If someone has a good ampere meter (mine isn't) and some free time i would appreciate some help.
And also, if i'm doing something wrong let me know.
Debug Messages
SDK:2.2.1(cfd48f3)/Core:unix-2.6.0-dev=-194000/lwIP:STABLE-2_1_2_RELEASE/glue:1.1-2-ga501b57/BearSSL:6778687
wifi evt: 2
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 6
cnt
connected with *******, channel 1
dhcp client start...
wifi evt: 0
ip:192.168.1.142,mask:255.255.255.0,gw:192.168.1.10
wifi evt: 3
LOOPS PER SECOND:17
LOOPS PER SECOND:16
LOOPS PER SECOND:16
LOOPS PER SECOND:16
...