Smart Thermostat Raspberry PI - part receive outside thermostat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fcurtemp (): | |
""" | |
Downloads most recent outside temperature from cloud server. | |
First inserts new value in hcurtemp table. | |
Then deletes old values from hcurtemp table. | |
Runs as a sperate thread. | |
""" | |
while True: | |
try: | |
dbdc1 = dbc.cursor() | |
dbdc1.execute("SELECT min(vkey) FROM curtemp") | |
rows = dbdc1.fetchall() | |
maxtemp = (rows)[0][0] | |
if (maxtemp == None): | |
maxtemp = 9999999999 | |
dbdc1.close() | |
max1 = str(maxtemp) | |
with hpool.connection(timeout=3) as connectioncur: | |
tablefc = connectioncur.table('hcurtemp') | |
hscan2 = tablefc.scan(row_stop=max1,batch_size=1,limit=1) | |
dbdc2 = dbc.cursor() | |
for key, data in hscan2: | |
dbdc2.execute("INSERT INTO curtemp (vkey, vvalue) VALUES(%i,%i)" % (int(key),int(data['fd:curt']) ) ) | |
logging.info("new curtemp") | |
logging.info(str(data['fd:curt'])) | |
dbdc2.close() | |
dbdc3 = dbc.cursor() | |
dbdc3.execute("DELETE FROM curtemp WHERE vkey NOT IN (SELECT MIN(vkey) FROM curtemp)") #delete old values | |
dbdc3.close() | |
except Exception: | |
logging.exception("fcurtemp") | |
time.sleep(550) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment