Sometimes MQTT return messages do not conform to the rules

stanley0216
Posts: 2
Joined: Wed Aug 07, 2024 5:10 am

Sometimes MQTT return messages do not conform to the rules

Postby stanley0216 » Wed Aug 07, 2024 5:37 am

Hello. My English skills are not good enough. Please understand.

- Model : esp32-c3-mini-1-h4x
- ESP-AT version : v3.3.0.0
- UART communication speed : 2Mbps (2,000,000)
- MQTT connection server : Microsoft Azure IoT Hub (MQTTS)
- Data transmitted to the device : 55328 byte ASCII string encoded in Base64
- AT command options for MQTT connection
→ QoS : 1
→ Certification : MQTT over TLS (no certificate verify)

MQTT was connected to MQTTS (port 8883) when connecting to Microsoft IoT Hub. After receiving the SAS token without using a certificate, it was used as the password.
There is no problem if I send small amount of data to the device (less than 1024 bytes at a time).
When I sent 55328 bytes of data encoded in Base64 for testing, sometimes it was received normally and sometimes it was received abnormally.

In general, the MQTT reception data rules looked like this:
+MQTTSUBRECV:0,"[[SubscribeAddress]].to=%2Fdevices%2F[[ClientID]]%2Fmessages%2FdeviceBound&%24.ct=text%2Fplain%3B%20charset%3DUTF-8&%24.ce=utf-8",12,Hello World!\r\n
→ The data ends with \r\n.
→ The length value (excluding \r\n) is surrounded by commas before the actual data.
→ Before the actual data and length value, it represents information from the receiving MQTT server.

However, the header content is abnormal, as shown in the attached image file.
(I captured the UART line connected to the MCU with a Saleae logic analyzer)
MQTT data reception capture image_20240807.png
MQTT data reception capture image_20240807.png (82.44 KiB) Viewed 3754 times
The received data length value is in the middle.
If I count from the data length value to the end (actual data value), it is 1024 bytes.

Why is this problem happening? How can I fix it?
Please help.

Have a nice day always. Thank you.

esp-at
Posts: 200
Joined: Mon May 09, 2022 3:00 am

Re: Sometimes MQTT return messages do not conform to the rules

Postby esp-at » Wed Aug 07, 2024 11:36 am

Hello~
I checked the MQTT code, and your issue seems quite unusual. The response header (+MQTTSUBRECV:<linkid>,<"topic">,<data_len>,) is constructed all at once by snprintf(), so it is unlikely to be affected by other data.

To investigate further, could you please enable AT log, compile the AT firmware, and check what happens?
  • python build.py mencuonfig -> Component config -> Log output -> Default log verbosity -> Info
  • python build.py mencuonfig -> Component config -> AT -> Enable ESP-AT Debug
  • python build.py mencuonfig -> Component config -> AT -> Enable ESP-AT Debug -> Enable Network Debug
https://docs.espressif.com/projects/esp ... le_it.html

If you have difficulties in compiling ESP-AT project, I would like to provide a test firmware for you to reproduce the issue.

stanley0216
Posts: 2
Joined: Wed Aug 07, 2024 5:10 am

Re: Sometimes MQTT return messages do not conform to the rules

Postby stanley0216 » Fri Aug 09, 2024 12:49 am

Hello!
I have rebuilt the ESP-AT source and downloaded it based on the information you provided.
When I used the AT+GMR command, I confirmed as follows:

------------------------------------------------------------------------------------
AT version:3.5.0.0-dev(0f91d98 - ESP32C3 - Jul 19 2024 02:57:45)
SDK version:v5.0.6-dirty
compile time(5d1f30af):Aug 9 2024 08:49:34
Bin version:v3.4.0.0-dev(MINI-1)

OK
------------------------------------------------------------------------------------

I wanted to test it on version 3.3.0.0, but I ended up with version 3.5.0.0-dev, so I tested it on that version first.
The test results are normal. I did not experience any symptoms similar to those in the attached photos.

I have verified that the TX of ESP32-C3 has a really detailed log output. Due to this log output behavior, I have verified that MQTT data reception is happening once every 750ms (1024 bytes each).

Could it be that the delay caused by the log output is causing the symptoms to disappear? I would like to test more precisely. What would be the best way to do it?

Who is online

Users browsing this forum: No registered users and 7 guests