-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollectData.py
44 lines (35 loc) · 1.21 KB
/
collectData.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
#!/usr/bin/python
# -*- coding:utf-8 -*-
import logging
from data import Data
from utils import sendDataToThingerIO, writeToCSV, shutdown
from lipo import getLiPoPercentage
#logging.basicConfig(level=logging.DEBUG, format="%(asctime)s:%(levelname)s:%(message)s")
logging.basicConfig(level=logging.WARNING, format="%(asctime)s:%(levelname)s:%(message)s")
def is_intstring(s):
try:
int(s)
return True
except ValueError:
return False
def main():
try:
logging.info(">> Collecting data")
data = Data()
logging.info(">> Writing data to CSV")
writeToCSV(data)
logging.info(">> Sending data to Thinger.io")
sendDataToThingerIO(data)
logging.info(">> Checking battery state")
if data.BatteryLevel < 20:
logging.warning(f"Battery critical: {data.BatteryLevel}% - Shutdown initiated.")
shutdown()
else:
logging.info(f"Battery state: {data.BatteryLevel}%")
except IOError as e:
logging.error(e)
except KeyboardInterrupt:
logging.info("Script closed by user")
exit()
if __name__ == "__main__":
main()