- Project has moved to: https://github.com/tuanpmt/espmqtt/tree/master/examples
- This project will not be developed, and all issues will not be supported.
Apache 2.0
ESP32 MQTT sample project for
Home Page: https://github.com/tuanpmt/espmqtt
License: Apache License 2.0
Apache 2.0
make[1]: Leaving directory /home/petter/work/esp32-mqtt/build/vfs' Target 'vfs-build' responsible for '/home/petter/work/esp32-mqtt/build/vfs/libvfs.a' make -C /home/petter/work/esp32-mqtt/build/wpa_supplicant -f /home/petter/work/esp-idf/make/component_wrapper.mk COMPONENT_MAKEFILE=/home/petter/work/esp-idf/components/wpa_supplicant/component.mk COMPONENT_NAME=wpa_supplicant build make[1]: Entering directory
/home/petter/work/esp32-mqtt/build/wpa_supplicant'
make[1]: Leaving directory /home/petter/work/esp32-mqtt/build/wpa_supplicant' Target 'wpa_supplicant-build' responsible for '/home/petter/work/esp32-mqtt/build/wpa_supplicant/libwpa_supplicant.a' make -C /home/petter/work/esp32-mqtt/build/xtensa-debug-module -f /home/petter/work/esp-idf/make/component_wrapper.mk COMPONENT_MAKEFILE=/home/petter/work/esp-idf/components/xtensa-debug-module/component.mk COMPONENT_NAME=xtensa-debug-module build make[1]: Entering directory
/home/petter/work/esp32-mqtt/build/xtensa-debug-module'
make[1]: Leaving directory /home/petter/work/esp32-mqtt/build/xtensa-debug-module' Target 'xtensa-debug-module-build' responsible for '/home/petter/work/esp32-mqtt/build/xtensa-debug-module/libxtensa-debug-module.a' make -C /home/petter/work/esp32-mqtt/build/main -f /home/petter/work/esp-idf/make/component_wrapper.mk COMPONENT_MAKEFILE=/home/petter/work/esp32-mqtt/main/component.mk COMPONENT_NAME=main build make[1]: Entering directory
/home/petter/work/esp32-mqtt/build/main'
/home/petter/work/esp-idf/make/component_common.mk:1: Deprecated feature: No longer necessary to include component_common.mk from /home/petter/work/esp32-mqtt/main/component.mk
xtensa-esp32-elf-gcc -std=gnu99 -Og -ggdb -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -Wno-old-style-declaration -DWITH_POSIX -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"' -DHAVE_CONFIG_H -DBUID_TIME="2017- 5月-06_23:45:47_CST" -Wno-error=format= -DLOCAL_CONFIG_AVAILABLE -DESP_PLATFORM -D IDF_VER="v2.0-rc1-401-gf9fba35-dirty" -MMD -MP -I /home/petter/work/esp32-mqtt/main/include -I /home/petter/work/esp-idf/components/app_update/include -I /home/petter/work/esp-idf/components/bootloader_support/include -I /home/petter/work/esp-idf/components/bt/include -I /home/petter/work/esp-idf/components/coap/port/include -I /home/petter/work/esp-idf/components/coap/port/include/coap -I /home/petter/work/esp-idf/components/coap/libcoap/include -I /home/petter/work/esp-idf/components/coap/libcoap/include/coap -I /home/petter/work/esp-idf/components/cxx/include -I /home/petter/work/esp-idf/components/driver/include -I /home/petter/work/esp-idf/components/esp32/include -I /home/petter/work/esp32-mqtt/components/espmqtt/include -I /home/petter/work/esp-idf/components/ethernet/include -I /home/petter/work/esp-idf/components/expat/port/include -I /home/petter/work/esp-idf/components/expat/include/expat -I /home/petter/work/esp-idf/components/fatfs/src -I /home/petter/work/esp-idf/components/freertos/include -I /home/petter/work/esp-idf/components/jsmn/include/ -I /home/petter/work/esp-idf/components/json/include -I /home/petter/work/esp-idf/components/json/port/include -I /home/petter/work/esp-idf/components/log/include -I /home/petter/work/esp-idf/components/lwip/include/lwip -I /home/petter/work/esp-idf/components/lwip/include/lwip/port -I /home/petter/work/esp-idf/components/lwip/include/lwip/posix -I /home/petter/work/esp-idf/components/lwip/apps/ping -I /home/petter/work/esp-idf/components/mbedtls/port/include -I /home/petter/work/esp-idf/components/mbedtls/include -I /home/petter/work/esp-idf/components/mdns/include -I /home/petter/work/esp-idf/components/micro-ecc/micro-ecc -I /home/petter/work/esp-idf/components/newlib/include -I /home/petter/work/esp-idf/components/newlib/platform_include -I /home/petter/work/esp-idf/components/nghttp/port/include -I /home/petter/work/esp-idf/components/nghttp/include -I /home/petter/work/esp-idf/components/nvs_flash/include -I /home/petter/work/esp-idf/components/openssl/include -I /home/petter/work/esp-idf/components/sdmmc/include -I /home/petter/work/esp-idf/components/spi_flash/include -I /home/petter/work/esp-idf/components/tcpip_adapter/include -I /home/petter/work/esp-idf/components/ulp/include -I /home/petter/work/esp-idf/components/vfs/include -I /home/petter/work/esp-idf/components/wpa_supplicant/include -I /home/petter/work/esp-idf/components/wpa_supplicant/port/include -I /home/petter/work/esp-idf/components/xtensa-debug-module/include -I /home/petter/work/esp32-mqtt/build/include -I. -c /home/petter/work/esp32-mqtt/main/./app_main.c -o app_main.o
When the client subscribes to multiple topics with a wild card and receives multiple retained messages, the callback is only called once. The data is somehow in the data buffer, but I expect that the callback function is called for every message.
I think the problem is in line 376 in mqtt.c:
if (client->mqtt_state.message_length_read >= client->mqtt_state.message_length)
this if statement is probably always true and so the loop stops after one run even when there are more messages left in the buffer
Could you please give me a quick explanation on how/where to install library. I am using Eclipse with ESP-IDF for ESP32 - pretty new to this environment. thanks
Hello everyone,
I am new to ESP32 and is using this MQTT library posted by tuanpmt.
To get started, I need to do some basic operations like Subscribing and Publishing a particular TOPIC.
Can anyone give me some good documentation/literature/examples to see how to initialize the structures in this library like mqtt_state, connect_info, xSendingQueue, send_rb etc?
As you know these structures are needed to initialize the mutt_client which is eventually needed to subscribe to the topic.
Thanks
Periodically, when the network is disconnected, I am getting a storeProhibited crash.
The serial monitor says "Network Disconnected" just before the crash.
Interestingly, not everytime the network is "disconnected" does this message pop up. For example it usually does not show when I pair the device with my phone's personal hotspot and toggle the hotspot off and back on. I have attempted to be very careful to only publish when the network connection is active.
When I comment out the mqtt_destroy() line in the code it seems to fix the problem. This does not feel like a long term solution however, as there may be a memory leak or something of the sort?
Hello, I tried to run the sample file on the MQTT connection, but the connection was refused, could anyone help me to understand what the problem is?
Thank you.
I (139) MQTT_SAMPLE: start the WIFI SSID:[Felipe] password:[******]
I (170) phy: phy_version: 359.0, e79c19d, Aug 31 2017, 17:06:07, 0, 0
I (171) wifi: mode : sta (30:ae:a4:0b:50:4c)
I (1136) wifi: n:8 0, o:1 0, ap:255 255, sta:8 0, prof:1
I (2123) wifi: state: init -> auth (b0)
I (2128) wifi: state: auth -> assoc (0)
I (2147) wifi: state: assoc -> run (10)
I (2185) wifi: connected with Felipe, channel 8
I (3030) event: ip: 192.168.43.107, mask: 255.255.255.0, gw: 192.168.43.1
[MQTT INFO] Starting mqtt task
[MQTT INFO] Resolve dns for domain: test.mosquitto.org
[MQTT INFO] Connecting to server 37.187.106.16:8883,45858
[MQTT INFO] Creating SSL object...
[MQTT INFO] Start SSL connect..
I (5148) wifi: pm start, type:0
[MQTT INFO] Connected!
[MQTT INFO] Connected to server test.mosquitto.org:8883
[MQTT INFO] Sending MQTT CONNECT message, type: 1, id: 0000
[MQTT INFO] Reading MQTT CONNECT response message
[MQTT WARN] Connection refused, not authorized
[MQTT INFO] Closing client socket
[MQTT INFO] Client destroyed
I am trying to subscribe to topic but when it fails after some time I retry and if it fails I stop mqtt to disconnect from broker but it does not.
[MQTT INFO] Connected to MQTT broker, create sending thread before call connected callback
[MQTT INFO] mqtt_sending_task
I (39213) BYTELENSCLIENT: Connected to BROKER.
[MQTT INFO] Queue subscribe, topic"topic_infoRX", id: 1
[MQTT INFO] Sending...38 bytes
[MQTT INFO] Queue subscribe, topic"topic_listRX", id: 2
[MQTT INFO] Sending...38 bytes
[MQTT INFO] mqtt_start_receive_schedule
I (41803) wifi: active cnt: 5
I (51803) wifi: send null to keep active
I (61803) wifi: send null to keep active
I (71803) wifi: send null to keep active
I (71873) GATTC_DEMO: Ticker: conn: 0 ,Noti: 0, scan: 0
I (71873) GATTC_DEMO: Ticker: wificon: 1, mqttcon: 1, mqttsub: 0
I (71873) GATTC_DEMO: Ticker: MQTT broker not Subscribed, retrying 1 <-- here I do mqtt_stop
I (81803) wifi: send null to keep active
I (91803) wifi: send null to keep active
[MQTT INFO] Sending pingreq
I (101803) wifi: active cnt: 1
I (106873) GATTC_DEMO: Ticker: conn: 0 ,Noti: 0, scan: 0
I (106873) GATTC_DEMO: Ticker: wificon: 1, mqttcon: 0, mqttsub: 0
I (106873) GATTC_DEMO: Ticker: MQTT broker not Connected, retrying 2 <-- this is just flag MQTT not disconnect from broker.
I (111803) wifi: send null to keep active
I (121803) wifi: send null to keep active
I (131803) wifi: send null to keep active
I (141803) wifi: send null to keep active
I (141873) GATTC_DEMO: Ticker: conn: 0 ,Noti: 0, scan: 0
I (141873) GATTC_DEMO: Ticker: wificon: 1, mqttcon: 0, mqttsub: 0
I (141873) GATTC_DEMO: Ticker: MQTT broker not Connected, retrying 3
I (151813) wifi: send null to keep active
[MQTT INFO] Sending pingreq
I (161813) wifi: active cnt: 1
Hello Tuan,
Great work. Code makes sense to me but I could not further dig deep into the problem.
I have tried using your MQTT example.
I successfully get connected to Adafruit MQTT server but seems like subscribing does not work fine for me.
Here is the MQTT log I get:
`[MQTT INFO] Starting mqtt task
[MQTT INFO] Resolve dns for domain: io.adafruit.com
[MQTT INFO] Connecting to server 52.5.238.97:8883,45858
[MQTT INFO] Creating SSL object...
[MQTT INFO] Start SSL connect..
[MQTT INFO] Connected!
[MQTT INFO] Connected to server io.adafruit.com:8883
[MQTT INFO] Sending MQTT CONNECT message, type: 1, id: 0000
[MQTT INFO] Reading MQTT CONNECT response message
I (5983) wifi: pm start, type:0
[MQTT INFO] Connected
[MQTT INFO] Connected to MQTT broker, create sending thread before call connected callback
[MQTT INFO] mqtt_sending_task
[MQTT INFO] Sending...21 bytes
[MQTT INFO] Queue subscribe, topic"Lock_Status", id: 1
[MQTT INFO] Sending...18 bytes
[MQTT INFO] mqtt_start_receive_schedule
[MQTT INFO] Read len -1
[MQTT INFO] Read error 0
[MQTT INFO] Closing client socket
[MQTT INFO] Client destroyed
`
In the connected callback I am only using subscribe, I have commented publishing for now but the unsuccessful read problem from mqtt_start_receive_schedule() function stays the same:
`void connected_cb(void *self, void *params)
{
mqtt_client *client = (mqtt_client *)self;
mqtt_subscribe(client, "Lock_Status", 0);
//mqtt_publish(client, "/test", "howdy!", 6, 0, 0);
}
Can you please help me figuring out the problem.
Thanks a lot.`
Hey,
the heap is getting smaller with every publish till it runs out to 0 bytes.
There is reason code 5 error. What is this error?
[MQTT INFO] Connected to server 52.5.238.97:1883
[MQTT INFO] Sending MQTT CONNECT message, type: 1, id: 0000
[MQTT INFO] Reading MQTT CONNECT response message
[MQTT WARN] Connection refuse, reason code: 5
[MQTT INFO] Connecting to server 52.5.238.97:1883,23303
[MQTT INFO] Connected!
[MQTT INFO] Connected to server 52.5.238.97:1883
[MQTT INFO] Sending MQTT CONNECT message, type: 1, id: 0000
[MQTT INFO] Reading MQTT CONNECT response message
[MQTT WARN] Connection refuse, reason code: 5
[MQTT INFO] Connecting to server 52.5.238.97:1883,23303
[MQTT INFO] Connected!
[MQTT INFO] Connected to server 52.5.238.97:1883
[MQTT INFO] Sending MQTT CONNECT message, type: 1, id: 0000
[MQTT INFO] Reading MQTT CONNECT response message
[MQTT WARN] Connection refuse, reason code: 5
[MQTT INFO] Connecting to server 52.5.238.97:1883,23303
[MQTT INFO] Connected!
[MQTT INFO] Connected to server 52.5.238.97:1883
[MQTT INFO] Sending MQTT CONNECT message, type: 1, id: 0000
[MQTT INFO] Reading MQTT CONNECT response message
[MQTT WARN] Connection refuse, reason code: 5
[MQTT INFO] Connecting to server 52.5.238.97:1883,23303
[MQTT INFO] Connected!
[MQTT INFO] Connected to server 52.5.238.97:1883
[MQTT INFO] Sending MQTT CONNECT message, type: 1, id: 0000
[MQTT INFO] Reading MQTT CONNECT response message
[MQTT WARN] Connection refuse, reason code: 5
[MQTT INFO] Connecting to server 52.5.238.97:1883,23303
[MQTT INFO] Connected!
[MQTT INFO] Connected to server 52.5.238.97:1883
[MQTT INFO] Sending MQTT CONNECT message, type: 1, id: 0000
[MQTT INFO] Reading MQTT CONNECT response message
[MQTT WARN] Connection refuse, reason code: 5
[MQTT INFO] Connecting to server 52.5.238.97:1883,23303
[MQTT INFO] Connected!
[MQTT INFO] Connected to server 52.5.238.97:1883
[MQTT INFO] Sending MQTT CONNECT message, type: 1, id: 0000
[MQTT INFO] Reading MQTT CONNECT response message
[MQTT WARN] Connection refuse, reason code: 5
[MQTT INFO] Connecting to server 52.5.238.97:1883,23303
[MQTT INFO] Connected!
[MQTT INFO] Connected to server 52.5.238.97:1883
[MQTT INFO] Sending MQTT CONNECT message, type: 1, id: 0000
[MQTT INFO] Reading MQTT CONNECT response message
[MQTT WARN] Connection refuse, reason code: 5
[MQTT INFO] Connecting to server 52.5.238.97:1883,23303
[MQTT INFO] Connected!
[MQTT INFO] Connected to server 52.5.238.97:1883
[MQTT INFO] Sending MQTT CONNECT message, type: 1, id: 0000
[MQTT INFO] Reading MQTT CONNECT response message
[MQTT WARN] Connection refuse, reason code: 5
[MQTT INFO] Connecting to server 52.5.238.97:1883,23303
[MQTT INFO] Connected!
[MQTT INFO] Connected to server 52.5.238.97:1883
[MQTT INFO] Sending MQTT CONNECT message, type: 1, id: 0000
[MQTT INFO] Reading MQTT CONNECT response message
[MQTT WARN] Connection refuse, reason code: 5
[MQTT INFO] Connecting to server 52.5.238.97:1883,23303
[MQTT INFO] Connected!
[MQTT INFO] Connected to server 52.5.238.97:1883
[MQTT INFO] Sending MQTT CONNECT message, type: 1, id: 0000
[MQTT INFO] Reading MQTT CONNECT response message
[MQTT WARN] Connection refuse, reason code: 5
[MQTT INFO] Connecting to server 52.5.238.97:1883,23303
[MQTT INFO] Connected!
[MQTT INFO] Connected to server 52.5.238.97:1883
[MQTT INFO] Sending MQTT CONNECT message, type: 1, id: 0000
[MQTT INFO] Reading MQTT CONNECT response message
[MQTT WARN] Connection refuse, reason code: 5
[MQTT INFO] Connecting to server 52.5.238.97:1883,23303
[MQTT INFO] Connected!
[MQTT INFO] Connected to server 52.5.238.97:1883
[MQTT INFO] Sending MQTT CONNECT message, type: 1, id: 0000
[MQTT INFO] Reading MQTT CONNECT response message
[MQTT WARN] Connection refuse, reason code: 5
It publishes lwt message but the message is blank.
Tested with local mosquitto server.
Esp-idf version v3.1-dev-239-g1c3dd23f
Dear @tuanpmt, we would like to report a bug in this repo, it happened when the internet connection between ESP32 to the internet was interrupted. The program in ESP32 was trying to publish data to the broker until the buffer was full because the ESP32 late to realize that it was not properly connected to broker after it experienced time out beyond keep alive time. The ring buffer was full and was not properly removed when your library was trying to overwrite the ring buffer. This is our prediction. Have you experienced something like this ?
I tried to connect to the ARTIK samsung's cloud using mqtts But I got errors like below.
[MQTT INFO] Connecting to server 52.200.124.224:8883,45858
[MQTT INFO] Creating SSL object...
[MQTT INFO] Start SSL connect..
[MQTT INFO] Connected!
[MQTT INFO] Connected to server api.artik.cloud:8883
[MQTT INFO] Sending MQTT CONNECT message, type: 1, id: 0000
[MQTT INFO] Reading MQTT CONNECT response message
I (12968) wifi: pm start, type:0
[MQTT ERROR] Error network response
[MQTT INFO] Closing client socket
[MQTT INFO] Client destroyed
got the package with
git clone --recursive https://github.com/tuanpmt/esp32-mqtt
and but there is componet -> mqtt when
make menuconfig
Shall I copy $PROJ_PATH/components/espmqtt to the dorectpru $PROJ_PATH/main?
.[0;32mI (3345) event: ip: 192.168.1.129, mask: 255.255.255.0, gw: 192.168.1.1.[0m
[MQTT INFO] Starting mqtt task
[MQTT INFO] Resolve dns for domain: broker.hivemq.com
[MQTT INFO] Connecting to server 35.156.1.237:1883,23303
[MQTT INFO] Connected!
[MQTT INFO] Connected to server broker.hivemq.com:1883
[MQTT INFO] Sending MQTT CONNECT message, type: 1, id: 0000
[MQTT INFO] Reading MQTT CONNECT response message
I (12649) wifi: pm start, type:0
[MQTT ERROR] Error network response
[MQTT INFO] Closing client socket
[MQTT INFO] Client destroyed
also how do I disable security? I went to mqtt_config.h and just commented #define CONFIG_MQTT_SECURITY_ON
is it the right way ?
Downloaded the Tuan MQTT example and the dependency:
esp32-mqtt
espmqtt
Restructured for Platformio, all files in src.
Build errors centered on incomplete removal of reconnect cxall back and a variable BUIDTIME that is undefined. Removed the reconnect references and the reference to BUIDTIME and obtained a clean compile after adding defines for SSID and PASSWORD variables. Did this by #include USER config file and corected varable names.
Using an ESP32thing from Sparkfun. This example worked prior to the recent updates. Now it fails and never gets to the MQTT part.
Log below:
Executing task: platformio.exe device monitor <
--- Miniterm on COM14 115200,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
ets Jun 8 2016 00:22:57
rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0x00
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0008,len:8
load:0x3fff0010,len:4408
load:0x40078000,len:11072
load:0x40080000,len:252
entry 0x40080034
␛[0;32mI (29) boot: ESP-IDF 2.210.0 2nd stage bootloader␛[0m
␛[0;32mI (29) boot: compile time 13:16:38␛[0m
␛[0;32mI (62) boot: Enabling RNG early entropy source...␛[0m
␛[0;32mI (62) boot: SPI Speed : 80MHz␛[0m
␛[0;32mI (62) boot: SPI Mode : DIO␛[0m
␛[0;32mI (74) boot: SPI Flash Size : 4MB␛[0m
␛[0;32mI (86) boot: Partition Table:␛[0m
␛[0;32mI (97) boot: ## Label Usage Type ST Offset Length␛[0m
␛[0;32mI (120) boot: 0 nvs WiFi data 01 02 00009000 00006000␛[0m
␛[0;32mI (143) boot: 1 phy_init RF data 01 01 0000f000 00001000␛[0m
␛[0;32mI (166) boot: 2 factory factory app 00 00 00010000 00100000␛[0m
␛[0;32mI (190) boot: End of partition table␛[0m
␛[0;32mI (202) boot: Disabling RNG early entropy source...␛[0m
␛[0;32mI (220) boot: Loading app partition at offset 00010000␛[0m
␛[0;32mI (1085) boot: segment 0: paddr=0x00010018 vaddr=0x00000000 size=0x0ffe8 ( 65512) ␛[0m
␛[0;32mI (1086) boot: segment 1: paddr=0x00020008 vaddr=0x3f400010 size=0x1812c ( 98604) map␛[0m
␛[0;32mI (1102) boot: segment 2: paddr=0x0003813c vaddr=0x3ffc0000 size=0x02ca8 ( 11432) load␛[0m
␛[0;32mI (1131) boot: segment 3: paddr=0x0003adec vaddr=0x40080000 size=0x00400 ( 1024) load␛[0m
␛[0;32mI (1156) boot: segment 4: paddr=0x0003b1f4 vaddr=0x40080400 size=0x12c14 ( 76820) load␛[0m
␛[0;32mI (1204) boot: segment 5: paddr=0x0004de10 vaddr=0x400c0000 size=0x00000 ( 0) load␛[0m
␛[0;32mI (1208) boot: segment 6: paddr=0x0004de18 vaddr=0x00000000 size=0x021f0 ( 8688) ␛[0m
␛[0;32mI (1233) boot: segment 7: paddr=0x00050010 vaddr=0x400d0018 size=0x6a684 (435844) map␛[0m
␛[0;32mI (1260) cpu_start: Pro cpu up.␛[0m
␛[0;32mI (1271) cpu_start: Starting app cpu, entry point is 0x40080e74␛[0m
␛[0;32mI (0) cpu_start: App cpu up.␛[0m
␛[0;32mI (1304) heap_alloc_caps: Initializing. RAM available for dynamic allocation:␛[0m
␛[0;32mI (1326) heap_alloc_caps: At 3FFAFF10 len 000000F0 (0 KiB): DRAM␛[0m
␛[0;32mI (1347) heap_alloc_caps: At 3FFC81F0 len 00017E10 (95 KiB): DRAM␛[0m
␛[0;32mI (1368) heap_alloc_caps: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM␛[0m
␛[0;32mI (1389) heap_alloc_caps: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM␛[0m
␛[0;32mI (1411) heap_alloc_caps: At 40093014 len 0000CFEC (51 KiB): IRAM␛[0m
␛[0;32mI (1432) cpu_start: Pro cpu start user code␛[0m
␛[0;32mI (1487) cpu_start: Starting scheduler on PRO CPU.␛[0m
␛[0;32mI (1489) cpu_start: Starting scheduler on APP CPU.␛[0m
␛[0;32mI (1489) MQTT_SAMPLE: [APP] Startup..␛[0m
␛[0;32mI (1489) MQTT_SAMPLE: [APP] Free memory: 210708 bytes␛[0m
␛[0;32mI (1499) MQTT_SAMPLE: [APP] SDK version: master␛[0m
I (1529) wifi: wifi firmware version: 407bb27
I (1529) wifi: config NVS flash: enabled
I (1529) wifi: config nano formating: disabled
␛[0;32mI (1529) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE␛[0m
␛[0;32mI (1539) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE␛[0m
I (1579) wifi: Init dynamic tx buffer num: 32
I (1579) wifi: Init dynamic rx buffer num: 32
I (1579) wifi: wifi driver task: 3ffcbec4, prio:23, stack:4096
I (1579) wifi: Init static rx buffer num: 10
I (1589) wifi: Init dynamic rx buffer num: 32
I (1589) wifi: Init rx ampdu len mblock:7
I (1589) wifi: Init lldesc rx ampdu entry mblock:4
I (1599) wifi: wifi power manager task: 0x3ffd4fbc prio: 21 stack: 2560
So ffar so good, I think, to here
␛[0;32mI (1599) MQTT_SAMPLE: start the WIFI SSID:[IOTDeva] password:[******]␛[0m
SSID and Password are coreect and work with other applications
I (1609) wifi: wifi timer task: 3ffd6024, prio:22, stack:3584
␛[0;32mI (1649) phy: phy_version: 355.1, 59464c5, Jun 14 2017, 20:25:06, 1, 0␛[0m
I (1649) wifi: mode : sta (24:0a:c4:05:cf:7c)
I (1889) wifi: n:2 0, o:1 0, ap:255 255, sta:2 0, prof:1
I (2869) wifi: state: init -> auth (b0)
I (3869) wifi: state: auth -> init (2)
I (3869) wifi: n:2 0, o:2 0, ap:255 255, sta:2 0, prof:1
I (3989) wifi: n:2 0, o:2 0, ap:255 255, sta:2 0, prof:1
I (3989) wifi: state: init -> auth (b0)
I (4989) wifi: state: auth -> init (2)
I (4999) wifi: n:2 0, o:2 0, ap:255 255, sta:2 0, prof:1
I (5119) wifi: n:2 0, o:2 0, ap:255 255, sta:2 0, prof:1
I (5119) wifi: state: init -> auth (b0)
I (6119) wifi: state: auth -> init (2)
I (6119) wifi: n:2 0, o:2 0, ap:255 255, sta:2 0, prof:1
I (6239) wifi: n:2 0, o:2 0, ap:255 255, sta:2 0, prof:1
I (6239) wifi: state: init -> auth (b0)
I (7239) wifi: state: auth -> init (2)
I (7239) wifi: n:2 0, o:2 0, ap:255 255, sta:2 0, prof:1
I (7359) wifi: n:2 0, o:2 0, ap:255 255, sta:2 0, prof:1
I (7359) wifi: state: init -> auth (b0)
This latter part repeats for ever and no MQTT subscription occurs either with mosquitto or my local broker
Any help appreciated.
Thanks
Frank
Hi,
I am using esp32 DEVKITV1. Using Arduino IDE. If I connect the chip right out of the box, I get all the chip information at the serial monitor. If I upload any code, the chip loops on SW_RESET
Here a copy:
ets Jun 8 2016 00:22:57
rst:0x3 (SW_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1100
load:0x40078000,len:9232
load:0x40080400,len:6400
entry 0x400806a8
ets Jun 8 2016 00:22:57
and it goes on and on reseting.
Any clues will be highly appreciated.
esp32 before uploading code.txt
The following includes should be added to app_main.c to compile properly in the latest IDF:
#include "nvs_flash.h"
#include "esp_event_loop.h"
Will we ever see this?
The link to the "new" version is a 404
Anyone looking should go to https://github.com/espressif/esp-mqtt
Working with da0e976, using espmqtt component @ espressif/esp-mqtt@2967332
Compilation fails with:
/Users/david/esp32/projects/esp32-mqtt/main/./app_main.c:97:5: error: unknown field 'reconnect_cb' specified in initializer
https://github.com/tuanpmt/espmqtt/blob/2967332b95454d4b53068a0d5484ae60e312eb12/include/mqtt.h#L40 does not declare a field "reconnect_cb" - perhaps the espmqtt component has not been pushed by the author to GitHub at the same time as this project, resulting in a mismatched submodule?
Workaround is obviously to comment out the line @
Line 97 in da0e976
Hi,
its nice project. Comprehensive and easy to use. I cant find it, is there option to set last will in it?
The original code stops at:
[APP] Startup..
[APP] Free memory: 262052 bytes
[APP] SDK version: 1.0.0(3e67f0f), Build time: 2016-Nov-04_10:46:54_EET
[APP] Start, connect to Wifi network: Shirkan ..
/work/esp32/esp-idf/components/freertos/./queue.c:716 (xQueueGenericSend)- assert failed!
Guru Meditation Error: Core 0 panic'ed (Unhandled debug exception)
due to unsynchronized threads for connect and mqtt
the following changes resolved the issue for me:
I used the 'original' startup / wifi connect code from the esp-idf samples (here: 03-http)
and added a sync so the mqtt thread does not start before the network is set up properly:
void app_main()
{
nvs_flash_init();
system_init();
initialise_wifi();
//xTaskCreate(&http_get_task, "http_get_task", 2048, NULL, 5, NULL);
/* Wait for the callback to set the CONNECTED_BIT in the
event group.
*/
xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT,
false, true, portMAX_DELAY);
ESP_LOGI(TAG, "Connected to AP");
// Notice that, all callback will called in mqtt_task
// All function publish, subscribe
mqtt_start(&settings);
}
Hi, I've tried to install the app onto my devboard (having set things like the MQTT server, ssid and password and I get this constantly.
My WiFi is mac filtered but it doesn't seem to be getting even that far (as in joining the network). It appears to be crashing at this line
strcpy(cfg.sta.ssid, WIFI_SSID);
strcpy(cfg.sta.password, WIFI_PASS);
But both are set
Any idea how to troubleshoot ?
ets Jun 8 2016 00:22:57
rst:0x3 (SW_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0x00
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3ffc0000,len:0
load:0x3ffc0000,len:920
load:0x40078000,len:2724
ho 0 tail 12 room 4
load:0x40098000,len:508
entry 0x40098118
I (266) heap_alloc_caps: Initializing heap allocator:
I (267) heap_alloc_caps: Region 19: 3FFB4E70 len 0002B190 tag 0
I (283) heap_alloc_caps: Region 25: 3FFE8000 len 00018000 tag 1
I (344) cpu_start: Pro cpu up.
I (378) cpu_start: Starting app cpu, entry point is 0x4008094c
I (0) cpu_start: App cpu up.
rtc v112 Sep 22 2016 16:08:39art user code
XTAL 40M
[0;32mI (630) cpu_start: Starting scheduler on PRO CPU.
I (193) cpu_start: Starting scheduler on APP CPU.
[APP] Startup..
[APP] Free memory: 258408 bytes
[APP] SDK version: 1.0.0(b95f5cf), Build time: 2016-Oct-09_11:04:38_AEDT
[APP] Start, connect to Wifi network: xxx ..
Guru Meditation Error of type LoadProhibited occurred on core 0. Exception was unhandled.
Register dump:
PC : 400d545e PS : 00060330 A0 : 800d414f A1 : 3ffb6c50
A2 : 00000001 A3 : 3ffb8e8c A4 : 3ffb27ec A5 : 00000000
A6 : 00000003 A7 : 00000001 A8 : 00000008 A9 : 3ffb6c30
A10 : 3ffb8e8c A11 : 400d0af8 A12 : 00000000 A13 : 3f401820
A14 : 00000001 A15 : 00000007 SAR : 0000001d EXCCAUSE: 0000001c
EXCVADDR: 0000000c LBEG : 4000c46c LEND : 4000c477 LCOUNT : ffffffff
Rebooting...
ets Jun 8 2016 00:22:57
rst:0x3 (SW_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0x00
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3ffc0000,len:0
load:0x3ffc0000,len:920
load:0x40078000,len:2724
ho 0 tail 12 room 4
load:0x40098000,len:508
entry 0x40098118
I (266) heap_alloc_caps: Initializing heap allocator:
I (267) heap_alloc_caps: Region 19: 3FFB4E70 len 0002B190 tag 0
I (283) heap_alloc_caps: Region 25: 3FFE8000 len 00018000 tag 1
I (344) cpu_start: Pro cpu up.
I (378) cpu_start: Starting app cpu, entry point is 0x4008094c
I (0) cpu_start: App cpu up.
I (471) cpu_start: Pro cpu start user code
rtc v112 Sep 22 2016 16:08:39
XTAL 40M
[0;32mI (630) cpu_start: Starting scheduler on PRO CPU.
I (193) cpu_start: Starting scheduler on APP CPU.
[APP] Startup..
[APP] Free memory: 258408 bytes
[APP] SDK version: 1.0.0(b95f5cf), Build time: 2016-Oct-09_11:04:38_AEDT
[APP] Start, connect to Wifi network: xxx ..
Guru Meditation Error of type LoadProhibited occurred on core 0. Exception was unhandled.
Register dump:
PC : 400d545e PS : 00060330 A0 : 800d414f A1 : 3ffb6c50
A2 : 00000001 A3 : 3ffb8e8c A4 : 3ffb27ec A5 : 00000000
A6 : 00000003 A7 : 00000001 A8 : 00000008 A9 : 3ffb6c30
A10 : 3ffb8e8c A11 : 400d0af8 A12 : 00000000 A13 : 3f401820
A14 : 00000001 A15 : 00000007 SAR : 0000001d EXCCAUSE: 0000001c
EXCVADDR: 0000000c LBEG : 4000c46c LEND : 4000c477 LCOUNT : ffffffff
Rebooting...
i use cjson to handle string i received when subcribe a topic
But if I use some cJSON function in event_handler loop in data_cb, it'll be wrong
When i use outside the event loop, it works fine. Can you help me, here is my code in data_cb
``void data_cb(void *self, void *params)
{
mqtt_client *client = (mqtt_client *)self;
mqtt_event_data_t *event_data = (mqtt_event_data_t *)params;
if(event_data->data_offset == 0) {
mqtt_publish(client,"devices/gateway1/pub","done",4,0,0);
}
char *data = malloc(event_data->data_length + 1);
memcpy(data, event_data->data, event_data->data_length);
data[event_data->data_length] = 0;
char *items = "{\"items\": \"huy\"}";
cJSON *request_json = cJSON_Parse(items);
char *item = cJSON_GetObjectItem(request_json, "items")->valuestring;
cJSON_Delete(request_json);
ESP_LOGI(MQTT_TAG,"[APP] Publish data : %s", item);
free(data);
}``
Hiya Tuan,
Awesome work!
I was playing with your demo code, all just fine. Then I noticed that calling a publish shortly after a subscribe seems to prevent a publish from within the subscribe callback from being run.
In your demo, the subscribe command triggers the subscribe callback which then runs code that publishes "abcde" to the test channel. When I add a publish line:
void connected_cb(void *self, void *params)
{
mqtt_client *client = (mqtt_client *)self;
mqtt_subscribe(client, "esp32_test", 0);
mqtt_publish(client, "esp32_test", "howdy!", 6, 0, 0);
}
the "abcde" as well as the debug messages from the subscribe callback never get run.
However, when I send messages to the subscribed channel, the data comes in and gets processed like it should. So it looks like it's subscribed properly, but the feedback (pub and log messages) just don't work.
I would start to dig into the timings of all this, but I think that you are much more familiar with the code at this point. :)
In connected_cb()
there is a subscribe immediately followed by a publish:
Lines 28 to 33 in da0e976
I was monitoring the behaviour with Wireshark and noticed that although the SUBACK is returned by my mosquitto server, the client is not processing it and therefore not calling subscribe_cb()
. I uncommented this line:
https://github.com/tuanpmt/espmqtt/blob/2967332b95454d4b53068a0d5484ae60e312eb12/mqtt.c#L425
Well, actually, the commented code was incorrect so I wrote this instead:
mqtt_info("msg_type %d, msg_id %d, pending_type %d, pending_id %d", msg_type, msg_id, client->mqtt_state.pending_msg_type, client->mqtt_state.pending_msg_id);
When only the subscribe happens (the publish is removed), there is a SUBACK (9) received, with ID 1, and the pending message is a SUBSCRIBE (8), so the MQTT_MSG_TYPE_SUBACK case is executed and the subscribe_cb()
is called.
[MQTT INFO] mqtt_start_receive_schedule
[MQTT INFO] Read len 5
[MQTT INFO] msg_type 9, msg_id 1, pending_type 8, pending_id 1
[MQTT INFO] Subscribe successful
I (4770) MQTT_SAMPLE: [APP] Subscribe ok, test publish msg
This successfully matches up the SUBACK (9) with the previous SUBSCRIBE (8) and fires the subscribe callback.
However if the publish happens immediately after the subscribe, it seems to overwrite the pending message, resulting in:
[MQTT INFO] mqtt_start_receive_schedule
[MQTT INFO] Read len 5
[MQTT INFO] msg_type 9, msg_id 1, pending_type 3, pending_id 0
[MQTT INFO] Read len 16
[MQTT INFO] msg_type 3, msg_id 0, pending_type 3, pending_id 0
[MQTT INFO] deliver_publish
The pending message's type is no longer SUBSCRIBE (8) but PUBLISH (3), so when the SUBACK (9) is received there is no pending SUBSCRIBE (8) to compare against and the subscribe_cb()
callback is not executed.
Oddly I don't see any debug from mqtt_start_receive_schedule()
indicating it received a SUBACK (8) in this case at all - where does it go? Wireshark confirms that it is delivered.
I need to check what the MQTT spec says about ignoring ACKs, however missing the subscribe_cb()
as a result is surely a bug. I think the solution could be to maintain a list of pending messages, and then look for a corresponding match when processing ACKs to ensure the callbacks are all fired.
Alternatively, the API could be changed to support an asynchronous model where the API consumer is responsible for handling incoming future acknowledgements, which also allows the API consumer to handle timeouts and retries. However it would be nice if this library took care of that because the current API is nice and simple.
No
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.