#!/usr/bin/python from Adafruit_BMP085 import BMP085 import MySQLdb as mdb import SDL_DS3231 import sys try: bmp = BMP085(0x77, 0) ds3231 = SDL_DS3231.SDL_DS3231(1, 0x68) temp = ((bmp.readTemperature()-7)*10) pressure = bmp.readPressure() cur_DateTime = ds3231.read_datetime() statement = "INSERT INTO `BP180`.`logdata` VALUES ('%s', '%d', '%d');" % (cur_DateTime, temp, pressure) con = mdb.connect('localhost', '', 'BP180'); with con: cur = con.cursor() cur.execute(statement) print "Inserted %d row %d %d" % (cur.rowcount, temp, pressure) if con: con.close() except mdb.Error, e: print "Error %d: %s" % (e.args[0], e.args[1]) sys.exit(1)