-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbatterytest.py
33 lines (28 loc) · 884 Bytes
/
batterytest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import time
time.sleep(10)
import sys
import MySQLdb
db = MySQLdb.connect(
host='localhost',
user='root',
passwd='smartcampus',
db='batterytest')
curs=db.cursor()
#counter=0
try:
curs.execute('SELECT * FROM batterytest')
data = curs.fetchall()
if str(data[0]) == '(0L,)':
while True:
time.sleep(10)
updateCounter = ("UPDATE batterytest SET c = c + 1")
curs.execute(updateCounter)
db.commit()
print("Counter updated")
else:
print("Test complete")
except KeyboardInterrupt:
print "\nA keyboard interrupt has been noticed"
except:
print "An error or exception occurred"
#Remember to configure the Raspberry Pi to start this script at startup