-
Notifications
You must be signed in to change notification settings - Fork 13
/
converters.ino
240 lines (236 loc) · 8.3 KB
/
converters.ino
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
void displayAttribute(uint8_t SQN, uint16_t u16SrcAddr, uint16_t u16ClusterId, uint16_t u16AttribId, byte u8AttribType, byte* au8AttribData, byte u8AttribIndex, uint16_t u16AttrSize)
{
attr_response += "{Date Time: ";
attr_response += timeStringBuff;
attr_response += "{SQN: 0x" + String(SQN, DEC);
attr_response += ";ShortAddr: " + u16toStr(u16SrcAddr);
attr_response += ";Cluster ID: " + u16toStr(u16ClusterId);
attr_response += ";Attribute ID: " + u16toStr(u16AttribId);
attr_response += ";Attribute Size: " + u16toStr(u16AttrSize);
attr_response += ";Attribute Type: " + u8toStr(u8AttribType)+ ";";
/*
clusterList.Add(0x0000, " (General: Basic)");
clusterList.Add(0x0001, " (General: Power Config)");
clusterList.Add(0x0002, " (General: Temperature Config)");
clusterList.Add(0x0003, " (General: Identify)");
clusterList.Add(0x0004, " (General: Groups)");
clusterList.Add(0x0005, " (General: Scenes)");
clusterList.Add(0x0006, " (General: On/Off)");
clusterList.Add(0x0007, " (General: On/Off Config)");
clusterList.Add(0x0008, " (General: Level Control)");
clusterList.Add(0x0009, " (General: Alarms)");
clusterList.Add(0x000A, " (General: Time)");
clusterList.Add(0x000F, " (General: Binary Input Basic)");
clusterList.Add(0x0020, " (General: Poll Control)");
clusterList.Add(0x0019, " (General: OTA)");
clusterList.Add(0x0101, " (General: Door Lock");
clusterList.Add(0x0201, " (HVAC: Thermostat)");
clusterList.Add(0x0202, " (HVAC: Fan Control)");
lusterList.Add(0x0204, " (HVAC: Thermostat UI Config)");
clusterList.Add(0x0300, " (Lighting: Color Control)");
clusterList.Add(0x0400, " (Measurement: Illuminance)");
clusterList.Add(0x0402, " (Measurement: Temperature)");
clusterList.Add(0x0403, " (Measurement: Pressure)");
clusterList.Add(0x0405, " (Measurement: Relative Humidity)");
clusterList.Add(0x0406, " (Measurement: Occupancy Sensing)");
clusterList.Add(0x0500, " (Security & Safety: IAS Zone)");
clusterList.Add(0x0502, " (Security & Safety: IAS WD)");
clusterList.Add(0x0702, " (Smart Energy: Metering)");
lusterList.Add(0x0B05, " (Misc: Diagnostics)");
clusterList.Add(0x1000, " (ZLL: Commissioning)");
*/
switch (u16ClusterId)
{
case 0x0000:
switch (u8AttribType)
{
case 0x42:
if (u16AttribId == 0x0005) {
NewDevName = "";
attr_response += " Attribute Data (Len - " + String(u16AttrSize) + "): ";
for (int i = 0; i < u16AttrSize; i++)
{
char c = (char)au8AttribData[u8AttribIndex + i];
attr_response += c;
NewDevName += c;
}
DnResponse = true;
}
else {
// for (int i = 0 ; i < u16AttrSize; i++)
// {
// attr_response += Hex([u8AttribIndex + i]);
// }
}
break;
default:
break;
}
break;
case 0x0006:
switch (u8AttribType)
{
case 0x10:
//attr_response += " (Boolean)";
attr_response += " Attribute Data: 0x" + String(au8AttribData[u8AttribIndex], DEC);
break;
}
break;
case 0x0400:
break;
case 0x0402:
switch (u8AttribType)
{
case 0x21:
uint16_t u16Data;
u16Data = au8AttribData[u8AttribIndex];
u16Data <<= 8;
u16Data |= au8AttribData[u8AttribIndex + 1];
attr_response += " (UINT16)";
attr_response += " Attribute Data: 0x" + String(u16Data, HEX);
break;
case 0x29:
uint16_t int16Data;
int16Data = au8AttribData[u8AttribIndex];
int16Data <<= 8;
int16Data |= au8AttribData[u8AttribIndex + 1];
attr_response += "Temperature = ";
attr_response += String(int16Data, DEC);
break;
}
break;
case 0x0403:
switch (u8AttribType)
{
case 0x21:
uint16_t u16Data;
u16Data = au8AttribData[u8AttribIndex];
u16Data <<= 8;
u16Data |= au8AttribData[u8AttribIndex + 1];
attr_response += " (UINT16)";
attr_response += " Attribute Data: 0x" + String(u16Data, HEX);
break;
case 0x29:
uint16_t int16Data;
int16Data = au8AttribData[u8AttribIndex];
int16Data <<= 8;
int16Data |= au8AttribData[u8AttribIndex + 1];
attr_response += "Pressure = ";
attr_response += String(int16Data, DEC);
break;
}
break;
case 0x0405:
switch (u8AttribType)
{
case 0x21:
uint16_t u16Data;
u16Data = au8AttribData[u8AttribIndex];
u16Data <<= 8;
u16Data |= au8AttribData[u8AttribIndex + 1];
attr_response += "Humidity = ";
attr_response += String(u16Data, DEC);
break;
}
break;
default:
//attr_response += " (Unknown)";
//attr_response += "\n";
break;
}
/*
switch (u8AttribType)
{
case 0x10:
//attr_response += " (Boolean)";
//attr_response += "\n";
//attr_response += " Attribute Data: 0x" + String(au8AttribData[u8AttribIndex], DEC);
//attr_response += "\n";
break;
case 0x18:
//attr_response += " (8-bit Bitmap)";
//attr_response += "\n";
//attr_response += " Attribute Data: 0x" + String(au8AttribData[u8AttribIndex],HEX);
//attr_response += "\n";
break;
case 0x20:
//attr_response += " (UINT8)";
//attr_response += "\n";
//attr_response += " Attribute Data: 0x" + String(au8AttribData[u8AttribIndex], HEX);
//attr_response += "\n";
break;
case 0x21:
uint16_t u16Data;
u16Data = au8AttribData[u8AttribIndex];
u16Data <<= 8;
u16Data |= au8AttribData[u8AttribIndex + 1];
attr_response += " (UINT16)";
attr_response += "\n";
attr_response += " Attribute Data: 0x" + String(u16Data, HEX);
attr_response += "\n";
break;
case 0x23:
uint32_t u32Data;
u32Data = au8AttribData[u8AttribIndex];
u32Data <<= 8;
u32Data |= au8AttribData[u8AttribIndex + 1];
u32Data <<= 8;
u32Data |= au8AttribData[u8AttribIndex + 2];
u32Data <<= 8;
u32Data |= au8AttribData[u8AttribIndex + 3];
attr_response += " (UINT32)";
attr_response += "\n";
attr_response += " Attribute Data: 0x" + String(u32Data, HEX);
attr_response += "\n";
break;
case 0x29:
uint16_t int16Data;
int16Data = au8AttribData[u8AttribIndex];
int16Data <<= 8;
int16Data |= au8AttribData[u8AttribIndex + 1];
attr_response += " (INT16)";
attr_response += "\n";
attr_response += " Attribute Data: 0x" + String(int16Data, HEX);
attr_response += "\n";
break;
case 0x30:
attr_response += " (8-bit Enumeration)";
attr_response += "\n";
attr_response += " Attribute Data: 0x" + String(au8AttribData[u8AttribIndex], HEX);
attr_response += "\n";
break;
case 0x42:
attr_response += " (Character String)";
attr_response += "\n";
attr_response += " Attribute Data (Len - " + String(u16AttrSize) + "): ";
for (int i = 0; i < u16AttrSize; i++)
{
char c = (char)au8AttribData[u8AttribIndex + i];
attr_response += c;
}
attr_response += "\n";
break;
case 0xF0:
attr_response += " (IEEE Address)";
attr_response += "\n";
attr_response += " Attribute Data: " + au8AttribData[u8AttribIndex];
attr_response += ":" + au8AttribData[u8AttribIndex + 1];
attr_response += ":" + au8AttribData[u8AttribIndex + 2];
attr_response += ":" + au8AttribData[u8AttribIndex + 3];
attr_response += ":" + au8AttribData[u8AttribIndex + 4];
attr_response += ":" + au8AttribData[u8AttribIndex + 5];
attr_response += ":" + au8AttribData[u8AttribIndex + 6];
attr_response += ":" + au8AttribData[u8AttribIndex + 7];
attr_response += "\n";
break;
default:
attr_response += " (Unknown)";
attr_response += "\n";
break;
}
*/
attr_response += "}";
Serial.println(attr_response);
webSocket.broadcastTXT(attr_response); //wsc
attr_response = "";
}