-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuv_light.py
52 lines (43 loc) · 1.38 KB
/
uv_light.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import SI1145.SI1145 as SI1145
import time
import sys
sensor = SI1145.SI1145()
#This code will result in an error. Will have to fix.
##import MySQLdb
##db = MySQLdb.connect(
## host = '192.168.1.151',
## user = 'pi',
## passwd = '10416232',
## db = 'light',
## port = 3306)
##
##curs = db.cursor()
#----------------------------------------------------
try:
while True:
vis = sensor.readVisible()
IR = sensor.readIR()
UV = sensor.readUV()
uvIndex = UV / 100.0
vis2 = 'Vis: ' + str(vis)
IR2 = 'IR: ' + str(IR)
uvIndex2 = 'UV Index: ' + str(uvIndex)
print 'Vis: ' + str(vis)
print 'IR: ' + str(IR)
print 'UV Index: ' + str(uvIndex) #CHANGE IN DB TO float(4,2)
print '-----------------------'
## addLight = ("INSERT INTO light VALUES(%s,%s,%s,%s,%s)")
##
## data = open("data.txt", "a+")
##
## curs.execute(addLight, (time.strftime("%Y/%m/%d"), time.strftime("%H:%M:%S"), vis, IR, uvIndex))
## db.commit()
##
## data.write(vis2 + "\n" + IR2 + "\n" + uvIndex2 + "\n")
## data.write('-----------------------' + "\n")
## data.close()
time.sleep(10)
except KeyboardInterrupt:
print "\nA keyboard interrupt has been noticed"
except:
print "An error or exception has occurred"