ESP32 works only for few days

Hi
my project depends on that ESP 32 keeps working 24/7 reading from energy meter PZEM004T using UART (RX TX) and sending the reading through wifi to my firebase

but it works for weeks or sometimes a few days before it stops functioning .. not reading, not sending and not blinking the built-in LED ( it blinks for every loop ) until I reset the esp

my code is a bit long and messy .. but I was sure for every "for" or "while" loops I used a delay to prevent watchdog problems

please any suggestions ... I can't access the Serial monitor when it freezes.. once I try everything reset and no error to see

thanks in advance

Leave your Serial monitor connected until it crashes, hopefully you get a stack trace. That'll be helpful to get an idea of what's going wrong. Clean up your code, that can also help finding the problem. Get rid of all uses of String.

wvmarle:
Leave your Serial monitor connected until it crashes, hopefully you get a stack trace. That'll be helpful to get an idea of what's going wrong. Clean up your code, that can also help finding the problem. Get rid of all uses of String.

how can i make it connected for weeks :>

I used many strings .. could this be the problem?
most of them are directly by the Serial.print .. I mean like Serial.println( "starting reading from sensor number 1" )

strings are not the problem, Strings are (that capital is a key difference).

And of course you should put all those string constants in PROGMEM. Use the F() macro and friends. That saves heaps of RAM, and while the ESP32 has a lot it's not a resource you should waste like that.

If your using arrays and you overrun them, that can cause issues.

Are you verifying you still have connection before trying to send data?

Considered using ESP.restart(); every hour to see if that helps?

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Do you have bypass capacitors ?
How are you powering your project?
Have you got your component and wiring layout so it does not come near the mains current wiring?
A picture of your project will help immensely.

Thanks.. Tom... :slight_smile:

I appreciate all your suggestions guys

I will post more information for my project

Hello guys

thank you for your help

here is my code:

and my circuit is attached

circuit.pdf (45.1 KB)

toOomy:
...but I was sure for every "for" or "while" loops I used a delay to prevent watchdog problems

Please explain.
I would expect a yield() to be used.
Leo..

Hi;
OPs circuit;


Tom.. :slight_smile:

Interesting way of multiplexing Serial inputs.

What's the purpose of the R1/R2 voltage divider? Voltage? What is the voltage coming out of "breadboard power supply"?

No bypass caps for J2 and J3 (odd to designate an IC with J rather than U).

What is the purpose of U1, and why are there all those green "no connect"(?) X-es in its connections?

Both sides of that "breadboard power supply" are power outputs? No power input?

wvmarle:
What is the purpose of U1, and why are there all those green "no connect"(?) X-es in its connections?

not sure what EasyEDA does, but my auto trace will connect all of the same designated pins and will show errors if a pin is not connected or not x'ed out.

Wawa:
Please explain.
I would expect a yield() to be used.
Leo..

delay() function has yield() as well

wvmarle:
Interesting way of multiplexing Serial inputs.

What's the purpose of the R1/R2 voltage divider? Voltage? What is the voltage coming out of "breadboard power supply"?

No bypass caps for J2 and J3 (odd to designate an IC with J rather than U).

What is the purpose of U1, and why are there all those green "no connect"(?) X-es in its connections?

Both sides of that "breadboard power supply" are power outputs? No power input?

thank you

R1/R2 because the ESP's RX should be on 3.3v level

U1 is a relay

and yup both are outputs and ofcourse it has an input ... 9 volt .. I just do not want to bother adding it to the scheme

about the bypass capacitor ... I don't think they are necessary for my circuit...are they?

TomGeorge:
Hi;
OPs circuit;

I dont understand :)) sorry what do you mean

toOomy:
delay() function has yield() as well

A cow is an animal, so an animal is a cow...

Wawa:
A cow is an animal, so an animal is a cow…

yup I remember I found on google that delay can be used instead of yield

please if I’m wrong correct me

On the ESP, the delay(0) command actually does something useful: it's the equivalent of yield().

delay(0) and yield() might be the same.
delay(1) adds a millisecond of nothing.
And it might put the ESP32 in sleep mode (it does on an ESP8266).
Leo…

wvmarle:
On the ESP, the delay(0) command actually does something useful: it's the equivalent of yield().

Wawa:
delay(0) and yield() might be the same.
delay(1) adds a millisecond of nothing.
And it might put the ESP32 in sleep mode (it does on an ESP8266).
Leo..

wow
really thank you
I will fix it

any more suggestions?

Create an RTOS timer that logs the memory stats every so often. ESP32 has a good API for that. Maybe you’re running into overflows.