jonasbystrom / ESP-Now-Sensor-system-with-WiFi

ESP-Now is used for battery operated Sensors (based on ESP8266, ESP32) sending to a Gateway which also is connected with WiFi to the Internet (at the same time).
MIT License
37 stars 8 forks source link

Thoughts on further optimizing sleep power. #4

Open joeatbayes opened 10 months ago

joeatbayes commented 10 months ago

Your write-up and code are some of the best examples I have seen in either the Arduino or ESP ecosystem.

I have been working on my own power optimized designs. I didn't have a CPU module with low enough power consumption even with deep sleep so I used some other tricks. If you combine what I did with what you did it could provide even longer battery life.

Added a low-side mosfet switch to disconnect sensor power when sensors are not being actively used. Found this necessary for greedy sensors like magnetic field sensors and MPU6050. The CPU powers up the sensors by setting a IO pin HIGH to energize the gate on the N-channel mosfet. I use a 1 meg resistor gate to ground to force sensors off when the CPU is booting. As soon as I finish taking readings I turn of the sensors while the CPU may run a bit longer transmitting the data.

Added a DS3231 clock chip that includes alarm functionality that I use to facilitate power conservation. I wanted it for accurate multi-year time keeping but found that it added some features that make managing the CPU a lot easier like low-voltage reset. It is ultra low power and can run for years on a coin cell.

My sensors are not always in WiFi range so I write data to SPIFFS and send in batch once they can connect again. I extended this so I have a transmit interval that may be longer than my measure interval. Since it takes a little time with CPU active to negotiate the connection this can save a bit more power.

One downside of this approach is that any data you want to retain between wakeup events must be stored in SPIFFS because the CPU can not retain RTC variable storage when completely powered off. I read there is some NVM on this CPU but have not tried using it.

TD-er commented 10 months ago

You could also look into the Arduino "EPROM" library, which is just a mapping to some flash sectors. Thus you must do the administration yourself on when to erase blocks and preferrably allocate multiple blocks so you can 'page swap' what block to use next. SPIFFS can get corrupted when running low on power, so better use something that's so low-level you can control how to handle incomplete written blocks.