dalehumby / powermeter

ESP8266 + MicroPython project to record household power usage
MIT License
2 stars 0 forks source link

Freeze after power outage - Battery Backed up #2

Open Zodiac-69 opened 3 years ago

Zodiac-69 commented 3 years ago

I have been using your design for about two weeks now, and it has been working very well I am powering the ESP8266 from a Buck/Boost unit MH-CD42 to make sure i don't miss any counts after a power outage. We had "load shedding" last night as you know - RSA - and this morning i noticed that HA is not showing the value. I tried to connect to the unit on the main page and the /metrics page without success, had to reboot. HA and my WiFi are connected to a UPS, so it is always on. The power outage was at 02:06 and the last value was sent at 02:07 Any idea why the unit will freeze? I had to press the reset to get it up and running again.

dalehumby commented 3 years ago

Hi @Zodiac-69. Thanks for getting in touch. Yeah, the loadshedding is a pain...

I have similar issues with my uPython ESP8266's and ESP32's - they seem to lock up after a power outage, such as forgetting to add electricity to my prepaid meter, or loadshedding. uPython doesn't support the ESP's hardware watchdog timer, which would reset the CPU if it locked up. I have implemented my own software watchdog using uPython timers, but even that doesn't seem to solve the problem.

Are you running your ESP8266 on a battery through the MH-CD42? (ie as a UPS for the ESP?)

From this article it appears that the CD42 is an Injoinic Technology IP5306, an IC used in USB power bank. Those ICs, when running off wall power typically bypasses the battery; and when there is a power failure it switches over to the battery which takes a few milliseconds. During that time the 5V rail may drop and brownout the ESP, locking it up.

I had a similar issue running my Raspberry Pi (for HA) on a generic 10,000 mAh power bank, and it locked up each time, until I replaced it with a PiJuice hat (The standard battery only last ~1 hour, so I'm considering a larger battery.)

If I were redoing this project today I would strongly favour using ESP Home (See this cookbook). Maybe not as much fun as writing it in uPython, but neither is pressing a reset button twice a day during loadshedding :) None of my ESP Home devices lock up, so I'm sure they have implemented the hardware watchdog timer correctly.

For inspiration: You could read the LCD of your power meter directly by using an ESP Cam + Machine Learning

Zodiac-69 commented 3 years ago

Hi Dale I was not following my own rule - power supply is the cause of 99% issues.... I managed to get it quite stable so far, two power outages, but thank you i shall look at your recommendations. I placed a 4700uF cap on the output of the CD42, then a 10uH inductor in series with the positive and a 100nF cap after the inductor. The 4700uF cap store enough to ride out the dip and the inductor / 100nF clean up the noise. I have the ESP and a RPI Zero W connected on the CD42 unit and no crashes thus far. We had a very long outage today, from 10:00 to 15:15 and the battery - 5000ma/h was still above 50%

dalehumby commented 3 years ago

That's quite a serious cap! Thanks for the circuit specs. I'm going to try your suggestion and buy myself a MH-CD42 so I can run some of my sensors on battery during power outages.