pubsubclient icon indicating copy to clipboard operation
pubsubclient copied to clipboard

Sometimes payload are mixed up with topic.

Open ElectApp opened this issue 2 years ago • 3 comments

I use esp8266 to read values from an electricity meter and publish the data on MQTT in json format with PubSubClient library. When working for a long period of time, sometimes the data is incorrect, as shown in the example.

Topic: application/24ff957f-c99e-4f15-ade2-f6ed792a1186/device/24e124468c481581/event/status

Example of the correct payload: {"app_id":"24ff957f-c99e-4f15-ade2-f6ed792a1186","model":"PM3PRL","device_id":"PM3PRL-24E124468C481581-131","devEui":"24e124468c481581","slave_id":131,"time":"2023-09-02 16:18:06","error":0,"log":[{"key":"V_RMS_A","val":233.1},{"key":"I_RMS_A","val":0.0},{"key":"P_A","val": 0},{"key":"Q_A","val": 0},{"key":"S_A","val": 0},{"key":"PF_A","val":0.000},{"key":"WH_A","val":294624},{"key":"Freq_A","val":50.0},{"key":"Op_St","val":21},{"key":"V_RMS_B","val":233.9},{"key":"I_RMS_B","val":0.0},{"key":"P_B","val": 0},{"key":"Q_B","val": 0},{"key":"S_B","val": 0},{"key":"PF_B","val":0.000},{"key":"WH_B","val":1397},{"key":"Freq_B","val":50.5},{"key":"V_RMS_C","val":234.1},{"key":"I_RMS_C","val":0.0},{"key":"P_C","val": 0},{"key":"Q_C","val": 0},{"key":"S_C","val": 0},{"key":"PF_C","val":0.000},{"key":"WH_C","val":21420},{"key":"Freq_C","val":50.0},{"key":"SoftV","val":231}]}

Example of a payload during a problem: {"app_id":"24ff957f-c99e-4f15-ade2-f6ed792a1186","model":"PM3PRL","device_id":"PM3PRL-24E124468C481581-131","devEui":"24e124468c481581","slave_id":131,"time":"2023-09-02 16:17:37","error":0,"log":[{"key":"V_RMS_A","val":232.8},{"key":0�Uapplication/24ff957f-c99e-4f15-ade2-f6ed792a1186/device/24e124468c481581/event/status{"app_id":"24ff957f-c99e-4f15-ade2-f6ed792a1186","model":"PM3PRL","device_id":"PM3PRL-24E124468C481581-133","devEui":"24e124468c481581","slave_id":133,"time":"2023-09-02 16:17:48","error":0,"log":[{"key":"V_RMS_A","val":234.6},{"key":"I_RMS_A","val":0.4},{"key":"P_A","val":98},{"key":"Q_A","val":15},{"key":"S_A","val":99},{"key":"PF_A","val":0.987},{"key":"WH_A","val":85564},{"key":"Freq_A","val":50.0},{"key":"Op_St","val":21},{"key":"V_RMS_B","val":234.5},{"key":"I_RMS_B","val":0.0},{"key":"P_B","val": 0},{"key":"Q_B","val": 0},{"key":"S_B","val

This problem occurs in MQTT broker or libraries?

ElectApp avatar Sep 02 '23 10:09 ElectApp

same here.

anyone a solution?

softwarecrash avatar Sep 22 '23 17:09 softwarecrash

I am also having something that maybe its the same of this problem. In my case the message gets deliver with diferrent length of bytes. It seems to happen if you use bytes and low amount of data, maybe something wrong with the MQTT_MAX_HEADER_SIZE...

wagfeliz avatar Aug 13 '24 17:08 wagfeliz

Something I notice, depending of the content in bytes of the message, the size of the delivery changes, example, if I send 23 bytes of 1, it will publish 40 bytes, if I publish 23 bytes of 200, it will publish 21 bytes. If I publish 1 byte of anything, its crashing and dont send anything, in my case the esp32... very weard.

wagfeliz avatar Aug 13 '24 17:08 wagfeliz