-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv_log_script.py
More file actions
47 lines (40 loc) · 1.6 KB
/
Copy pathenv_log_script.py
File metadata and controls
47 lines (40 loc) · 1.6 KB
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
45
46
47
import requests
from requests.auth import HTTPBasicAuth
import json
import time
import datetime
url = "https://sheep.frillip.net/panel/status.json"
username =
password =
output_file =
r = requests.get(url,
auth=HTTPBasicAuth(username,password))
unix_time_int = int(time.time())
utc_offset_sec = time.altzone if time.localtime().tm_isdst else time.timezone
utc_offset = datetime.timedelta(seconds=-utc_offset_sec)
iso8601_stamp = datetime.datetime.fromtimestamp(unix_time_int).replace(microsecond=0,tzinfo=datetime.timezone(offset=utc_offset)).isoformat()
human_date = datetime.datetime.fromtimestamp(unix_time_int).strftime("%d/%m/%Y")
human_time = datetime.datetime.fromtimestamp(unix_time_int).strftime("%H:%M:%S")
status_resp = r.json()
bme = status_resp["sensors"]["bme280"]
mppt = status_resp["mppt"]
bmv = status_resp["bmv"]
load = mppt["load"]
pv = mppt["pv"]
batt = bmv["batt"]
# This is useless because of rounding by the MPPT
# mppt_efficiency = round(( load["p"] / ( pv["p"] - batt["p"] ) ) * 100,2)
modem = status_resp["modem"]
data_usage = modem["data_usage"]
river = status_resp["river"]
f=open(output_file,"a")
print(unix_time_int,human_date,human_time,iso8601_stamp,
bme['t'],bme['p'],bme['h'],
load["v"],load["i"],load["p"],
pv["v"],pv["i"],pv["p"],pv["yield"],
batt["v"],batt["i"],batt["p"],batt["soc"],mppt["batt"]["cs"],batt["charge_consumed"],
modem["connected_time"],data_usage["data_up"],data_usage["data_down"],
modem["connected_total_time"],data_usage["data_total_up"],data_usage["data_total_down"],
river["level"],
sep=",", file=f)
f.close()