Project

General

Profile

« Previous | Next » 

Revision abe2d7e5

Added by David Sorber about 13 years ago

Adding some charset info to make sure mod_wsgi doesn't puke on UTF-8 encoded strings. Also added a "-d" (debug enable) switch to the RPi client so that it only prints out debug information if you want it to. Finally, I added a try except block around the database insert code in the server daemon so that the whole daemone doesn't crash when there is an error.

View differences:

525.743/code/server.py
from bfcslib.sensor_reading import SensorReading
DB_PATH = '/Users/dsorber/Desktop/beer_temps.db'
HOST = '10.0.0.4'
DB_PATH = '/home/dsorber/bfcs/beer_temps.db'
HOST = '192.168.1.1'
PORT = 2243
def main():
......
db_conn = sqlite3.connect(DB_PATH)
db = db_conn.cursor()
db.execute("INSERT INTO temp_data VALUES (%s, %s, %s, %s, %s, %s)" %
(calendar.timegm(obj.time.timetuple()), obj.temp1,
obj.temp2, obj.temp3, obj.temp4,
int(obj.relay_status and '1' or '0')))
db_conn.commit()
try:
db.execute("INSERT INTO temp_data VALUES (%s, %s, %s, %s, %s, %s)" %
(calendar.timegm(obj.time.timetuple()), obj.temp1,
obj.temp2, obj.temp3, obj.temp4,
int(obj.relay_status and '1' or '0')))
db_conn.commit()
except:
print 'FAILED'
db_conn.close()
continue
db_conn.close()
print 'SUCCESS'
conn.close()
if __name__ == '__main__':
sys.exit(main())
sys.exit(main())

Also available in: Unified diff