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

Publisher invoke error #3

Closed
vaclavrak opened this issue Jan 1, 2018 · 3 comments
Closed

Publisher invoke error #3

vaclavrak opened this issue Jan 1, 2018 · 3 comments

Comments

@vaclavrak
Copy link

thank you for your lib, looks very usefull, still I have very simple code like this what does not work and I have no idea what I do wrong

#include <ESP8266WiFi.h>
#include <uMQTTBroker.h>


const char *ssid = "myAP";
const char *password = "password123";

unsigned int mqttPort = 1883;       // the standard MQTT broker port
unsigned int max_subscriptions = 30;
unsigned int max_retained_topics = 30;

void data_callback(uint32_t *client /* we can ignore this */, const char* topic, uint32_t topic_len, const char *data, uint32_t lengh) {
  char topic_str[topic_len+1];
  os_memcpy(topic_str, topic, topic_len);
  topic_str[topic_len] = '\0';

  char data_str[lengh+1];
  os_memcpy(data_str, data, lengh);
  data_str[lengh] = '\0';

  Serial.print("received topic '");
  Serial.print(topic_str);
  Serial.print("' with data '");
  Serial.print(data_str);
  Serial.println("'");
}


void setup() {
  delay(1000);
  Serial.begin(115200);

  WiFi.mode(WIFI_AP);
  WiFi.softAP(ssid, password);

  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);

  MQTT_server_onData(data_callback);
    
  Serial.println("Starting MQTT broker");
  MQTT_server_start(mqttPort, max_subscriptions, max_retained_topics);
  MQTT_local_subscribe((unsigned char *)"#", 0);
}


void loop() {

}

however I connect the AP from my computer I use mosquitto_pub for send a simple message, all looks OK in terminal

$ mosquitto_pub -h 192.168.4.1 -t 'test' -m "Hi there" -d 

Client mosqpub/15186-Think sending CONNECT
Client mosqpub/15186-Think received CONNACK
Client mosqpub/15186-Think sending PUBLISH (d0, q0, r0, m1, 'test', ... (8 bytes))
Client mosqpub/15186-Think sending DISCONNECT

on the serial console I see message like

AP IP address: 192.168.4.1
Starting MQTT broker
received topic 'test' with data 'Hi there'

Exception (9):
epc1=0x4021f89e epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000206 depc=0x00000000

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

