-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlpgmon_client.py
41 lines (31 loc) · 947 Bytes
/
lpgmon_client.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
import requests
import datetime
import time
import logging
from colorama import init, Back, Fore, Style
#init state. Change these two per your liking.
freq = 2 #request frequency in seconds
period = 2 #total request period in hours
#init state end.
path = 'your path to csv file'
log_file = open(path,'w')
#calculate iterations
period_in_sec = period * 60 * 60
iterations = int(period_in_sec / freq)
print('|| ',datetime.datetime.now(), ' || Starting monitoring for: ', period, ' HRS. ', iterations, ' iterations')
#Starting...
init()
print(Back.GREEN)
print(Fore.BLACK)
for i in range(iterations):
time.sleep(freq)
r = requests.get('http://your Node MCU's IP/lpglvl')
if(r.status_code == 200):
s = r.text
s += ','
s += datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print(s)
s += '\n'
log_file.write(s)
print(Style.RESET_ALL)
print('|| ',datetime.datetime.now(), '|| ', iterations, ' iterations completed.')