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

Basic example crashes when wrong port is set (1880 where node-red is running).

Open olonsoft opened this issue 4 years ago • 4 comments

Today while testing the "FullyFeatured-ESP8266.ino" example, I made a mistake and instead of using port 1883, I set 1880 where my node-red is running. The program crashes:

Connecting to Wi-Fi...
Connected to Wi-Fi.
Connecting to MQTT...
Publish acknowledged.
  packetId: 21584
Publish acknowledged.
  packetId: 29556

Exception (28):
epc1=0x4020340f epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

>>>stack>>>

ctx: sys
sp: 3fffec20 end: 3fffffb0 offset: 01a0
3fffedc0:  3ffefaec 4bc6a7f0 40202610 402081b4  
3fffedd0:  402035bc 00000000 3ffee538 00000000
3fffede0:  0000001a 00000000 401002d4 000000fe
3fffedf0:  3ffee6c5 3ffee638 401026ce 00000100
3fffee00:  00012646 7fffffff 00002200 3ffefa6c
3fffee10:  00000000 3fffee60 3ffee538 4020345c
3fffee20:  00000000 3fffee60 3ffee538 4020759a
3fffee30:  3ffef86c 2c9f0300 4000050c 3fffc278
3fffee40:  4010000a 3fffc200 00000022 3ffef86c
3fffee50:  3ffefa6c 00000000 3ffee538 40207852
3fffee60:  3ffef464 3ffef474 00000001 3ffeeb48
3fffee70:  3ffeecf0 3ffeedec 3ffefa6c 3ffeeb48
3fffee80:  3ffef86c 3ffeeb2c 3ffeeb2d 402120d0  
3fffee90:  00000c60 00000000 00000020 401009de
3fffeea0:  3ffeecf0 b113a8c0 00000012 3ffef37c
3fffeeb0:  00000000 00000000 00000020 3ffeedec
3fffeec0:  3ffeecf0 3ffefa8a 3ffefa6c 40217b3e
3fffeed0:  00000014 3ffeecf0 00000065 3ffef37c
3fffeee0:  00000000 3ffef30c 00000020 401009a7
3fffeef0:  40229d20 3ffef9d4 3ffef30c 3ffef37c
3fffef00:  00000008 3ffeecf0 3ffefa6c 4020ed6d
3fffef10:  3fffdc80 3ffef30c 3ffef9d4 4020eb90  
3fffef20:  402341ca 3ffef30c 3ffef9d4 402341db
3fffef30:  3ffefa7c 3ffefa6c 00000000 3ffe84e8
3fffef40:  4022994b 00000000 3ffef9d4 4022f9e3
3fffef50:  40000f49 3fffdab0 3fffdab0 40000f49
3fffef60:  40000e19 40001878 00000002 3fffffb0
3fffef70:  3fffff10 aa55aa55 00000001 4010482d
3fffef80:  40104833 00000002 3fffffb0 4023eb48  
3fffef90:  4010000d 00000000 00000000 00000000
3fffefa0:  00000000 3fffef3c 00000000 00000000
3fffefb0:  3fffffc0 00000000 00000000 feefeffe
3fffefc0:  feefeffe feefeffe feefeffe feefeffe
...
3ffffc80:  feefeffe feefeffe feefeffe feefeffe
3ffffc90:  feefeffe feefeffe feefeffe feefeffe  
3ffffca0:  feefeffe 80af1999 feefeffe feefeffe
3ffffcb0:  00000a20 00000000 40240000 ffffff1a
3ffffcc0:  00000a48 80be5999 00000018 00000000
3ffffcd0:  00000000 00000020 4022aaa7 00000001
3ffffce0:  ffffffff 00000000 3ffe8d31 00000008
3ffffcf0:  4022aaf6 3ffef7ec 3ffef7ec 00000000
3ffffd00:  fffffffe 00000000 401015cf 3ffef7ec
3ffffd10:  000000c0 4022383c 00000000 3ffef854  
3ffffd20:  3ffe8be0 40229bb3 3ffef7ec 3ffecfbc  
3ffffd30:  00000000 4021db7b 3ffecfbc 3ffef7ec
3ffffd40:  3ffe8895 0000001c 00000001 0000000a
3ffffd50:  3ffef885 3ffeef44 00000007 3ffed700
3ffffd60:  3ffe8895 3ffe8895 3ffef33f 4021f9bb
3ffffd70:  3ffed6b4 4021f58c 40221bec 3ffed6b4
3ffffd80:  40105111 0000c358 3ffed7e0 00000000  
3ffffd90:  3ffedef0 3ffed7e0 00000001 00000001
3ffffda0:  00000002 00000000 00000020 401001dc
3ffffdb0:  401018c5 40221bec 00000002 40101490
3ffffdc0:  3ffe8be2 4010472f 3ffec378 401001dc
3ffffdd0:  00000001 4010390a 3ffecda8 40101490
3ffffde0:  00000005 00000000 00000020 401001dc
3ffffdf0:  00000002 00000000 00000005 40101490
3ffffe00:  3ffe8be5 40104747 3ffec670 40101490  
3ffffe10:  4010202b 3ffec670 3ffec378 40101490  
3ffffe20:  fffffffc 0003d132 3ffed0b8 4010220c
3ffffe30:  3ffe9478 00000000 00000000 4010220c
3ffffe40:  fffffffc 0003d132 401026ce 00000100
3ffffe50:  3ffe9478 7fffffff 00002200 00000001
3ffffe60:  00000001 00004208 4000050c 3fffc278
3ffffe70:  3ffe9478 00080000 00000022 0003d132  
3ffffe80:  3ffe9484 2c9f0300 4000050c 3fffc278  
3ffffe90:  401023f0 3fffc200 00000022 3fffc278
3ffffea0:  40207004 00000030 0000001b ffffffff
3ffffeb0:  40205ab4 00000000 40205ac4 00000000
3ffffec0:  00000000 00000000 00000000 fffffffe
3ffffed0:  ffffffff 3fffc6fc 00000001 3ffee808
3ffffee0:  00000000 3fffdad0 3ffee848 00000030
3ffffef0:  00000000 3fffdad0 3ffee848 00000030  
3fffff00:  00000000 3fffdad0 3ffee848 00000030
3fffff10:  3ffe8622 00000001 00000010 3ffee848
3fffff20:  40204d8c 3ffee71c 3ffe8802 40204d98
3fffff30:  40204d00 3ffee71c 3ffe8881 00000002
3fffff40:  00000006 00000000 3ffee6e4 00000001
3fffff50:  40207f40 40207f54 3ffee71c 3ffee848
3fffff60:  007a1200 6eb043e4 3ffee500 4020104a  
3fffff70:  00000000 40207f54 3ffee538 4020163f
3fffff80:  00000000 00000000 00000001 401001dc  
3fffff90:  3fffdad0 00000000 3ffee808 401001fd
3fffffa0:  3fffdad0 00000000 3ffee808 40205aed
<<<stack<<<

