Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Smart Thermostat Raspberry PI - part receive outside thermostat
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