def main(stdscr): sensor = Adafruit_DHT.DHT22() stdscr.nodelay(1) tstart = time.time() while (stdscr.getch() == -1) : humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) #humidity = Adafruit_DHT.read(sensor, pin) #temperature = Adafruit_DHT.read(sensor, pin) while True: ser.write("\xFE\x44\x00\x08\x02\x9F\x25") time.sleep(0.01) resp = ser.read(7) high = ord(resp[3]) low = ord(resp[4]) co2 = (high*256) + low stdscr.addstr(0, 0, 'Timestamp = %0.3f sec' % (time.time() - tstart)) stdscr.addstr(1, 0, 'Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity)) stdscr.addstr(2, 0, 'Humidity = %0.2f %%' % humidity) stdscr.addstr(3, 0, 'Carbon Dioxide = %0.2f ppm' % co2) stdscr.addstr(4, 0, 'Press any key to exit...') stdscr.refresh() time.sleep(.5) stdscr.erase()
""" sensor=dht.DHT22(17) sensor.measure() a=sensor.temperature print("The Temperature "+ str(a)) b=sensor.humidity if(b>100): continue print("The humidity"+str(b)) print("\n") """ URl='https://api.thingspeak.com/update?api_key=' KEY='7LJU9O896AZ847RZ' #HEADER='&field1={}&field2={}&field3={}&field4={}&field5={}'.format(a,b,c,distance,water) HEADER='&field1={}&field2={}%field3={}'.format(c,distance,water) NEW_URL=URl+KEY+HEADER print(NEW_URL) data=urllib.request.urlopen(NEW_URL) time.sleep(2) # except RuntimeError: # continue try: sensor=dht.DHT22(7) TRIG = 18 ECHO = 24 thingspeak_post() except: GPIO.cleanup()