When I set port 1883 it works. When I also set any other not used port, it normally disconnects.

olonsoft avatar Apr 14 '20 08:04 olonsoft

Port 1880 is the web interface of nodered not the MQTT port so that is why...

The crash should not happen, but it in normal situation it will be fine...

jeroenst avatar Apr 14 '20 09:04 jeroenst

The crash should not happen, but it in normal situation it will be fine...

This crash happened in my application and I couldn't find what was wrong until I noticed the wrong port. Then I run the basic example to be sure that was not my code's bug. I hope this to be fixed soon.

olonsoft avatar Apr 14 '20 10:04 olonsoft

Is it possible to decode the stack trace? I'm quite interested in how this happens. I can't reproduce.

bertmelis avatar Apr 14 '20 19:04 bertmelis

The code is this:

#include <ESP8266WiFi.h>
#include <Ticker.h>
#include <AsyncMqttClient.h>

#define WIFI_SSID "Support"
#define WIFI_PASSWORD "12345678"

#define MQTT_HOST IPAddress(192, 168, 19, 10)
#define MQTT_PORT 1880

AsyncMqttClient mqttClient;
Ticker mqttReconnectTimer;

WiFiEventHandler wifiConnectHandler;
WiFiEventHandler wifiDisconnectHandler;
Ticker wifiReconnectTimer;

void connectToWifi() {
  Serial.println("Connecting to Wi-Fi...");
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
}

void connectToMqtt() {
  Serial.println("Connecting to MQTT...");
  mqttClient.connect();
}


void onWifiConnect(const WiFiEventStationModeGotIP& event) {
  Serial.println("Connected to Wi-Fi.");
  connectToMqtt();
}

void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
  Serial.println("Disconnected from Wi-Fi.");
  mqttReconnectTimer.detach(); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
  wifiReconnectTimer.once(2, connectToWifi);
}


