mruettgers / SMLReader

ESP8266 based smart meter (SML) to MQTT gateway
GNU General Public License v3.0
292 stars 68 forks source link

Battery powered operation / deep sleep (was: Great Work) #24

Open trosenda opened 3 years ago

trosenda commented 3 years ago

thanks for the code, it helped me to spot some strange electricity usage in my house. any idea when the sleep mode will be implemented ? my installation had to run on a power bank as there is no socket close to the meter. I would be fine with one telegram every 300 seconds.

thanks !

FluppFish commented 3 years ago

check config.h .interval = 300 is maybe the solution you are looking for... If you are not able to compile it by yourself i could send the .bin files to you..

mruettgers commented 3 years ago

Right now I don't have a clue when I will have the time to implement this feature. Configuring an interval won't help here, because the ESP8266 keeps running and thus consuming energy. Regarding the deep sleep feature I was thinking to switch over to the ESP32, because the power consumption in deep sleep is less than the one of the ESP8266 and because there is much more RTC memory available that could be used during deep sleep to cache measurements before sending them batched via wifi.

trosenda commented 3 years ago

That sounds very advanced! I was thinking of an easier (less detailed) way, really just waking up for like 10 seconds, going to sleep for 300. 1.8.0/2.8.0 is good enough for my use case, don't need much more

I am not famliar with yield().

Would a simple ESP.deepSleep(300e6); inside of void loop() do the trick already ?

Thanks for the reply!

On Wed, Jun 2, 2021, 22:49 Michael Rüttgers @.***> wrote:

Right now I don't have a clue when I will have the time to implement this feature. Configuring an interval won't help here, because the ESP8266 keeps running and thus consuming energy. Regarding the deep sleep feature I was thinking to switch over to the ESP32, because the power consumption in deep sleep is less than the one of the ESP8266 and because there is much more RTC memory available that could be used during deep sleep to cache measurements before sending them batched via wifi.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mruettgers/SMLReader/issues/24#issuecomment-853372931, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKYOFODQ7CDNMWRMYDCMVGLTQ2KNJANCNFSM452JHLPQ .

trosenda commented 3 years ago

quick test only, seems it wasnt it. any pointers where to start ?

mruettgers commented 3 years ago

It might work this way, but untested: https://github.com/mruettgers/SMLReader/compare/sample/hacky-deepsleep

But in order to make timer based wakeup work after putting the device into deepsleep you have to connect GPIO16/D0 to RST.

trosenda commented 3 years ago

Thank you. It goes into sleep and comes back (big challenge was to find a powerbank which doesnt turn off because off low current during sleep) I am unfortunately only receiving the following :

` 2021-06-13 11:47:48 MQTT2_DEVICE MQTT2_esp8266_02A548 info: Hello from 0002A548, running SMLReader version 2.2.0. 2021-06-13 11:47:48 MQTT2_DEVICE MQTT2_esp8266_02A548 LWT: Online

2021-06-13 11:52:53 MQTT2_DEVICE MQTT2_esp8266_02A548 info: Hello from 0002A548, running SMLReader version 2.2.0. 2021-06-13 11:52:53 MQTT2_DEVICE MQTT2_esp8266_02A548 LWT: Online

2021-06-13 11:57:54 MQTT2_DEVICE MQTT2_esp8266_02A548 info: Hello from 0002A548, running SMLReader version 2.2.0. 2021-06-13 11:57:54 MQTT2_DEVICE MQTT2_esp8266_02A548 LWT: Online`

mruettgers commented 3 years ago

Sounds like the ESP ist going to sleep too fast. Try to add a delay before the sleep command in a non-blocking manner (short delays of i.e. 10ms together with a yield call within a loop).

Somehow like this after the publish and before the sleep call:

for (uint8_t i = 0; i < 200; i++) {
  delay(10);
  yield();
}
trosenda commented 3 years ago

Excellent, coming close. running since a couple of hours, may need to increase the loop a bit, since I have 56 Info vs 44 1-0_1.8.0_255_value readings. so sometimes it sleeps to quick. 300 a good value or any other recommendation ?

but will have to wait until tomorrow before I can bother the handyman for roomkey again.

trosenda commented 3 years ago

The wemos with powerbank via usb was (obviously) drawing to much power. did now change to an ESP8285 powered by 4AA batteries (2S,2P) 10k or 4.7k pullup did not work, I went with 1k again.

mruettgers commented 3 years ago

In case it is still drawing too much power it might be an option to power the circuit with a LiFePO4 battery. Thus you can omit any LDO in between. In another project I'm running an ESP32 drawing about 10 μA in deep-sleep while directly connected to a LiFeP04 cell. With an LDO (and a LiPo cell, 3,7V) the circuit was drawing about 35 μA in deep-sleep.

trosenda commented 3 years ago

LiFePO4 would come by the cost of chargers etc. Let's see how long it will last on AA, I will report. BTW, no LDO, connected batteries directly to +3.3. Unfortunately my DMM dont allow for autorange between µA and mA, so I couldn't accurately measure.

mruettgers commented 3 years ago

Ah, I see. Btw., I'm using https://lowpowerlab.com/guide/currentranger/ for measuring, which is really cool. The serial logging option combined with auto-ranging allows me to write directly into an InfluxDB database and to analyze with Grafana.

trosenda commented 3 years ago

that's a very nice device. I have to resist spending so much money ;)

trosenda commented 3 years ago

The first set of batteries (4x Varta industrial AA) lasted from 20.6-2.7. not as long as I hoped for. I might need to invest into something like power ranger. My poor man measurement (guess work, really) showed 140micro amps during sleep.

mruettgers commented 3 years ago

That sounds like the LDO is drawing too much power during deep sleep. And that was one of the reasons I'm working with a LiFePo4 cell now (~7 µA in deep sleep for an ESP32).

Edit: Ok, you said you don't use any LDO, so there might be another issue. Do you use a plain ESP8285 or a complete board?

PS: I renamed the topic because other people might be interested in battery powered operation, too.

trosenda commented 3 years ago

WeMos lite. Batteries connected directly to 3.3. The second set lastet only till today, which is only 6 days. Didn't check yet (room key, handy man, etc), just saw I don't see any messages no more. Will see over the weekend if I get plain 8285, or invest into better current meter.

SBajonczak commented 3 years ago

Hi I use a lipo for another Projekt on a wemo d1 mini. This ging to sleep for the maximum sleep time (I think, it was 30 Minutes). I use this setup for measuring a beehive with an hx711 and several temp Sensors,but the runtime is about a month with a 3,7v lipo. In did Not Do any solder magic. But there are several "China" stuff that contains a uart in it. This Part consumes the most currency, and that was my Prior fail into this.

I am currently on my holdiay so that I can contribute only when I am at home.

Maybe you can attach a Puffer battery like the lipo, a cn365 (Red one) Solar charger and a Solar cell. Then it can run nearly forever?

lal12 commented 2 years ago

Did you experiment with the wifi sleep modes? The following is my experience for the ESP32, but to my knowledge and according to a quick research this should mostly be true for the ESP8266 as well.

There is WIFI_PS_MIN_MODEM, where the modem awakes every DTIM period and there is WIFI_PS_MAX_MODEM which sleeps longer (as configured). The latter one can cause issues with packet loss (which should be handled by the TCP layer) and in rare cases there are problems with some APs though I didn't had any issues with that. But even the MIN mode already decreases power usage quite a bit.

The WiFiClient.setSleep* methods are usable for that.