Disconnected with result code 1
Connected with result code 0
SUB v1/da9e1390-e819-11e9-8221-599f77add412/things/11c78520-f5cd-11e9-a38a-d57172a4b4d4/cmd/+
PUB v1/da9e1390-e819-11e9-8221-599f77add412/things/11c78520-f5cd-11e9-a38a-d57172a4b4d4/sys/model Python
PUB v1/da9e1390-e819-11e9-8221-599f77add412/things/11c78520-f5cd-11e9-a38a-d57172a4b4d4/sys/version 1.1.0
PUB v1/da9e1390-e819-11e9-8221-599f77add412/things/11c78520-f5cd-11e9-a38a-d57172a4b4d4/data/1 temp,c=13
PUB v1/da9e1390-e819-11e9-8221-599f77add412/things/11c78520-f5cd-11e9-a38a-d57172a4b4d4/data/2 lum,lux=130
PUB v1/da9e1390-e819-11e9-8221-599f77add412/things/11c78520-f5cd-11e9-a38a-d57172a4b4d4/data/3 bp,hpa=813
Disconnected with result code 1
Caught exception in on_connect: Connection failed, not authorized
Disconnected with result code 5
Caught exception in on_connect: Connection failed, not authorized
Disconnected with result code 5
Caught exception in on_connect: Connection failed, not authorized
Disconnected with result code 5
Caught exception in on_connect: Connection failed, not authorized
Disconnected with result code 5
Caught exception in on_connect: Connection failed, not authorized
Disconnected with result code 5
Caught exception in on_connect: Connection failed, not authorized
Disconnected with result code 5
Caught exception in on_connect: Connection failed, not authorized
Disconnected with result code 5
Caught exception in on_connect: Connection failed, not authorized
Disconnected with result code 5
Caught exception in on_connect: Connection failed, not authorized
Disconnected with result code 5
Caught exception in on_connect: Connection failed, not authorized
Disconnected with result code 5
Caught exception in on_connect: Connection failed, not authorized
Disconnected with result code 5
#!/usr/bin/env python
import cayenne.client
import time
import logging
import Adafruit_DHT
# Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
MQTT_USERNAME = "xxx"
MQTT_PASSWORD = "xxxx"
MQTT_CLIENT_ID = "xxx"
sensor = Adafruit_DHT.DHT11
pin = 23
# 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
client.begin(MQTT_USERNAME, MQTT_PASSWORD, 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:
client.loop()
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
if (time.time() > timestamp + 10):
client.virtualWrite(3, 10, "temp", "c" )
if temp11 is not None:
client.virtualWrite(1, temp11, "temp", "c" )
else:
print("temp error")
if humidity11 is not None:
client.virtualWrite(2, humidity11, "rel_hum", "p")
else:
print("humidity error")
timestamp = time.time()
i = i+1
#!/usr/bin/env python
import cayenne.client
import time
import logging
import math
import Adafruit_DHT
# Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
MQTT_USERNAME = "xxxx"
MQTT_PASSWORD = "xxxx"
MQTT_CLIENT_ID = "xxx"
sensor = Adafruit_DHT.DHT11
pin = 18
# 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
client.begin(MQTT_USERNAME, MQTT_PASSWORD, 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:
client.loop()
humidity11, temp11 = Adafruit_DHT.read_retry(sensor, pin)
# client.virtualWrite(1, temp11, "temp", "c" )
if (time.time() > timestamp + 10):
client.virtualWrite(1, 10, "temp", "c" )
if temp11 is not None:
client.virtualWrite(1, temp11, "temp", "c" )
else:
print("temp error")
if humidity11 is not None:
client.virtualWrite(2, humidity11, "rel_hum", "p")
else:
print("humidity error")
if temp11 is not None and humidity11 is not None:
VPDME=((6.1078*math.exp(17.08085*temp11/(234.175+temp11)))-(6.1078*math.exp(17.08085*temp11/(234.175+temp11))*(humidity11/100)))/10.
print(VPDME)
client.virtualWrite(2, humidity11, "pressure", "kpa")
else:
print("VPDME error")
timestamp = time.time()
i = i+1
I see both the temp and timer is writing the channel 1:
if (time.time() > timestamp + 10):
client.virtualWrite(1, 10, "temp", "c" )
if temp11 is not None:
client.virtualWrite(1, temp11, "temp", "c" )
Also, the next to statements are also writing to the same channel:
if humidity11 is not None:
client.virtualWrite(2, humidity11, "rel_hum", "p")
else:
print("humidity error")
if temp11 is not None and humidity11 is not None:
VPDME=((6.1078*math.exp(17.08085*temp11/(234.175+temp11)))-(6.1078*math.exp(17.08085*temp11/(234.175+temp11))*(humidity11/100)))/10.
print(VPDME)
client.virtualWrite(2, humidity11, "pressure", "kpa")
Is it safe to say I can leave the first if as is and change the humidity and vpdme to:
if humidity11 is not None:
client.virtualWrite(2, humidity11, "rel_hum", "p")
else:
print("humidity error")
if temp11 is not None and humidity11 is not None:
VPDME=((6.1078*math.exp(17.08085*temp11/(234.175+temp11)))-(6.1078*math.exp(17.08085*temp11/(234.175+temp11))*(humidity11/100)))/10.
print(VPDME)
client.virtualWrite(3, VPDME, "pressure", "kpa")
Another difference is that I am running the two scripts from different location, one is in /home/pi/python/ and the other is /home/pi/Cayenne-MQTT-Python
pi@Bettie-Pi:~ $ python
Python 2.7.13 (default, Sep 26 2018, 18:42:22)
[GCC 6.3.0 20170516] on linux2
Type âhelpâ, âcopyrightâ, âcreditsâ or âlicenseâ for more information.