UtilitechAS / amsreader-firmware

ESP8266 and ESP32 compatible firmware to read, interpret and publish data to MQTT from smart electrical meters, both DLMS and DSMR is supported
Other
386 stars 73 forks source link

MQTT status switches to offline imediately after appearing online #842

Open shaohme opened 1 month ago

shaohme commented 1 month ago

Describe the bug The AMS reader appears offline immediately after appearing online when connecting to MQTT.

To Reproduce Steps to reproduce the behavior:

  1. Setup to publish to MQTT broker
  2. Observe the MQTT topic configured for new messages
  3. Reboot AMR reader
  4. Observe that the topic /status initially sets to 'online' after which it changes to 'offline'

Expected behavior It should be kept in 'online' state as long as the device is running.

Screenshots screenshot-1726137823 screenshot-1726138247

Hardware information:

Relevant firmware information:

ArnieO commented 1 month ago

Just to be sure what you experiencing: Does the device not transmit payloads? Or is it the problem that the transmitted status is set to "offline"?

shaohme commented 1 month ago

Just to be sure what you experiencing: Does the device not transmit payloads?

I assume by 'payloads' you mean MQTT messages to the broker. If so, it does.

Or is it the problem that the transmitted status is set to "offline"?

Yes. It starts by setting the value 'online' but shortly after sets it to 'offline' and stays there, as show in the screenshot.

ArnieO commented 1 month ago

It starts by setting the value 'online' but shortly after sets it to 'offline' and stays there, as show in the screenshot.

I've tried to reproduce this, using this setting: image

I get one "online" message, then nothing more - until I do a software reboot (yellow button on the bottom of config screen). I then get one "offline" message, and as soon as it boots one "online" message:

Following activation of the Reboot button: image

Then, 2 seconds later - when it has rebooted: image

shaohme commented 1 month ago

I have not setup a "Client ID" in my MQTT config before. When I set it, and reboot the reader, the problem disappeared :face_with_diagonal_mouth:

ArnieO commented 1 month ago

I think each client has to "present itself" to the broker with an ID (that must not be the same as any other client). I guess that explains it!

If your setup now works as expected, I invite you to close this thread.

shaohme commented 1 month ago

I think each client has to "present itself" to the broker with an ID (that must not be the same as any other client). I guess that explains it!

If your setup now works as expected, I invite you to close this thread.

I guess, but should AMS not inform the user of this? Either by recommending or demand a client id?

ArnieO commented 1 month ago

I guess, but should AMS not inform the user of this? Either by recommending or demand a client id?

That is actually a good idea! This field could be auto populated with Hostname as default value. I will update the Wiki now to remind that Client ID cannot be empty.

I mark this as an enhancement proposition for @gskjold to consider.

gskjold commented 1 day ago

Making this field required when MQTT is enabled