Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from time import *
- import sqlite3 as sql
- import smbus
- bus = smbus.SMBus(1)
- #humidity = (((firstbyte << 8) | secondbyte)*125 / 65536.0)-6
- #temp = (((firstbyte << 8) + secondbyte)*175.72/65536.0)-46.85
- address = 0x40
- db = sql.connect("feucht.db")
- cursor = db.cursor()
- cursor.execute("create table if not exists messung(temp double,humidity double, ts text)")
- db.commit()
- try:
- while True:
- bus.write_byte(address,0xF5)
- sleep(0.3)
- msbRF = bus.read_byte(address)
- sleep(0.3)
- lsbR = bus.read_byte(address)
- sleep(0.3)
- bus.write_byte(address,0xF3)
- sleep(0.3)
- msbTE = bus.read_byte(address)
- sleep(0.3)
- lsbTE = bus.read_byte(address)
- sleep(0.3)
- temp = (((msbTE << 8) + lsbTE) * 175.72 / 65536.0) - 46.85
- humidity = (((msbRF << 8) + lsbR) * 125 / 65536.0) -6
- cursor.execute("insert into messung values("+str(temp)+"," + str(humidity)+",date('now'))")
- sleep(30)
- #print("Temperatur: " + str(round(temp,2)) + "°C") #celsius
- #print("Luftfeuchtigkeit: " + str(round(humidity,2))+"%") # prozent
- except KeyboardInterrupt:
- print("Programm beendet")
- db.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement