Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import datetime
  2. import sqlite3
  3. import time
  4. import Adafruit_DHT
  5.  
  6. db = sqlite3.connect(':memory:')
  7. cursor = db.cursor()
  8. cursor.execute('CREATE TABLE pomiary(id INTEGER PRIMARY KEY AUTOINCREMENT, wilgotnosc DOUBLE, temperatura DOUBLE);')
  9.  
  10. sensor = Adafruit_DHT.DHT11
  11. sensor_pin = 'P8_9'
  12.  
  13. while True:
  14.  
  15. hum = []
  16. temp = []
  17.  
  18. for i in range(0, 18):
  19. humP = 0
  20. tempP = 0
  21. humP, tempP = Adafruit_DHT.read_retry(sensor, sensor_pin)
  22. hum.append(humP)
  23. temp.append(tempP)
  24. time.sleep(1)
  25.  
  26. meanTemp = (sum(temp) - min(temp) - max(temp)) / 16
  27. meanHum = (sum(hum) - min(hum) - max(hum)) / 16
  28.  
  29. print('Temperatura: ' + repr(meanTemp))
  30. print('Wilgotnosc: ' + repr(meanHum))
  31.  
  32. cursor.execute('INSERT INTO pomiary(temperatura,wilgotnosc) values (' + str(meanTemp) + ', ' + str(meanHum) + '); ')
  33. cursor.execute('SELECT * FROM pomiary;')
  34. msg = cursor.fetchall()
  35. print('Pomiary:')
  36. print(msg)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement