martin-ger / uMQTTBroker

MQTT Broker library for ESP8266 Arduino
MIT License
446 stars 106 forks source link

MQTT Client -> Exception 9 when reconnecting #1

Open reaper7 opened 6 years ago

reaper7 commented 6 years ago

My mqtt broker has set user and password, I forgot about it and I tried the @i-n-g-o mqtt_pub example as is without setUserPwd...

Connecting to MyHomeNet
.......
WiFi connected
IP address: 
192.168.0.117
Connecting to MQTT server
connect mqtt...
disconnected. try to reconnect...

in setup mqtt try connect to broker without success (because user/pass not set) then jump to myDisconnectedCb and causer error on second myMqtt.connect():

Exception (9):
epc1=0x40104a44 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000003 depc=0x00000000

ctx: sys 
sp: 3ffffd30 end: 3fffffb0 offset: 01a0

>>>stack>>>
3ffffed0:  3ffeeb80 0000037b 0000037b 4010020c  
3ffffee0:  40104c70 001d573f 3ffee930 00000000  
3ffffef0:  3ffee2b0 3ffee930 3ffee89c 401004f4  
3fffff00:  00000001 0018928b 4021991a 3ffee89c  
3fffff10:  3ffee930 3fff1d9c 3ffe8ab4 402198d1  
3fffff20:  00000000 0018924e 40201340 3fff1e14  
3fffff30:  3fff0310 3fff1ffc 3ffee89c 4020269c  
3fffff40:  3ffeb87c 3fff1ffc 3ffee89c 40201f77  
3fffff50:  0000005c 00000001 4010420a 40203145  
3fffff60:  3ffec7c8 40100a91 00000000 40218f85  
3fffff70:  40222a5f 00000000 3fff1dfc 40222a6c  
3fffff80:  4010085e 00000002 00000002 3fff0944  
3fffff90:  4021b9ba 3fffdab0 00000000 3fff0338  
3fffffa0:  3fffdc60 00000000 3fffdab0 40000f49  
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(1,6)

 ets Jan  8 2013,rst cause:4, boot mode:(1,6)

wdt reset

esp exception decoder show:

Exception 9: LoadStoreAlignmentCause: Load or store to an unaligned address
Decoding 15 results
0x40104a44: ets_timer_setfn at ?? line ?
0x40104c70: ets_timer_arm_new at ?? line ?
0x402029fd: Print::write(char const*) at C:\PROGRAMY\Arduino\hardware\esp8266com\esp8266\cores\esp8266/Print.cpp line 99
0x40201340: delay at C:\PROGRAMY\Arduino\hardware\esp8266com\esp8266\cores\esp8266/core_esp8266_wiring.c line 46
0x40202a74: Print::println(char const*) at C:\PROGRAMY\Arduino\hardware\esp8266com\esp8266\cores\esp8266/Print.cpp line 99
0x40201f71: myDisconnectedCb() at C:\PROGRAMY\arduino_projekty\mqtt_test1/mqtt_test1.ino line 87
0x4010420a: lmacTxFrame at ?? line ?
0x40203145: mqttDisconnectedCb at C:\PROGRAMY\arduino_projekty\libraries\uMQTTBroker\src/MQTT.cpp line 198
0x40100a91: ppEnqueueRxq at ?? line ?
0x40218f85: mqtt_tcpclient_discon_cb at C:\PROGRAMY\arduino_projekty\libraries\uMQTTBroker\src/mqtt.c line 497
0x40222a5f: espconn_tcp_disconnect_successful at app/espconn_tcp.c line 384
:  (inlined by) espconn_Task at app/espconn_tcp.c line 439
0x40222a6c: espconn_tcp_disconnect_successful at app/espconn_tcp.c line 389
:  (inlined by) espconn_Task at app/espconn_tcp.c line 439
0x4010085e: ppProcessTxQ at ?? line ?
0x4021b9ba: ppPeocessRxPktHdr at ?? line ?

when I set user/pass everything works fine

martin-ger commented 6 years ago

Just to understand a few questions:

Thanks, Martin

reaper7 commented 6 years ago

