async-mqtt-client icon indicating copy to clipboard operation
async-mqtt-client copied to clipboard

Something wrong with ESP32 WiFi stack interaction

Open smacyas opened this issue 5 years ago • 1 comments

From time to time there is a situation in which in the WiFi STA mode there is a disconnection from the broker (reconnection), and despite the fact that WiFi.status () is WL_CONNECTED, the device ceases to be available on the network.

The part of the log: Disconnected from MQTT: 192.168.250.247:1883 MQTT disconnect, restarting [WiFi/ETH] event: 5 WiFi lost connection [WiFi/ETH] event: 4 .WiFi connected [WiFi/ETH] event: 7 .IP address: 192.168.250.245 .WiFi channel: 11 .Wi-Fi RSSI: -59 .Connecting to MQTT: 192.168.250.247:1883 and after that the device is not available on the network

Esp32 start crash Esp32 end crash

smacyas avatar Nov 07 '19 09:11 smacyas

I tried to do similar test. On working status disconnect LAN cable from MQTT broker. MQTT disconnected message I get after 40 seconds. It tries to reconnect every 2 seconds after previous connect function fails. When I turn LAN cable back on to MQTT broker it connects back after ~10-15 sec. When I tried to restart router (WiFi), it detected disconnection if Wifi quite fast, after reconnect it starting reconnecting back to Mqtt broker with success.

have you set all event as in library example?

  wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);
  wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);

  mqttClient.onConnect(onMqttConnect);
  mqttClient.onDisconnect(onMqttDisconnect);
  mqttClient.onMessage(onMqttMessage);
  mqttClient.setServer(mqtt_server, atoi(mqtt_port));

aliusc avatar Jan 20 '20 18:01 aliusc