Cayenne MQTT Timeout Spec

What is the maximum Cayenne MQTT will hold the line, keep the dashboard live without dropping off / timeout requiring restart / login ?
At a hunch it feels like 60 to 90 seconds and main issue is it seems to need a bit of traffic / some time at fast rates to restart flow of data to the dashboard ? Just need to find a happy slow MQTT channel data blob rate.

Having a lot of success with BYOD thanks. We use small python scripts GPIO serial port + Power to slow serial wireless devices (433MHz ASK and extreme configured bare bones LoRA harware) all on ancient and Lite Pi. The above detail timeout needed as we have a series of remote data and power limited projects on horizon…

~ Andrew

Once you connect and publish data, do you disconnect from the MQTT connection? If so the dashboard will turn OFFLINE, else the dashboard remains ONLINE until the connection is broken and interrupted.

The connection is good and works well as expected. I find that if no data is sent in or data is too slow then disconnection occurs. Is the maximum time until disconnection occurs set by Cayenne MQTT server side settings or could it be by a python script / library I am using ?
I am using GitHub - myDevicesIoT/Cayenne-MQTT-Python: Python Library for Cayenne MQTT API
~ Andrew

i have this code running for 10 min now and the dashboard remain online:

#!/usr/bin/env python
import cayenne.client
import time
import logging

# Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
MQTT_CLIENT_ID = "xxxxx"

# The callback for when a message is received from Cayenne.
def on_message(message):
    print("message received: " + str(message))
    # If there is an error processing the message return an error string, otherwise return nothing.

client = cayenne.client.CayenneMQTTClient()
client.on_message = on_message
             MQTT_CLIENT_ID, loglevel=logging.INFO)
# For a secure connection use port 8883 when calling client.begin:
# client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID, port=8883, loglevel=logging.INFO)

i = 0
timestamp = 0

while True:

I was noticing code that was loosing connection @picaxe1, then reconnecting automatically next time it tried to publish data. Turned out to be another machine that was subscribed using the same Client-ID. Publishing machine would reconnect and send data, subscribing machine would kick publisher off so it could read the data … and on it went.
My recollection (it was a year or two ago) is:

  • MQTT protocol simply says each Client-ID must be unique. No other implications.
  • Cayenne appears to need the username, password and Client-ID specified on the dashboard in order to publish.
  • Cayenne requires correct username and password to subscribe, but not the Client-ID specified.
  • I wondered, but never tested, whether the Cayenne libraries substitute a random Client-ID when a device is subscribing.

The solution, then is to use a random (& unique) Client-ID on the subscribing machine(s). That way they all stay connected.
This becomes an issue if you wish to have two machines both publishing to the same project. That might require a workaround in the Cayenne world.
I sometimes use Cayenne libraries, sometimes directly use Eclipse Paho libraries. I think Cayenne also use Paho libraries with some customization, so that might not matter.

this is not correct, for both publishing and subscribing you need the client id which helps in identifying the device in the account. The MQTT username and password are same across all devices in the user account, only the client id is different. You can read more about it here Cayenne Docs

Sorry, I thought I replied and didn’t. I found this which seems to suggest that the timeout is 60 seconds. Just keep in mind that if you have any blocking events in your code you could surpass that 60 seconds, so might be better to stick with 45 seconds.

@adam thats not cayenne related. On cayenne until and unless you disconnect manual it won’t show offline on the dashboard. You can try with just connecting and not sending any info

Yeah you’re right. I had that bookmarked and thought it was the link I was looking for but that is not Cayenne. I can’t find what I was looking for now though. I can say for sure that if you don’t communicate with the server in a given period you’ll get disconnected though, unless that has changed in the last year or so. DHT11/DHT22 with Raspberry Pi - #53 by jburhenn

You just need the client.loop() and you are good to go.

Okay situation clearer here now. There is NO timeout. What I was seeing was result of some untidy coding that had too many client loops in it. So far I have a steady connection overnight that is staying on line. Will reorganise things so the serial to MQTT does not do repeat client.loops. I am pretty sure that was the issue.
Thanks for helping sort this out
~ Andrew

Ok - I went into the far away dusty corners of my code to see what I did to get this working!
Of course the documentation you cite is correct. The ‘unique’ client-id is used to identify the project being addressed when one subscribes to a channel in that project. In this context we refer to ‘unique to this user’. In the broader MQTT world, the client-id is ‘unique to this connection to the broker’.

  1. My code in question does use native paho libraries. (line 6)
  2. It uses a genuinely unique client-id to connect to the broker (ie Cayenne). (line 121 ff)
  3. It then uses the Cayenne ‘Client-ID’ to subscribe to a data widget. (line 40)

Now that you have got me thinking about this - I suppose the same technique can be used to publish from multiple Pis to one project. Had not thought this through before, but it will help some current projects. Thank you!

Looking at the ‘standard’ Cayenne Python example, this uses the same ‘client’ object to connect to the broker, then suscribe to a channel. In that environment, there is no option to change the Client-ID

My code is here: