Ok, so opening an old tread. I bought the DHT22 which I must say is 100 times better than the DHT11, in terms of thermal stability and actual humidity and tempreture readings.
Anyway, the issue of the scripts running 6 hours persists. I read an old post Here where the user had the same issue, scripts running about 6 - 7 hours. From what I can tell, some users say it might be a RAM issue as the pi might run out of RAM after a while. The script that I am running is setup into crontab which works nicely at hard cycle. If the scripts stops the only way of me getting it up and running again is to hard cycle the board. Trying to reset the board through API does not get the script going again.
What I cant understand is that with the scripts that stop etc, the normal Pi data seems to come through with no issues. As far as I can tell the overhead is light with this data as it is only real time data and nothing seems to be stored in a database.
Anyone have simular experiences ?
I am currently using the following
#!/usr/bin/env python
import cayenne.client as cayenne
import time
import Adafruit_DHT
#import logging
import math
time.sleep(60) #Sleep to allow wireless to connect before starting MQTT
# Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
MQTT_USERNAME = ""
MQTT_PASSWORD = ""
MQTT_CLIENT_ID = ""
sensor = Adafruit_DHT.DHT22
pin = 17
leaftemp = 1.5
client = cayenne.CayenneMQTTClient()
client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID) #, loglevel=logging.INFO)
timestamp = 0
while True:
client.loop()
if (time.time() > timestamp + 5):
humidity22, temp22 = Adafruit_DHT.read_retry(sensor, pin)
if temp22 is not None:
client.virtualWrite(1, temp22, cayenne.TYPE_TEMPERATURE, cayenne.UNIT_CELSIUS ) #change all channels
else:
print("temp error")
if humidity22 is not None:
client.virtualWrite(2, humidity22, cayenne.TYPE_RELATIVE_HUMIDITY, cayenne.UNIT_PERCENT)
else:
print("humidity error")
if temp22 is not None and humidity22 is not None:
vpd=((6.1078*math.exp(17.08085*temp22/(234.175+temp22)))-(6.1078*math.exp(17.08085*temp22/(234.175+temp22))*(humidity22/100)))/10
client.virtualWrite(3, vpd, "pressure", "kPa")
else:
print("vpd error")
if temp22 is not None and humidity22 is not None:
ltemp22 = temp22 - leaftemp
asvp= 6.1078*math.exp(temp22/(temp22+238.3)*17.2694)
lsvp= 6.1078*math.exp(ltemp22/(ltemp22+238.3)*17.2694)
lvpd= (lsvp -(asvp*humidity22/100))/10
client.virtualWrite(4, lvpd, "pressure", "kPa")
else:
print("lvpd error")
timestamp = time.time()
`