void onMqttConnect(bool sessionPresent) {
  Serial.println("Connected to MQTT.");
  Serial.print("Session present: ");
  Serial.println(sessionPresent);
  uint16_t packetIdSub = mqttClient.subscribe("test/lol", 2);
  Serial.print("Subscribing at QoS 2, packetId: ");
  Serial.println(packetIdSub);
  mqttClient.publish("test/lol", 0, true, "test 1");
  Serial.println("Publishing at QoS 0");
  uint16_t packetIdPub1 = mqttClient.publish("test/lol", 1, true, "test 2");
  Serial.print("Publishing at QoS 1, packetId: ");
  Serial.println(packetIdPub1);
  uint16_t packetIdPub2 = mqttClient.publish("test/lol", 2, true, "test 3");
  Serial.print("Publishing at QoS 2, packetId: ");
  Serial.println(packetIdPub2);
}

void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
  Serial.println("Disconnected from MQTT.");

  if (WiFi.isConnected()) {
    mqttReconnectTimer.once(2, connectToMqtt);
  }
}

void onMqttSubscribe(uint16_t packetId, uint8_t qos) {
  Serial.println("Subscribe acknowledged.");
  Serial.print("  packetId: ");
  Serial.println(packetId);
  Serial.print("  qos: ");
  Serial.println(qos);
}

void onMqttUnsubscribe(uint16_t packetId) {
  Serial.println("Unsubscribe acknowledged.");
  Serial.print("  packetId: ");
  Serial.println(packetId);
}

void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
  Serial.println("Publish received.");
  Serial.print("  topic: ");
  Serial.println(topic);
  Serial.print("  qos: ");
  Serial.println(properties.qos);
  Serial.print("  dup: ");
  Serial.println(properties.dup);
  Serial.print("  retain: ");
  Serial.println(properties.retain);
  Serial.print("  len: ");
  Serial.println(len);
  Serial.print("  index: ");
  Serial.println(index);
  Serial.print("  total: ");
  Serial.println(total);
}

void onMqttPublish(uint16_t packetId) {
  Serial.println("Publish acknowledged.");
  Serial.print("  packetId: ");
  Serial.println(packetId);
}

void setup() {
  Serial.begin(115200);
  Serial.println();
  Serial.println();

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

  mqttClient.onConnect(onMqttConnect);
  mqttClient.onDisconnect(onMqttDisconnect);
  mqttClient.onSubscribe(onMqttSubscribe);
  mqttClient.onUnsubscribe(onMqttUnsubscribe);
  mqttClient.onMessage(onMqttMessage);
  mqttClient.onPublish(onMqttPublish);
  mqttClient.setServer(MQTT_HOST, MQTT_PORT);

  connectToWifi();
}

void loop() {
}

Stack trace decoded:

Exception Cause: 28  [LoadProhibited: A load referenced a page mapped with an attribute that does not permit loads]