>>>stack>>>
3ffffb60:  c9debd7f 00000004 3fff1894 4021f48b  
3ffffb70:  00000000 3fffff90 3fff19d4 402050eb  
3ffffb80:  00000000 3fffff90 3fff19d4 40203f89  
3ffffb90:  00000220 3ffffbd0 3ffffd60 ffffffff  
3ffffba0:  00000000 00000000 00000000 00000000  
3ffffbb0:  00000000 00000000 00000000 00000000  
3ffffbc0:  00000000 00000000 00000000 00000000  
3ffffbd0:  00000000 00000000 00000000 00000000  
3ffffbe0:  b4add38b cb3afebd c8360c74 1e896969  
3ffffbf0:  dc0c6c40 4b75d3a4 a893c528 e32305aa  
3ffffc00:  9f299337 ae589c17 72aa5526 4e242f35  
3ffffc10:  4000b5f9 00000008 00000038 3ffffcf0  
3ffffc20:  00000008 3ffffcf0 449a227d ea602601  
3ffffc30:  8a1802a6 450c03f3 2568e749 7e947257  
3ffffc40:  3cabe89c 7df31f6e c920a4c0 f67d45e4  
3ffffc50:  7ff16bfe d0ced68c 49d0a471 a155f6b0  
3ffffc60:  c526af25 ecf858ec d59f58b4 02d556f9  
3ffffc70:  e3515695 ccf26100 28600fd8 7a269758  
3ffffc80:  a434a05a 4cae08f3 e520dca1 a1822d81  
3ffffc90:  ada9e487 a8c1b449 9ee49f5e 5851bb99  
3ffffca0:  4000b62e 57e846a5 754f2b08 9c1c6eed  
3ffffcb0:  4000b6c4 3ffffcf0 3ffffe80 ffffffff  
3ffffcc0:  4000b72e 3ffffcd0 00000008 3ffffd50  
3ffffcd0:  00000000 00000000 4000a333 3ffffdf8  
3ffffce0:  3ffffe80 3ffffdd8 4020714b 00000001  
3ffffcf0:  ffffffff 00000000 4020714b 00000001  
3ffffd00:  ffffffff 00000000 3ffe9001 00000008  
3ffffd10:  4020719e 3ffec648 3fff04fc 00020021  
3ffffd20:  402072aa 3ffec648 3fff04fc 3ffec648  
3ffffd30:  00000002 00000000 00000020 40101612  
3ffffd40:  3ffe8eb2 402065f3 3ffec648 3fff08ef  
3ffffd50:  00000000 4020e364 3fff12c4 00000100  
3ffffd60:  00000002 00000000 00000000 3ffec648  
3ffffd70:  3fff18ce 40225a6c 3fff18ce 3fff1894  
3ffffd80:  3fff08bc 0bc01a22 00002200 4000050c  
3ffffd90:  3fffc278 4010268c 3fffc200 00000000  
3ffffda0:  3fff00fc 00000000 3fff08bc 40225d51  
3ffffdb0:  3ffe8eb5 401048ef 3ffec918 ffffffff  
3ffffdc0:  40102325 3ffec918 3fff03f8 3fff1894  
3ffffdd0:  3fff1894 3fff17c8 3fff08bc 40225fb8  
3ffffde0:  4010385c 00040000 7fffffff 00000000  
3ffffdf0:  00000022 40103859 00040000 40226f00  
3ffffe00:  3ffed078 40102836 00000000 401004d8  
3ffffe10:  3fff17c8 3fff17c4 00002200 4000050c  
3ffffe20:  3fffc278 4010268c 3fffc200 00000022  
3ffffe30:  3ffffe40 00000001 3fff1894 00000080  
3ffffe40:  4021fbd7 00000030 0000001c ffffffff  
3ffffe50:  40203dc4 3fff198c 00000010 00000014  
3ffffe60:  3ffee0b0 00000000 00000000 3fff1968  
3ffffe70:  ffffffff 3fffc6fc 0000005c 00000000  
3ffffe80:  3fff1134 3fff0300 3fff193c 00000030  
3ffffe90:  00000007 3fff1924 0000001a 00000000  
3ffffea0:  3fff190c 3fff17c8 3fff17c4 40224aa6  
3ffffeb0:  0000111c 3fff18f0 00000006 00000001  
3ffffec0:  3fff17c4 3fff0208 00000000 3fff0200  
3ffffed0:  3fff17c4 3fff0208 3fff0204 402287b8  
3ffffee0:  00000003 0104a8c0 00000019 00000002  
3ffffef0:  4021f73c 00000000 3ffeebb4 40223191  
3fffff00:  40200000 00000000 3ffec648 3fff193c  
3fffff10:  3fff0300 3fff198c 00000000 40220c3c  
3fffff20:  3ffeeb68 000002b8 000002b8 4010020c  
3fffff30:  3ffeeb68 000002a2 000002a2 4010020c  
3fffff40:  00000000 3ffe8821 3fff1924 4010068c  
3fffff50:  3fff0300 3ffe8821 3fff19d4 40106d24  
3fffff60:  4021f0e2 3fff1134 3fff1924 402205a6  
3fffff70:  3fff0300 3fff1134 3fff1924 40220765  
3fffff80:  40100fae 00000002 00000000 3fff094c  
3fffff90:  402062b2 3fffdab0 00000000 3fff0328  
3fffffa0:  3fffdaf0 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

so message was received, but it generates an exception what I don't understand, ESP decoder tool show me more info like this:

