philbowles / PangolinMQTT

PangolinMQTT - ArduinoIDE client library for ESP8266, ESP32 and STM32-NUCLEO
Other
71 stars 21 forks source link

MQTT reconnect fails with reason=1 when WiFi disconnects and reconnects #28

Closed mrdc closed 3 years ago

mrdc commented 3 years ago

Hello,

I'm trying to port my project to PangolinMQTT and have an error with MQTT auto reconnection when using supplied example: https://github.com/philbowles/PangolinMQTT/blob/master/examples/QuickStart_P/QuickStart_P.ino

PangolinMQTT 0.0.8 mosquitto 1.6.12 ESP32 Wrover

Steps to reproduce:

  1. Upload the example to ESP32
  2. Wait for ESP32 to connect to mosquitto
  3. Drop Wifi connection for ESP32 via router (ban ESP32)
  4. We receive this in ESP32 serial:
    
    Disconnected from MQTT reason=-13
    [WiFi-event] event: 5
    WiFi lost connection
    Connecting to Wi-Fi...
    E (168936) wifi: Set status to INIT.

[WiFi-event] event: 5 WiFi lost connection E (169877) wifi: Set status to INIT.

[WiFi-event] event: 5 WiFi lost connection E (170004) wifi: Set status to INIT. ...

5. Bring Wifi back to ESP32 via router (unban ESP32):

... [WiFi-event] event: 4 [WiFi-event] event: 7 WiFi connected IP address: 192.168.1.40 Connecting to MQTT...

SESSION IS CLEAN Connected to MQTT session=0 max payload size=115876 Subscribing at QoS 2 T=177202 Publishing at QoS 0 T=177202 Publishing at QoS 1 T=177203 Publishing at QoS 2 ...


6. Everything looks fine, but then I receive this:

... [0x3FFCC09A] 0x00000000: 53 61 76 65 20 74 68 65 20 50 61 6E 67 6F 6C 69 Save the Pangoli [0x3FFCC0AA] 0x00000010: 6E 21 00 n!. Connecting to Wi-Fi... Disconnected from MQTT reason=1

7. MQTT reconnect doesn't work anymore :(
8. When I simply turn off WiFi router, I receive this:

... [WiFi-event] event: 4 [WiFi-event] event: 7 WiFi connected IP address: 192.168.1.40 Connecting to MQTT... Connecting to Wi-Fi... Disconnected from MQTT reason=-13



Any ideas what is wrong?
philbowles commented 3 years ago

Apologies for the delay - a new version has been released. Hope this fixes the issue, if not - let me know

rtprof commented 3 years ago

Hello. I use the latest version (1.0.1) and have the same problem. I blocked an Internet access for the esp8266 and after few minutes opened it

D:1: CONNECTING to m16.cloudmqtt.com:15381 as esp8266-E48296 FH=14832 session=1 14:02:35.092 -> D:4: We are now clean:) 14:02:35.092 -> D:2: ----> TX CONNECT 95 bytes 14:02:35.264 -> Address: 0x3FFF35FC len: 0x5F (95) 14:02:35.264 -> [0x3FFF35FC] 0x00000000: 10 5D 00 04 4D 51 54 54 04 D6 00 1E 00 0E 65 73 .]..MQTT......es 14:02:35.264 -> [0x3FFF360C] 0x00000010: 70 38 32 36 36 2D 45 34 38 32 39 36 00 20 63 6C p8266-E48296. cl 14:02:35.264 -> [0x3FFF361C] 0x00000020: 69 6D 61 74 65 2F 6C 79 74 6B 6F 2F 31 34 39 37 imate/lytko/1497 14:02:35.264 -> [0x3FFF362C] 0x00000030: 35 36 33 38 2F 61 76 61 69 6C 61 62 6C 65 00 07 5638/available.. 14:02:35.300 -> [0x3FFF363C] 0x00000040: offline.. 14:02:35.300 -> [0x3FFF364C] 0x00000050: .. 14:02:35.438 -> D:4: <---- RX CONNACK 3FFF6F6A len=4 14:02:35.472 -> Address: 0x3FFF6F6A len: 0x4 (4) 14:02:35.472 -> [0x3FFF6F6A] 0x00000000: 20 02 00 00 ... 14:02:35.472 -> D:2: <---- RX CONNACK 3FFF6F6A len=4 14:02:35.472 -> Address: 0x3FFF6F6A len: 0x4 (4) 14:02:35.472 -> [0x3FFF6F6A] 0x00000000: 20 02 00 00 ... 14:02:35.472 -> D:1: CONNECTED FH=14832 MaxPL=5368 SESSION CLEAN 14:02:35.472 -> Connected to MQTT. 14:02:35.472 -> Session present: 0 14:02:36.769 -> D:1: T=2880731 SRV GONE? ka=30 tix=46 14:02:59.531 -> D:1: ON DISCONNECT FH=11624 r=1 14:02:59.531 -> D:4: CLEAR 0 FRAGMENTS 14:02:59.531 -> Disconnected from MQTT. 14:03:00.828 -> D:1: TCP CHOPPED US! 14:03:21.288 -> D:1: ON DISCONNECT FH=14832 r=0 14:03:21.288 -> D:4: CLEAR 0 FRAGMENTS 14:03:21.288 -> Disconnected from MQTT.