I am trying to run 2 scripts sequentially. The first one gets the data and the second one enters the data into a table (which is already created).
#!/usr/bin/env python import RPi.GPIO as GPIO import MySQLdb as mdb import datetime import time #adjust for where your switch is connected buttonPin = 18 GPIO.setmode(GPIO.BCM) GPIO.setup(buttonPin,GPIO.IN) #import time #initialise a previous input variable to 0 (assume button not pressed last) prev_input = 0 while True: #take a reading input = GPIO.input(18) #if the last reading was low and this one high, print if ((not prev_input) and input): print ("Button Pressed") #update previous input prev_input = input #slight pause to debounce time.sleep(0.025)
conn = mdb.connect (host='localhost', user='root', passwd='xxxxxxxxx',db='paintuse') cursor = conn.cursor() sql = ("""INSERT INTO gunuse (`id`, `switchOnLog`) VALUES (666, GPIO.input(18))""") try: cursor.execute(sql) cursor.commit() except: conn.rollback() cursor.close()
The first script runs to the time.sleep line and doesn't go any further.