Exception 9: LoadStoreAlignmentCause: Load or store to an unaligned address
Decoding 48 results
0x4021f89e: espconn_disconnect at /Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/app/espconn.c line 949
0x4021f48b: espconn_sent at /Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/app/espconn.c line 415
0x402050eb: QUEUE_Gets at /home/rak/Arduino/libraries/uMQTTBroker/src/queue.c line 47
0x40203f89: MQTT_ServerTask at /home/rak/Arduino/libraries/uMQTTBroker/src/mqtt_server.c line 878
0x4020714b: pp_attach at ?? line ?
0x4020714b: pp_attach at ?? line ?
0x4020719e: pp_attach at ?? line ?
0x402072aa: pp_attach at ?? line ?
0x40101612: pp_post at ?? line ?
0x402065f3: ppTxPkt at ?? line ?
0x4020e364: ieee80211_output_pbuf at ?? line ?
0x40225a6c: etharp_send_ip at /Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/netif/etharp.c line 435
0x4010268c: wDev_ProcessFiq at ?? line ?
0x40225d51: etharp_output_to_arp_index at /Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/netif/etharp.c line 890
0x401048ef: lmacRxDone at ?? line ?
0x40102325: trc_NeedRTS at ?? line ?
0x40225fb8: etharp_output at /Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/netif/etharp.c line 995
0x4010385c: lmacProcessTXStartData at ?? line ?
0x40103859: lmacProcessTXStartData at ?? line ?
0x40226f00: ip_output_if_opt at /Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/core/ipv4/ip.c line 780
0x40102836: wDev_ProcessFiq at ?? line ?
0x401004d8: malloc at /home/rak/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/umm_malloc/umm_malloc.c line 1664
0x4010268c: wDev_ProcessFiq at ?? line ?
0x4021fbd7: espconn_delete at /Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/app/espconn.c line 1225
0x40203dc4: MQTT_server_deleteClientCon at /home/rak/Arduino/libraries/uMQTTBroker/src/mqtt_server.c line 176
0x40224aa6: tcp_output at /Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/core/tcp_out.c line 990
0x402287b8: tcp_input at /Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/core/tcp_in.c line 423
0x4021f73c: espconn_get_connection_info at /Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/app/espconn.c line 833
0x40223191: pbuf_alloc at /Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/core/pbuf.c line 388
0x40220c3c: espconn_tcp_delete at /Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/app/espconn_tcp.c line 1372
0x4010020c: _umm_free at /home/rak/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/umm_malloc/umm_malloc.c line 1287
0x4010020c: _umm_free at /home/rak/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/umm_malloc/umm_malloc.c line 1287
0x4010068c: free at /home/rak/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/umm_malloc/umm_malloc.c line 1733
0x40106d24: vPortFree at /home/rak/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/heap.c line 18
0x4021f0e2: espconn_copy_partial at /Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/app/espconn.c line 55
0x402205a6: espconn_tcp_memp_free at /Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/app/espconn_tcp.c line 244
0x40220765: espconn_tcp_disconnect_successful at /Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/app/espconn_tcp.c line 385
:  (inlined by) espconn_Task at /Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/app/espconn_tcp.c line 424
0x40100fae: ppProcessTxQ at ?? line ?
0x402062b2: ppPeocessRxPktHdr at ?? line ?

but I could not see what is wrong, the code is very simple and if I'm publishing messages in loop method all looks just fine. So problem is only if I receive message via WiFi.

Any idea what could be wrong?

@martin-ger
Copy link
Owner

Can confirm this problem. Obviously, it has something to do with the disconnect, not the publish itself. If I try it with other clients (e.g. mqtt-spy) everything works fine. I guess, it has to do with the timing (immediate disconnect?).

Will look into that...

@martin-ger
Copy link
Owner

Think, I found it: a race condition when client and broker are disconnecting at nearly the same time. Should be resolved now. Thank you for your report, was an important issue!

@vaclavrak
Copy link
Author

could confirm all is working as expected ;) thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants