Part 2 of Many DHT11 and some Math

yay it works !!!

quick question, what is the function of this line ?

        client.virtualWrite(1, 10, "temp", "c" )

or was is for trouble shooting ?

Also, I run VNC for ease of coding and ease of programming. However when I close the VNC desktop, my raspberry closes the connection.

I use crontab to set up my bootup script but that also dont seem to work, nothing happens during bootup / reboot.

sudo crontab -e

***** /etc/myDevices/crontab.sh
@reboot python3 /home/pi/python/Tomato/shramik.py &
#* 1 * * * python /home/pi/python/Tomato/shramik.py &

Script runs perfectly when I exceute it in the terminal/

Add the python file to your crontab with sudo crontab -e then type in @reboot python3 /home/pi/python/Tomato/shramik.py & and save.

Add the python file to your crontab with sudo crontab -e then type in @reboot python3 /home/pi/python/Tomato/shramik.py & and save.

I tried that, still not working, to make matter worse if I close the terminal in VNC, my script stops running on my pi.

image

If I run it manually, it connects instantly to the dashboard. However, with cron it doesnt. I have used cron the past sucessfully.

Hi, @shramik_salgaonkar

It took me a while to figure out and narrow down the issues with my code. As my competence is not there yet.

What I found was the program is executing before the wifi had time to connect to the server, therefore I added time.sleep(30) this is the min time the code requires to connect before starting MQTT.

Additionally, I removed the callback function which for some reason also prevents the script from starting at reboot.

I will bash the script some more to see what else will jump out but for now it works.

Thanks for all the help !!

i had removed the delay from the code i sent to you.

All good, just glad its working now. Next step is buying a better humidity sensor. The DHT11 is a dud.

1 Like

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 :confused: 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()

`

i did not understand what you mean by this?
Beside, there are various reason to crash after 6-7 hours and difficult to predict what is it.

Hey, What I meant was the data from Device: Raspberry Pi always comes through but device c0b1 stops after 6 hours.

Also my script is running from a virgen installation of Rasbian only thing on it is the script running.

as i said there can be various factors Python Script Stops Running After about 3 Hours - Raspberry Pi Stack Exchange
@adam any idea about this.

I was also looking at that thread. I was wondering if this is isolated, I mean a little super computer stopping after 6 hours due to memory hmm… I dont know,.

My suggestion is run the script in a terminal on the pi and after it stop reporting look to see if it crashed or if it’s still running

Ill give that a try thanks. Isnt there a way to log such errors ? Terminals such as VNC and putty seems to drop connection after a while.

ran script this morning with putty:

Caught exception in on_connect: Connection failed, not authorized
Caught exception in on_connect: Connection failed, not authorized
Caught exception in on_connect: Connection failed, not authorized
Caught exception in on_connect: Connection failed, not authorized
Caught exception in on_connect: Connection failed, not authorized
Caught exception in on_connect: Connection failed, not authorized
Caught exception in on_connect: Connection failed, not authorized
Caught exception in on_connect: Connection failed, not authorized
Caught exception in on_connect: Connection failed, not authorized
Caught exception in on_connect: Connection failed, not authorized
Caught exception in on_connect: Connection failed, not authorized
Caught exception in on_connect: Connection failed, not authorized
temp error
humidity error
vpd error
lvpd error

not sure about this error. will look into it.

It looks like you are DHT is giving error.