I'm using lib only as client and this happens on client. Original lib -> the same problem

mqtt_pub.ino from origial mqtt-client lib, only wifi user/pass and mqtt server IP changed. if I add in setup (before myMqtt.connect();): myMqtt.setUserPwd("mymqttuser", "mymqttpass"); everything works correctly

but without setUserPwd I got:

Exception 9: LoadStoreAlignmentCause: Load or store to an unaligned address
Decoding 18 results
0x40104a44: ets_timer_setfn at ?? line ?
0x4010020c: _umm_free at C:\PROGRAMY\Arduino\hardware\esp8266com\esp8266\cores\esp8266\umm_malloc/umm_malloc.c line 1291
0x40104c70: ets_timer_arm_new at ?? line ?
0x401004f4: calloc at C:\PROGRAMY\Arduino\hardware\esp8266com\esp8266\cores\esp8266\umm_malloc/umm_malloc.c line 1688
0x402198da: MQTT_Connect at C:\PROGRAMY\arduino_projekty\libraries\esp-mqtt-arduino\src\mqtt/mqtt.c line 915
0x40219891: MQTT_Connect at C:\PROGRAMY\arduino_projekty\libraries\esp-mqtt-arduino\src\mqtt/mqtt.c line 901
0x40201340: delay at C:\PROGRAMY\Arduino\hardware\esp8266com\esp8266\cores\esp8266/core_esp8266_wiring.c line 46
0x4020269c: MQTT::connect() at C:\PROGRAMY\arduino_projekty\libraries\esp-mqtt-arduino\src/MQTT.cpp line 198
0x40201f77: myDisconnectedCb() at C:\tmp\arduino_modified_sketch_608881/mqtt_pub.ino line 90
0x4010420a: lmacTxFrame at ?? line ?
0x40203125: mqttDisconnectedCb at C:\PROGRAMY\arduino_projekty\libraries\esp-mqtt-arduino\src/MQTT.cpp line 198
0x40100a91: ppEnqueueRxq at ?? line ?
0x40218f65: mqtt_tcpclient_discon_cb at C:\PROGRAMY\arduino_projekty\libraries\esp-mqtt-arduino\src\mqtt/mqtt.c line 509
0x4022294b: espconn_tcp_disconnect_successful at app/espconn_tcp.c line 384
:  (inlined by) espconn_Task at app/espconn_tcp.c line 439
0x40222958: espconn_tcp_disconnect_successful at app/espconn_tcp.c line 389
:  (inlined by) espconn_Task at app/espconn_tcp.c line 439
0x4010085e: ppProcessTxQ at ?? line ?
0x4021b8a6: ppPeocessRxPktHdr at ?? line ?
Marais-M commented 6 years ago

Hi Martin

Thanks for the hard work done with the Andriod library.

When running the code on ESP8266 I intermittently get a broker error message when I disconnect a client from the broker: (connect and then a few seconds later disconnect the client).

Fatal exception 9(LoadStoreAlignmentCause): epc1=0x40227fd2, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000107, depc=0x00000000

Exception (9): epc1=0x40227fd2 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000107 depc=0x00000000

With debug activated and a client disconnect requested, I noticed that during the client diconnect sequence a espconn_delete(mqttClientCon->pCon) and when the MQTT_ServerTask is executed a espconn_disconnect(clientcon->pCon) is called. The Fatal exception happens when espconn_disconnect(clientcon->pCon) is executed.

Would it not be better to prevent a espconn_delete to be followed by espconn_disconnect by changing ClientCon->connState in MQTT_server_deleteClientCon.

bool ICACHE_FLASH_ATTR MQTT_server_deleteClientCon(MQTT_ClientCon * mqttClientCon) { MQTT_INFO("MQTT: DeleteClientCon\r\n");

if (mqttClientCon == NULL) return;

os_timer_disarm(&mqttClientCon->mqttTimer);

if (mqttClientCon->pCon != NULL) {
     mqttClientCon->connState = TCP_DISCONNECTING;
      espconn_delete(mqttClientCon->pCon);
  }

Your feedback plse.

Regards Marius