Skip to content

Client stops sending mqtt data after some hours #14

Open
@valerionew

Description

@valerionew

Hi,
I'm using this library on a mkr 1010 to send some data every 5 seconds. I based my sketch on the WiFi Simple Sender example. After 1-2 hours the library stops sending mqtt messages to my broker.
For now i did the following observations:

  1. the loop() code is still running
  2. i'm still able to ping my arduino
  3. my broker is still running, other devices on the network can still publish on it

The code is hosted on arduino create

Activity

Testato

Testato commented on Sep 19, 2019

@Testato

Same problem.
mkr1010 to a mosquitto on Rpi

linked a pull request that will close this issue on Sep 28, 2019
attilagyurman

attilagyurman commented on Oct 27, 2019

@attilagyurman

Same problem. Broker is mosquitto, it says after about 23 hour:

1572082448: Client Arduino-0000273f has exceeded timeout, disconnecting.
1572082448: Socket error on client Arduino-0000273f, disconnecting.

If i restart arduino, i can see the ping requests in mosquitto log, but if i restart mosquitto while arduino is connected, arduino doesn't reconnect.

valerionew

valerionew commented on Oct 27, 2019

@valerionew
Author
valerionew

valerionew commented on Nov 10, 2019

@valerionew
Author

@attilagyurman have you tried the code? Does it patch the problem?

attilagyurman

attilagyurman commented on Nov 11, 2019

@attilagyurman

@attilagyurman have you tried the code? Does it patch the problem?

@5N44P Yes, it's working perfectly.

sandeepmistry

sandeepmistry commented on Nov 11, 2019

@sandeepmistry
Contributor

@5N44P just to clarify this topic, was it related to the WiFi or the socket disconnecting?

valerionew

valerionew commented on Nov 11, 2019

@valerionew
Author

I set up this code to try and see if it is a wifi disconnection or just the connection with the MQTT broker.
The result is that it is both, but:

  • all the disconnections from the wifi happen at the same hour (17:22), but there is no rtc function active in the arduino as far as I know, so I'm prone to thinking that this is my access point's fault
  • the socket disconnections seem more erratic, and that might be the endpoint
sandeepmistry

sandeepmistry commented on Nov 14, 2019

@sandeepmistry
Contributor

Ok, so if it's a socket or WiFi level issue I think this can be closed or moved to the WiFiNINA repo if applicable.

You have a pull request #15 open to track adding reconnection to the examples, which is good.

tiszavolgyi

tiszavolgyi commented on Dec 9, 2019

@tiszavolgyi

I have the same problem on an MKR1000. Usually, it only works for like 20-30 minutes, sometimes a few hours. The wifi is connected, i'm still able to ping my arduino, the loop() code is still running, my MQTT broker is running as well.

However, my device does not send data to the MQTT topic...

Trying the reconnecting solution from @5N44P I will report back if it is working. Thank you!

gregor2004ua

gregor2004ua commented on Dec 19, 2020

@gregor2004ua

Having the same issue. Initially it was happening every hour, after making poll() calls less frequent it now happens every 8-10 hours. Does anyone have a permanent solution for this?

Webbeh

Webbeh commented on Jan 5, 2021

@Webbeh

...instead of using poll(), which seems to be VERY blocking on my end, I tend to send a random message on a random "keepalive" topic every 30s or so, seems to work by me.

I have quite critical applications where the arduino is really not easily reachable (avalanche level displays on ski slopes) and this is the only thing that seemed to work okay.

valerionew

valerionew commented on Jan 5, 2021

@valerionew
Author

I have had my reconnecting example going for more than a year and it's working fine too

pesor

pesor commented on Jun 21, 2021

@pesor

As far as I can see, the algoritm disconnect the MQTT connection after 60 minutes, this is hardcoded in the library file.

I have solved the issue, by adding this statement at the end of the loop():

if (!mqttClient.connected()) { mqttClient.connect(broker, port); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: imperfectionPerceived defect in any part of project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Client stops sending mqtt data after some hours · Issue #14 · arduino-libraries/ArduinoMqttClient