-
Notifications
You must be signed in to change notification settings - Fork 0
/
hpump.py
executable file
·196 lines (173 loc) · 5.41 KB
/
hpump.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/python3
# parse data from a hayward smart temp device
import binascii
# debug
def isprint(
x
):
return (0x20<=x and x<0x7F)
# debug
def decimal(
byteArray
):
return
i = 0
s = 'decimal:'
for x in byteArray:
if (9==i or 10==i):
ox = x
x *= 0.5
x -= 30.0
s += ' %4d(=%.2f) ' % (ox, x)
elif 11==i:
ox = x
x *= 4.0
x -= 316.0
s += ' %4d(=%.2f) ' % (ox, x)
elif 31==i:
ox = x
#x /= -15.0
#x += 40.0
x *= -0.075
x += 41.0
s += ' %4d(=%.2f) ' % (ox, x)
else:
s += '%4d' % x
i += 1
return s
# debug
def quoted(
byteArray
):
array = bytearray()
for x in byteArray:
if isprint(x):
array.append(x)
else:
array.append(0x2E)
array.append(0x20)
return array.decode('utf-8')
# parse a binary data chunk
def parse(
byteArray
):
hdr = bytearray([0x80, 0x07, 0x00, 0x2f, 0xa8, 0x00, 0x08, 0x46])
for i in range(0, len(hdr)):
a = hdr[i]
b = byteArray[i]
if (a!=b) and (0!=i) and (1!=i):
print('expected hdr is ', binascii.hexlify(hdr))
print(' actual hdr is ', binascii.hexlify(byteArray))
raise Exception('mmmh, wrong header')
hdrType = byteArray[0:2]
if (0x80==hdrType[0]) and (0x00==hdrType[1]):
# TODO
pass
elif (0x80==hdrType[0]) and (0x01==hdrType[1]):
# TODO
pass
elif (0x80==hdrType[0]) and (0x02==hdrType[1]):
# model type (I'm too lazy to properly decode value also, don't care about it)
print("model + type is: F888888 HeatPump");
return True
elif (0x80==hdrType[0]) and (0x03==hdrType[1]):
# box name
sz = byteArray[9]
name = byteArray[11:11+sz]
print('box name is "%s"' % name.decode('utf-8'))
return True
elif (0x80==hdrType[0]) and (0x04==hdrType[1]):
# box id + box code
sz0 = byteArray[8]
uuid = byteArray[9:9+sz0]
sz1 = byteArray[29]
code = byteArray[30:30+sz1]
print(
'box uuid="%s" code="%s"' % (
uuid.decode('utf-8'),
code.decode('utf-8'),
)
)
return True
elif (0x80==hdrType[0]) and (0x05==hdrType[1]):
# wifi SSID to connect to
sz = byteArray[9]
ssid = byteArray[11:11+sz]
print('WIFI SSID to connect to is "%s"' % ssid.decode('utf-8'))
return True
elif (0x80==hdrType[0]) and (0x06==hdrType[1]):
# password for SSID to connect to
sz = byteArray[9]
passwd = byteArray[11:11+sz]
print('WIFI PASSWD to connect with is "%s"' % passwd.decode('utf-8'))
return True
elif (0x80==hdrType[0]) and (0x07==hdrType[1]):
# password plus a whole bunch of shite - skip
return True
elif (0xd0==hdrType[0]) and (0x00==hdrType[1]):
# TODO
# this changes A LOT over time, but don't need it
return True
elif (0xd0==hdrType[0]) and (0x01==hdrType[1]):
# this one's got current time (incorrect btw) and temps in it
hour = byteArray[25]
minute = byteArray[26]
# temp is encoded as : temp = (0.5*byteValue - 30.0)
tIn = byteArray[9]
tIn *= 0.5
tIn -= 30.0
# temp is encoded as : temp = (0.5*byteValue - 30.0)
tOut = byteArray[10]
tOut *= 0.5
tOut -= 30.0
# seems to be 0 (ON) or 25 (OFF) ... or maybe the other way round
pumpState = byteArray[14]
# dump what we found
print('TIME, 24H MODE: %02dH:%02dM' % (hour, minute))
print('TEMP OUTPUT: %.2f' % tOut)
print('TEMP INPUT: %.2f' % tIn)
print('PUMP STATE: %d' % pumpState)
print("/bin/bash ./influxwrite.sh 'HPUMP_WIFI' 'tIn' '%.2f'" % tIn)
print("/bin/bash ./influxwrite.sh 'HPUMP_WIFI' 'tOut' '%.2f'" % tOut)
print("/bin/bash ./influxwrite.sh 'HPUMP_WIFI' 'state' '%.2f'" % pumpState)
return True
elif (0xd0==hdrType[0]) and (0x02==hdrType[1]):
# this one never seems to change -> boring
return True
else:
# unknown
raise Exception('unknown type in hdr')
return True
def doFile(
fileName
):
print('==================================================== %s' % fileName)
with open(fileName, "rb") as f:
prev = None
byteArray = f.read()
marker = bytearray([0xaa, 0x5a, 0xb1])
markerLen = len(marker)
while 0<len(byteArray):
off = byteArray.find(marker)
if off<0:
break
ok = False
bytesHead = byteArray[:off]
if prev is not None:
ok = parse(bytesHead)
prev = bytesHead
if False:
if False==ok:
hx = binascii.hexlify(bytesHead)
hx = str(hx)[2:-2]
xx = ''
for j in range(0, 4):
for i in range(0, 10):
xx += str(i)
xx += ' '
print(xx)
print(hx)
print(quoted(bytesHead))
print(decimal(bytesHead))
byteArray = byteArray[(off + markerLen):]
doFile('./raw.bin')