forked from raspberry-pi-weather-station/weather-station-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bmp.py
34 lines (29 loc) · 1015 Bytes
/
bmp.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
import Adafruit_BMP.BMP085 as BMP085
import json
import time
import os
sensor = BMP085.BMP085()
pressure = sensor.read_pressure()
alt=float(sensor.read_altitude())
slp=float(sensor.read_sealevel_pressure())
os.system('touch /home/pi/weather_station/weather-station-1/.lock')
json_file = open('/home/pi/weather_station/weather-station-1/sensors.json','r')
file_contents = json_file.read()
json_data = json.loads(file_contents)
json_data['pressure'] = pressure
json_data['altitude'] = alt
json_data['slp'] = slp
date_time = time.ctime();
json_data['date']['pretty'] = date_time
json_data['date']['day'] = date_time.split(' ')[2]
json_data['date']['weekday'] = date_time.split(' ')[0]
json_data['date']['month'] = date_time.split(' ')[1]
json_data['date']['time'] = date_time.split(' ')[3]
json_file.close()
data = json.dumps(json_data)
json_file = open('sensors.json', 'w')
json_file.write(data)
json_file.close()
os.system('rm /home/pi/weather_station/weather-station-1/.lock')
print "Bmp data written"
exit(0)