mlesniew / PicoMQTT

ESP MQTT client and broker library
GNU Lesser General Public License v3.0
236 stars 25 forks source link

Unfortunately, only sporadic data from a Shelly Pro3EM to the Borker #13

Closed GeThi255 closed 11 months ago

GeThi255 commented 1 year ago

Hello,

Currently I use a Raspi with Mosquito as a broker to distribute the data from the Ahoy DTU and a Shelly Pro3EM. This also works very well.

Now I want to replace the Raspi with the broker with an ESP32 with PicoMqtt. The Ahoy DTU also connects to the ESP32, but the Shelly Pro3EM doesn't connect very well.

The Shelly Pro3EM publishes a data set about every 3 seconds. With the Raspi there is no problem. With the ESP32, most of them are lost.

In the diagnostics window of the Shelly there is a message with "MQTT0 queue overflow!".

shelly_notification:163 Status change of em:0: 
{"id":0,"a_act_power":4.1,"a_aprt_power":66.2,"a_current":0.291,"a_pf":0.52,"a_voltage":227.9,"b_act_power":177.4,"b_aprt_power":263.5,"b_current":1.153,"b_pf":0.76,"b_voltage":228.6,"c_act_power":93.0,"c_aprt_power":104.1,"c_current":0.455,"c_pf":0.91,"c_voltage":228.9,"n_current":null,"total_act_power":274.478,"total_aprt_power":433.737,"total_current":1.899} 
shos_mqtt_conn.c:857 MQTT0 queue overflow!
shos_mqtt_conn.c:857 MQTT0 queue overflow!

Any ideas?

BR Gerd

mlesniew commented 1 year ago

It's hard to say based on the information you shared, but it appears that Shelly buffers unsent MQTT messages in a queue. It wasn't able to send the messages, so the queue filled up. It attempts to add new messages to the queue, but fails -- that's the queue overflow.

Try the following:

GeThi255 commented 1 year ago

I did some tests but i can't figure out very much.

The WiFi connection ist good and device is connected. The PicoMQTT received some messages form the Shelly device with "overflow" in the Shelly log console. At the same time the connection to my Ahoy-DTU works fine.

I don't know which MQTT standard the Shelly device uses.

May be you are right with your lasst point but I can't change the QoS in the settings. I tried the "alexCajas EmbeddedMqttBroker" for ESP with the same result. Ahoy-DTU works fine and Shelly had the same issue.

Everything works fine on my Raspi with mosquito.

Than you for your help.

mlesniew commented 1 year ago

If Ahoy-DTU connects correctly, but Shelly can't, then there must be something unusual that Shelly is trying to do or it is not configured correctly. Unfortunately, I don't have a Shelly device to do testing myself.

You can try doing the following:

mlesniew commented 1 year ago

@GeThi255 any luck?

GeThi255 commented 1 year ago

Hello,

sorry for my late answer. I was in vacation and afterwards I had a lot to do on my job.

I've tried a few things but not really much. So I had no progress.

I checked the first point on your list, without any changes. I did the second point without receiving any messages. Same setup with my raspi works. No success on the esp3.

That's all i did by now. I'll try some additional test in the next days.

Thank you very much

BR Gerd

GeThi255 commented 1 year ago

Hello,

I did some changes yesterday and may be I found a reason.

First I did a firmware update on my Shelly device (Version1.0.3). But this did not help

Afterwards I changed the Shelly standard client ID (shellypro3em-c8f09e87ef1c) to something shorter like x12345.

Now it seems to work. Could it be a issue with the length of the client ID?

BR Gerd

mlesniew commented 1 year ago

You've hit the nail on the head!

PicoMQTT follows the MQTT 3.1.1 standard, which specifies that client IDs should be between 1 and 23 characters long and can only contain letters and digits. Your client ID "shellypro3em-c8f09e87ef1c" is just a tad too long at 25 characters and includes a dash. (see http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc385349242).

At the same time the standard states that MQTT broker implementations have the flexibility to relax these restrictions. They may accept longer client IDs or different characters, which they often do.

In my PicoMQTT library, I tried to play by the standard's rules. If the client ID goes over 23 characters, it's rejected and the connection is closed.

Technically, this isn't a bug because it's in line with MQTT's standard. However, as your experience shows, strict adherence to the standard is impractical. I have now increased the maximum allowed client ID length to 64 chars.

Version 0.3.8 will have this change included and should be available for installation soon.

Thanks for your feedback and for diving deep into this!