-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoutput_data.py
100 lines (84 loc) · 3.01 KB
/
output_data.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#
#
# This example outputs all values to the console window with a list of errors of your energy unit.
#
#
from senertec.client import senertec
from senertec.canipValue import canipValue
import json
from time import sleep
import os
result = []
def start():
# you can use the example file datapointFilter.json to fetch only datapoints you really want!
# edit the file as your needs, this is highly recommended.
file = open(os.getcwd() + "\\datapointFilter.json")
filter = json.load(file)
file.close()
# create a new senertec object with filter
senertecClient = senertec()
global result
totalDataPoints = 0
timeoutCounter = 0
# set your callback function where received data should go to
senertecClient.messagecallback = output
# login to dachsportal2 with email and password
if senertecClient.login("username", "password") is False:
return
# if login was successful you need to initialize the platform.
if senertecClient.init() is False:
return
# get all energy units/heating systems from your account.
units = senertecClient.getUnits()
if len(units) < 1:
print("No energy units were found")
return
# connect to first unit
if senertecClient.connectUnit(units[0].serial) is False:
return
print(
f"Connected to unit: {units[0].model} with serial: {units[0].serial}")
# get errors to output them below
errors = senertecClient.getErrors()
# request all datapoints.
# totalDataPoints = senertecClient.request(None)
# request datapoint from specific board
# totalDataPoints = senertecClient.request_with_board("AM027", "SCB-04@1")
# request datapoints from filter
totalDataPoints = senertecClient.request(filter)
# loop wait 2 seconds and checks if all points get received
while (len(result) < totalDataPoints):
# break after 60sec timeout
if timeoutCounter > 30:
break
sleep(2)
timeoutCounter += 1
# logout after all datapoints get received or timeout was reached
senertecClient.logout()
# print all values
for value in result:
print("Source: " + value.sourceDatapoint + "\nName: " + value.friendlyDataName + "\nValue: " +
value.dataValue.__str__() + value.dataUnit + "\n")
# print total count of received values
print(f"Received {len(result)} values.")
# print all errors
print("\n-----Device errors-----")
for e in errors:
if (e.code != ""):
print(
f"\nError: {e.code} in Board: {e.boardName} \nCategorie: {e.errorCategory} \nMessage: {e.errorTranslation}")
# this is the callback function to get the requested data from the websocket connection.
def output(value: canipValue):
global result
temp = next(
(
x
for x in result
if x.sourceDatapoint == value.sourceDatapoint
),
None,
)
# sometimes we get values twice, so we filter it
if not temp:
result.append(value)
start()