WIFI : Trouble with ESP WiFi routine

anmolaggarwal
Posts: 3
Joined: Sat May 16, 2020 3:44 am

WIFI : Trouble with ESP WiFi routine

Postby anmolaggarwal » Fri Jul 23, 2021 5:54 am

I am having trouble with ESP WiFi routine as it frequently interrupts and I am getting software exceptions due to which esp restarts.
Can someone please look at wifi and mqtt my event handler and initialization routine and let me know if something is wrong here.
The Software always connects to WiFi on startup, but crashes after some time. The duration is random. Sometime 3-4 minutes. Sometime hours.

Also the use of MQTT client handle,do we require two handles? one to start the client & one for the MQTT events.
Attachments
esp32_wifi_code_for_review.c
(29.35 KiB) Downloaded 197 times

User avatar
mbratch
Posts: 294
Joined: Fri Jun 11, 2021 1:51 pm

Re: WIFI : Trouble with ESP WiFi routine

Postby mbratch » Mon Jul 26, 2021 12:20 pm

That's 1000 lines of code you're asking people to review cold. Perhaps you can narrow the problem down somehow. What is the console output when the crash occurs? There's typically a lot of detail there that can point you to a more specific location of the failure (e.g., a specific function). You should read through that carefully. A crash like this is likely due to a stack overflow or some other means of writing over memory that you shouldn't be writing.

One thing I noticed right off: you are referencing something called `device_id` but it's definition doesn't appear anywhere in this file. It would be critical to know how it's defined and if it might get too long for places you're using it. That's probably not the issue, but it leaves open the question for someone who doesn't know your code.

ESP_Sprite
Posts: 8884
Joined: Thu Nov 26, 2015 4:08 am

Re: WIFI : Trouble with ESP WiFi routine

Postby ESP_Sprite » Tue Jul 27, 2021 1:01 am

mbratch already said it very eloquently. As an extra: if you still have problems pinning down where the issue is, try removing code until you have the bare minimum program that still exhibits the issue. Either 1. you find the bug yourself somewhere along the way, or 2. you have an example with a size that people can easily look in for bugs, so they're more likely to actually do that.

Who is online

Users browsing this forum: No registered users and 72 guests