0x402034cf: AsyncMqttClient::_onData(AsyncClient*, char*, unsigned int) at ??:?
0x402026d0: std::_Function_base::_Base_manager<std::_Bind<std::_Mem_fn<void (AsyncMqttClient::*)(unsigned short)> (AsyncMqttClient*, std::_Placeholder<1>)> >::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) at ??:?
0x402081d8: std::_Function_handler<void (unsigned short), std::_Bind<std::_Mem_fn<void (AsyncMqttClient::*)(unsigned short)> (AsyncMqttClient*, std::_Placeholder<1>)> >::_M_invoke(std::_Any_data const&, unsigned short) at ??:?
0x4020367c: AsyncMqttClient::_onPubComp(unsigned short) at ??:?
0x401002d4: millis at ??:?
0x4010363c: lmacProcessTXStartData at ??:?
0x401002d4: millis at ??:?
0x4020351c: std::_Function_handler<void (void*, AsyncClient*, void*, unsigned int), AsyncMqttClient::AsyncMqttClient()::{lambda(void*, AsyncClient*, void*, unsigned int)#6}>::_M_invoke(std::_Any_data const&, void*, AsyncClient*, void*, unsigned int) at AsyncMqttClient.cpp:?
0x4020759a: AsyncClient::_recv(std::shared_ptr<ACErrorTracker>&, tcp_pcb*, pbuf*, long) at ??:?
0x4000050c: ?? ??:0
0x40207852: AsyncClient::_s_recv(void*, tcp_pcb*, pbuf*, long) at ??:?
0x402120d0: tcp_input at /home/gauchard/dev/esp8266/esp8266/tools/sdk/lwip2/builder/lwip2-src/src/core/tcp_in.c:501 (discriminator 1)
0x401009de: malloc at ??:?
0x40217b3e: ip4_input at /home/gauchard/dev/esp8266/esp8266/tools/sdk/lwip2/builder/lwip2-src/src/core/ipv4/ip4.c:1467
0x401009a7: free at ??:?
0x40229d20: ppRecycleRxPkt at ??:?
0x4020ed6d: ethernet_input_LWIP2 at /home/gauchard/dev/esp8266/esp8266/tools/sdk/lwip2/builder/lwip2-src/src/netif/ethernet.c:188
0x4020eb90: esp2glue_ethernet_input at /home/gauchard/dev/esp8266/esp8266/tools/sdk/lwip2/builder/glue-lwip/lwip-git.c:469
0x402341ca: ethernet_input at /home/gauchard/dev/esp8266/esp8266/tools/sdk/lwip2/builder/glue-esp/lwip-esp.c:365
0x402341db: ethernet_input at /home/gauchard/dev/esp8266/esp8266/tools/sdk/lwip2/builder/glue-esp/lwip-esp.c:373
0x4022994b: ppPeocessRxPktHdr at ??:?
0x4022f9e3: ets_snprintf at ??:?
0x40000f49: ?? ??:0
0x40000f49: ?? ??:0
0x40000e19: ?? ??:0
0x40001878: ?? ??:0
0x4010482d: call_user_start_local at ??:?
0x40104833: call_user_start_local at ??:?
0x4023eb48: sleep_reset_analog_rtcreg_8266 at ??:?
0x4010000d: call_user_start at ??:?
0x40240000: ?? ??:0
0x4022aaa7: pp_attach at ??:?
0x4022aaf6: pp_attach at ??:?
0x401015cf: ppCalFrameTimes at ??:?
0x4022383c: ieee80211_setup_ratetable at ??:?
0x40229bb3: ppTxPkt at ??:?
0x4021db7b: ieee80211_send_probereq at ??:?
0x4021f9bb: scan_remove_probe_ssid at ??:?
0x4021f58c: scan_start at ??:?
0x40221bec: cnx_start_handoff_cb at ??:?
0x40105111: ets_timer_arm_new at ??:?
0x401001dc: ets_post at ??:?
0x401018c5: rcUpdateTxDone at ??:?
0x40221bec: cnx_start_handoff_cb at ??:?
0x40101490: pp_post at ??:?
0x401001dc: ets_post at ??:?
0x401018c5: rcUpdateTxDone at ??:?
0x40101490: pp_post at ??:?
0x4010472f: lmacTxFrame at ??:?
0x40101490: pp_post at ??:?
0x4010390a: lmacRecycleMPDU at ??:?
0x401001dc: ets_post at ??:?
0x401001dc: ets_post at ??:?
0x40103d7b: lmacRecycleMPDU at ??:?
0x4010363c: lmacProcessTXStartData at ??:?
0x40101490: pp_post at ??:?
0x40104747: lmacRxDone at ??:?
0x4010202b: rcReachRetryLimit at ??:?
0x4010220c: rcReachRetryLimit at ??:?
0x401026ce: wDev_ProcessFiq at ??:?
0x4000050c: ?? ??:0
0x401023f0: wDev_ProcessFiq at ??:?
0x40100ca4: cont_wrapper at ??:?
0x40205977: loop_task(ETSEventTag*) at core_esp8266_main.cpp:?
0x40100ca4: cont_wrapper at ??:?
0x40205ac4: loop_wrapper() at core_esp8266_main.cpp:?
0x40204d8c: HardwareSerial::write(unsigned char const*, unsigned int) at ??:?
0x40204d98: HardwareSerial::write(unsigned char const*, unsigned int) at ??:?
0x40204d00: AsyncMqttClientInternals::UnsubAckPacket::UnsubAckPacket(AsyncMqttClientInternals::ParsingInformation*, std::function<void (unsigned short)>) at ??:?
0x40207f40: std::_Function_handler<void (unsigned short), void (*)(unsigned short)>::_M_invoke(std::_Any_data const&, unsigned short) at ??:?
0x40207f54: std::_Function_base::_Base_manager<void (*)(unsigned short)>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) at ??:?
0x4020104a: connectToWifi() at ??:?
0x40207f54: std::_Function_base::_Base_manager<void (*)(unsigned short)>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) at ??:?
0x4020163f: setup at ??:?
0x401001dc: ets_post at ??:?
0x401001fd: esp_schedule at ??:?
0x40205aed: loop_wrapper() at core_esp8266_main.cpp:?

olonsoft avatar Apr 15 '20 09:04 olonsoft