Can't pass variables to MQTT function based on esp-idf example MQTT/tcp

woipdomain
Posts: 3
Joined: Tue Feb 04, 2020 10:35 am

Can't pass variables to MQTT function based on esp-idf example MQTT/tcp

Postby woipdomain » Tue Feb 04, 2020 11:10 am

Hi all ,

Thanks in first term for developing this great IoT tool.

We are having problems to publish simple MQTT JSON string to a broker.

When we try to use esp_mqtt_client_publish() out of the mqtt_event_handler_cb(esp_mqtt_event_handle_t event), the system halts and reboot, we don't figure out how can we pass variables to mqtt_event_handler and mqtt_event_handler_cb, in order tu publish correctly in a polite way.

We can only send simple strings from the mqtt_event_handler_cb(esp_mqtt_event_handle_t event) function , and we need to send unformated JSON varibles, any way we try to pass those variables end in a compile error or unit GURU MEDITATION.

Please help .-

Thank you in advance..

Santi ,

D51 Tech guy.

Our mqtt function :
  1.  static void mqtt_send(char *topic, char *message)
  2. {
  3.  
  4.     printf("MQTT Topic : %s\n",topic);
  5.     printf("MQTT Data : %s\n",message);
  6.  
  7.     ESP_LOGI(MTAG, "[APP] Startup..");
  8.     ESP_LOGI(MTAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size());
  9.     ESP_LOGI(MTAG, "[APP] IDF version: %s", esp_get_idf_version());
  10.  
  11.     esp_log_level_set("*", ESP_LOG_INFO);
  12.     esp_log_level_set("MQTT_CLIENT", ESP_LOG_VERBOSE);
  13.     esp_log_level_set("MQTT_EXAMPLE", ESP_LOG_VERBOSE);
  14.     esp_log_level_set("TRANSPORT_TCP", ESP_LOG_VERBOSE);
  15.     esp_log_level_set("TRANSPORT_SSL", ESP_LOG_VERBOSE);
  16.     esp_log_level_set("TRANSPORT", ESP_LOG_VERBOSE);
  17.     esp_log_level_set("OUTBOX", ESP_LOG_VERBOSE);
  18.  
  19.  
  20.     esp_mqtt_client_config_t mqtt_cfg = {
  21.         .uri = CONFIG_BROKER_URL
  22.     };
  23.     esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
  24.     esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, client);
  25.     esp_mqtt_client_start(client);
  26.     esp_mqtt_client_publish(client,topic,message, 0, 1, 0); // <<<<< If we remove this LINE Everything run nice. Does not work even passing a string "quoted".
  27.     esp_mqtt_client_destroy(client);
  28. }
ERROR LOG

  1. Let the WIFI connection progress ...
  2. I (6164) wifi: new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1
  3. I (6164) wifi: state: init -> auth (b0)
  4. I (6184) wifi: state: auth -> assoc (0)
  5. I (6194) wifi: state: assoc -> run (10)
  6. I (6214) wifi: connected with MIWIFI_SSXU, aid = 3, channel 1, BW20, bssid = 50:78:b3:d4:a7:a4, security type: 4, phy: bgn, rssi: -67
  7. I (6224) wifi: pm start, type: 1
  8.  
  9. I (6334) wifi: AP's beacon interval = 102400 us, DTIM period = 1
  10. I (9364) esp_netif_handlers: sta ip: 192.168.1.154, mask: 255.255.255.0, gw: 192.168.1.1
  11. I (9364) power_save: got ip: 192.168.1.154
  12. Box Connected and ready to send data.
  13. Sending data to local broker...
  14. JSON len = 73  
  15. JSON Payload ={"temperature":31.54296875,"humidity":39.154052734375,"co2":400,"tvoc":0}
  16. MQTT Topic : dt/h1/r1/s2
  17. MQTT Data : {"temperature":31.54296875,"humidity":39.154052734375,"co2":400,"tvoc":0}
  18. I (11064) MQTTS_FUNCTIONS: [APP] Startup..
  19. I (11064) MQTTS_FUNCTIONS: [APP] Free memory: 233908 bytes
  20. I (11074) MQTTS_FUNCTIONS: [APP] IDF version: v4.1-dev-1086-g93a8603c5-dirty
  21. I (11084) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
  22. Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.
  23. Core 0 register dump:
  24. PC      : 0x400d7ed4  PS      : 0x00060f30  A0      : 0x800d5c07  A1      : 0x3ffbb280  
  25. 0x400d7ed4: mqtt_get_type at /home/noid/esp/esp-idf/components/mqtt/esp-mqtt/lib/include/mqtt_msg.h:93
  26.  (inlined by) esp_mqtt_client_publish at /home/noid/esp/esp-idf/components/mqtt/esp-mqtt/mqtt_client.c:1317
  27.  
  28. A2      : 0x3ffc6644  A3      : 0x00000000  A4      : 0x3ffc6500  A5      : 0x00000049  
  29. A6      : 0x00000001  A7      : 0x3ffbb290  A8      : 0x800d7e9d  A9      : 0x3ffbb260  
  30. A10     : 0x3ffc6670  A11     : 0x3f403bd8  A12     : 0x3ffc6500  A13     : 0x00000049  
  31. A14     : 0x00000001  A15     : 0x00000000  SAR     : 0x0000000c  EXCCAUSE: 0x0000001c  
  32. EXCVADDR: 0x00000000  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xfffffffc  
  33.  
  34. ELF file SHA256: 41bef4c4b700d514d8ccaaa205a3e43dd41d361fe5f5919162a398cd668de929
  35.  
  36. Backtrace: 0x400d7ed1:0x3ffbb280 0x400d5c04:0x3ffbb2d0 0x400d6598:0x3ffbb370 0x400d208a:0x3ffbb3b0 0x40094079:0x3ffbb3d0
  37. 0x400d7ed1: esp_mqtt_client_publish at PATH/esp-idf/components/mqtt/esp-mqtt/mqtt_client.c:1316
  38.  
  39. 0x400d5c04: mqtt_send at ../main/wds_f/mqtt_functions.c:168
  40.  
  41. 0x400d6598: app_main at /../main/wisedomsensor_main.c:222
  42.  
  43. 0x400d208a: main_task at PATH/esp-idf/components/esp32/cpu_start.c:569
  44.  
  45. 0x40094079: vPortTaskWrapper at PATH/esp-idf/components/freertos/port.c:143
  46.  
  47.  
  48. Rebooting...

woipdomain
Posts: 3
Joined: Tue Feb 04, 2020 10:35 am

Re: Can't pass variables to MQTT function based on esp-idf example MQTT/tcp

Postby woipdomain » Wed Feb 05, 2020 12:00 pm

Hi all ,

Will be very nice if someone give a clue on how to FIX this MQTT problem.

Thank you in advance!

Santi .-

woipdomain
Posts: 3
Joined: Tue Feb 04, 2020 10:35 am

Re: Can't pass variables to MQTT function based on esp-idf example MQTT/tcp

Postby woipdomain » Fri Feb 07, 2020 8:38 am

Hellooo ! , Have somebody any clue about why the system is hanging?

Maybe could seem too obbious for some of you , but we spend 2 weeks trying and trying without success .-

Please!

Thank you !

Who is online

Users browsing this forum: No registered users and 18 guests