Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime
- import sqlite3
- import time
- import Adafruit_DHT
- db = sqlite3.connect(':memory:')
- cursor = db.cursor()
- cursor.execute('CREATE TABLE pomiary(id INTEGER PRIMARY KEY AUTOINCREMENT, wilgotnosc DOUBLE, temperatura DOUBLE);')
- sensor = Adafruit_DHT.DHT11
- sensor_pin = 'P8_9'
- while True:
- hum = []
- temp = []
- for i in range(0, 18):
- humP = 0
- tempP = 0
- humP, tempP = Adafruit_DHT.read_retry(sensor, sensor_pin)
- hum.append(humP)
- temp.append(tempP)
- time.sleep(1)
- meanTemp = (sum(temp) - min(temp) - max(temp)) / 16
- meanHum = (sum(hum) - min(hum) - max(hum)) / 16
- print('Temperatura: ' + repr(meanTemp))
- print('Wilgotnosc: ' + repr(meanHum))
- cursor.execute('INSERT INTO pomiary(temperatura,wilgotnosc) values (' + str(meanTemp) + ', ' + str(meanHum) + '); ')
- cursor.execute('SELECT * FROM pomiary;')
- msg = cursor.fetchall()
- print('Pomiary:')
- print(msg)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement