Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32 does not reconnect to Wifi #2400

Open
4 tasks done
LPG-PG opened this issue Nov 9, 2024 · 4 comments
Open
4 tasks done

ESP32 does not reconnect to Wifi #2400

LPG-PG opened this issue Nov 9, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@LPG-PG
Copy link

LPG-PG commented Nov 9, 2024

What happened?

After an indefinite period of time, the ESP32 module loses the connection to the WiFi. No new DHCP lease is obtained, so neither web, API, MQTT nor ping works.

To Reproduce Bug

It happens ramdomly between 1 and 5 days

Expected Behavior

OpenDTU has to be reboot to fix it temporary

Install Method

Pre-Compiled binary from GitHub releases

What git-hash/version of OpenDTU?

v24.10.15

What firmware variant (PIO Environment) are you using?

generic_esp32

Relevant log/trace output

No response

Anything else?

I checked some parts of the code and I'm not sure, if there is a bug in NetworkSettings.cpp -> NetworkSettingsClass::applyConfig()
line 288ff

WiFi.begin(
            Configuration.get().WiFi.Ssid,
            Configuration.get().WiFi.Password,
            WIFI_ALL_CHANNEL_SCAN);

I mean, that Wifi.begin is called with Channel 1 because the enum WIFI_ALL_CHANNEL_SCAN value is 1.

The declaration of the called function is:

wl_status_t begin(char* ssid, char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true);

So the third paramter is the channel, which is in this case 1.

Please confirm the following

  • I believe this issue is a bug that affects all users of OpenDTU, not something specific to my installation.
  • I have already searched for relevant existing issues and discussions before opening this report.
  • I have updated the title field above with a concise description.
  • I have double checked that my inverter does not contain a W in the model name (like HMS-xxxW) as they are not supported.
@LPG-PG LPG-PG added the bug Something isn't working label Nov 9, 2024
@tbnobody tbnobody mentioned this issue Nov 29, 2024
4 tasks
@Subnum12
Copy link

I have same issue.
I did try wifi reconnect while console log was enabled. For whatever reason the console gets disconnected while wifi is disconnect. However, that's the last output even I could not recreate the issue with manual wifi reconnect.

[2094941][E][WiFiClient.cpp:429] write(): fail on fd 48, errno: 113, "Software caused connection abort"
Disconnected from MQTT.
Disconnect reason:TCP_DISCONNECTED
Network lost co˫▒ѥ▒▒5
                     Websocket: [/livedata][5] disconnect

@tbnobody
Copy link
Owner

I mean, that Wifi.begin is called with Channel 1 because the enum WIFI_ALL_CHANNEL_SCAN value is 1.

You are right. at least the setting of WIFI_ALL_CHANNEL_SCAN is wrong at this place... did you try if it works better if you remove this parameter?

@stefan123t
Copy link

stefan123t commented Dec 19, 2024

@tbnobody I think @LPG-PG is right, we maybe somehow using the wrong signature for the WiFi.begin() method.
We should be using the WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN) separately prior calling the WiFi.begin() method.

https://github.com/espressif/arduino-esp32/blob/352705e6077de4f0575324efa234814e823b9fb8/libraries/WiFi/src/WiFiSTA.cpp#L232-L240

The actual WiFi.begin() method obviously seems to have the signature as @LPG-PG reported:

https://github.com/espressif/arduino-esp32/blob/352705e6077de4f0575324efa234814e823b9fb8/libraries/WiFi/src/WiFiSTA.cpp#L83-L93

The issue seems to be in the „new credentials… “ code path of the NetworkSettings.applyConfig() method:

void NetworkSettingsClass::applyConfig()
{
setHostname();
if (!strcmp(Configuration.get().WiFi.Ssid, "")) {
return;
}
MessageOutput.print("Configuring WiFi STA using ");
if (strcmp(WiFi.SSID().c_str(), Configuration.get().WiFi.Ssid) || strcmp(WiFi.psk().c_str(), Configuration.get().WiFi.Password)) {
MessageOutput.print("new credentials... ");
WiFi.begin(
Configuration.get().WiFi.Ssid,
Configuration.get().WiFi.Password,
WIFI_ALL_CHANNEL_SCAN);
} else {
MessageOutput.print("existing credentials... ");
WiFi.begin();
}
MessageOutput.println("done");
setStaticIp();
}

If this is the case/cause somehow that code path gets active after 2-5 days for some yet unknown reason, but it should eventually show up in the logging.

@LPG-PG
Copy link
Author

LPG-PG commented Dec 21, 2024

You are right. at least the setting of WIFI_ALL_CHANNEL_SCAN is wrong at this place... did you try if it works better if you remove this parameter?

I haven't tried it yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants