modified: python_code/temp-humid-read-loop.py

new file:   python_code/temp-humid-read-single.py
	modified:   python_code/updateMysql.py
This commit is contained in:
Jonny Ervine
2015-06-18 10:20:47 +08:00
parent 3810ccb1b6
commit 05431d1b63
3 changed files with 125 additions and 36 deletions
+4 -6
View File
@@ -4,17 +4,15 @@
##
import sys
import MySQLdb
#import datetime
#import time
def main(temp, humid, host, db, user, passwd):
print('Temp = {0} *C, Hum = {1} %'.format(temp, humid))
print('Updating MySQL database next ...')
def main(temp, humid, host, db, user, passwd, logging):
logging.debug('Temp = {0} *C, Hum = {1} %'.format(temp, humid))
logging.debug('Updating MySQL database next ...')
connection = MySQLdb.connect(host,user,passwd,db)
cursor=connection.cursor()
sqltemp=format(temp, '5.1f')
sqlhumid=format(humid, '5.1f')
print(sqltemp, sqlhumid)
logging.info('Temperature: {0}*C Humidity: {1}% ... updating to MySQL database'.format(sqltemp, sqlhumid))
sql = """INSERT INTO TempHumid (ComputerTime, Temperature, Humidity, id) VALUES (unix_timestamp(now()), %s, %s, NULL)"""
args = (sqltemp, sqlhumid)
cursor.execute(sql, args)