Sometimes MQTT return messages do not conform to the rules
Posted: 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)
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.
- 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)
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.