I'm in the process of teaching myself python. so please excuse my ignorance.
I'm trying to run this statement only if the digital inputstate(True).
def insert_to_db(id_sensor, value_sensor):
db = MySQLdb.connect("localhost","root","raspberry","sensor_log" )
cursor = db.cursor()
time_sensor = time.time()
# Prepare SQL query to INSERT a record into the database.
sql = "INSERT INTO table_sensor_log(timestamp, sensor_id, sensor_value) VALUES ('%d', '%d', '%d' )" % (time_sensor,id_sensor ,value_sensor)
try:
cursor.execute(sql)
db.commit()
except:
db.rollback()
db.close()