-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbariwrite.py
More file actions
executable file
·35 lines (30 loc) · 879 Bytes
/
bariwrite.py
File metadata and controls
executable file
·35 lines (30 loc) · 879 Bytes
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
#!/usr/bin/python3
# coding=utf-8
"""reads barometric pressure sensor and writes it to a log
"""
from datetime import datetime
from time import time
from time import sleep
import ms5637
__author__ = 'Moe'
__copyright__ = 'Copyright 2017 Moe'
__license__ = 'MIT'
__version__ = '0.0.2'
# Bari sensor of MS5637
sensor = ms5637.Chip()
bari_file = 'bari_data.csv'
try:
while True:
bari_data = open(bari_file, 'a')
now = time()
humantime = datetime.fromtimestamp(now).strftime('%Y-%m-%dT%H:%M:%SZ')
pressure, _temperature = sensor.get_data()
outstring = str(humantime) + ', ' + str(pressure) + '\n'
print(str(now) + ' ' + str(pressure))
bari_data.writelines(outstring)
sleep(0.07)
except KeyboardInterrupt:
print('\nTerminated by user\nBari data written.\nGood Bye.\n')
finally:
bari_data.close()
# End