Emontx4 saved config lost

Hi all,

Yesterday, I saw a very strange behavior when I was playing around with a self-made ESP32-Expansion board.
This board does not have anything wired to Emontxv4, except GND, +3.3, TX, RX.
My emontxv4 was configured so it outputs full-json on the serial.

Since a couple of times, I’ve “bricked” the ESP32, I had to restart emontxv4 multiple times (RJ11 unplugged/re-plugged).
No idea how many times…

Then I saw some errors in the ESPHome log from the ESP32… I found out that the ESP32 did not receive JSON anymore but instead the “raw” data.

After checking with a serial cable, I could see that the saved config was gone, it was again the default one!

Did someone already have this bug?

Fred

Potentially the EEPROM has been corrupted by the power up/power down sequence - the ATmega328 is not particularly robust to power supply variations, which can lead to corruption of the EEPROM. I don’t know if the standard Arduino setup enables the brown out detector, which would help to mitigate this. The ESP32 uses quite a bit of power through the +3V3 connector, so I suspect that is the system level cause of this.

Yes, that was my idea too.

BTW, it’s an emontx 4, so not an Atmega328p :wink:

OpenEnergyMonitor has designed an ESP32 expansion board for emontx 4. Though, it has never been released!

Of course :man_facepalming: It’s the AVR128DB - same principle! The BoD can mitigate to some degree, but it’s likely the case - unfortunately you need to reflash the bootloader to change the BoD settings. There’s nothing inherently wrong with having the ESP32 powered directly, but start up and power down should be well controlled.

1 Like

I’m not sure there is a mechanism for that other than pulling the plug :slight_smile:

MIght be worth handling that as a specific error in the logs.

A built-in status sensor perhaps? The emonTX generates some status data on boot, perhaps it could parse that into some sensor attributes?

1 Like

It shouldn’t be too bad doing that once, but if you’re doing it repeatedly back to back the chance is that you’ll not get clean power downs and ups. Essentially it’s introducing voltage glitches - a classical technique to scramble microcontroller execution!

1 Like