-
Notifications
You must be signed in to change notification settings - Fork 1
/
pressure.py
37 lines (26 loc) · 1.1 KB
/
pressure.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
import Adafruit_BMP.BMP085 as BMP085
import time
sensor = BMP085.BMP085()
##import MySQLdb
##db = MySQLdb.connect("localhost","root","smartcampus","pressure")
##curs = db.cursor()
try:
while True:
temp = sensor.read_temperature()
pressure = sensor.read_pressure()
altitude = sensor.read_altitude()
sealevelpressure = sensor.read_sealevel_pressure()
print('Temp = {0:0.2f} *C'.format(temp))
print('Pressure = {0:0.2f} Pa'.format(pressure))
print('Altitude = {0:0.2f} m'.format(altitude))
print('Sealevel Pressure = {0:0.2f} Pa'.format(sealevelpressure))
print('------------------------------------------')
## add_pressure = ("INSERT INTO pressurerecord VALUES(%s,%s,%s,%s,%s,%s)")
## curs.execute(add_pressure, (time.strftime("%Y/%m,%d"), time.strftime("%H:%M:%S"),temp, pressure, altitude, sealevelpressure))
## db.commit()
## time.sleep(10)
time.sleep(10)
except KeyboardInterrupt:
print "\nA keyboard interrupt has been noticed"
except:
print "An error or exception has occurred"