I typed in sudo pip3 install cayenne-mqtt in my terminal, then tried running this code to connect a custom device to cayenne, but I got the error message “Disconnected with result code 5.” I made sure I typed in the correct client information, does anyone know how i should fix this?
#!/usr/bin/env python
import cayenne.client
import time
#Initiates the connection to the Cayenne cloud server
client = cayenne.client.CayenneMQTTClient()
Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
MQTT_USERNAME = “”
MQTT_PASSWORD = “”
MQTT_CLIENT_ID = “”
This initiate the connection to the Cayenne Cloud
so that it can be displayed on the Dash
client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID )
#This loop runs forever but you can change it so that it only performs your code
once or only at certain times
x = 0
while True:
client.loop()
#client.virtualWrite(channel_number, value, "type_value", "unit_value")
# This is the standard way to transmit data to cayenne
#Channel_number is the widget on the dashboard it should appear as.
#Every virtualWrite should have a differerent channel
#Value is the value to pass in
# Type is the kind of data you're passing to cayenne
#Unit_value is the unit the value has
# Right now the code sends a slowly increasing number to the dashboard
# as a celsius value that increments every 5 seconds
client.virtualWrite(5, x, "temp", "C")
x +=1
time.sleep(5)