Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[paho-dev] paho.mqtt.python system clock adjust causing timeout

Hi list,

Thank you for a very useful product! I've been using paho.mqtt.python
on an embedded application on a Raspberry-PI and it's been working
mostly well for several months.

However, I do have a little problem. The raspberry PI doesn't have a
battery-backed real time clock, so whenever it is restarted, and
establishes internet connectivity, it uses NTP to set the clock. This
typically causes the clock to skip forward by a significant ammount.

I'm using paho.mqtt.python to connect to the "Mosquitto" MQTT-server,
and whenever the system clock is adjusted, my connection to the server
drops.

Looking at the source code at
https://github.com/eclipse/paho.mqtt.python/blob/master/src/paho/mqtt/client.py
, I see that time.time() is used to determine when to consider the
connection timed out.

This will of course not work if the system clock is adjusted.

I don't think there is any (reasonable) way to fix this in plain
python 2.x. What is needed is a time base which can be relied upon to
not skip ahead or reverse, so that it can be used to measure time for
timeouts. I think some sort of operating system dependent extension is
needed, something like https://pypi.python.org/pypi/monotonic .

I've noticed that the Mosquitto does use code similar to that used in
monotonic (see link above).

What is the paho policy for dependencies? Could paho.mqtt.python be
made (optionally?) dependent on monotonic? Or is there a better
solution?

/Anders


Back to the top