-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBresserWeatherSensorLWCmd.h
483 lines (397 loc) · 11.2 KB
/
BresserWeatherSensorLWCmd.h
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
///////////////////////////////////////////////////////////////////////////////
// BresserWeatherSensorLWCmd.h
//
// LoRaWAN Command Interface
//
// Definition of control/configuration commands and status responses for
// LoRaWAN network layer and application layer
//
// created: 05/2024
//
//
// MIT License
//
// Copyright (c) 2024 Matthias Prinke
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
//
// History:
//
// 20240504 Extracted from BresserWeatherSensorLWCfg.h
// 20240507 Added CMD_GET_SENSORS_CFG/CMD_SET_SENSORS_CFG
// 20240508 Updated description of CMD_GET_SENSORS_CFG/CMD_SET_SENSORS_CFG
// 20240603 Added CMD_GET_SENSORS_STAT
// 20240606 Added CMD_GET_STATUS_INTERVAL/CMD_SET_STATUS_INTERVAL
// 20240608 Added CMD_GET_LW_STATUS
// 20240609 Refactored command encoding
// 20240614 Renamed CMD_RESET_RAINGAUGE to CMD_RESET_WS_POSTPROC
// 20240716 Added CMD_SCAN_SENSORS
// 20240722 Added CMD_SET_LW_STATUS_INTERVAL, renamed
// CMD_<GET|SET>_STATUS_INTERVAL to CMD_<GET|SET>_APP_STATUS_INTERVAL
// 20240920 Changed sendCfgUplink() to encodeCfgUplink()
// 20241227 Removed delay from encodeCfgUplink()
//
// ToDo:
// -
//
///////////////////////////////////////////////////////////////////////////////
#if !defined(_LWCMD_H)
#define _LWCMD_H
#include <Arduino.h>
#include <LoraEncoder.h>
// ===========================
// LoRaWAN command interface
// ===========================
// ---------------------------
// -- LoRaWAN network layer --
// ---------------------------
// CMD_GET_DATETIME
// -----------------
#define CMD_GET_DATETIME 0x20
// Downlink (command):
// byte0: 0x00
// Uplink (response):
// byte0: unixtime[31:24]
// byte1: unixtime[23:16]
// byte2: unixtime[15: 8]
// byte3: unixtime[ 7: 0]
// byte4: rtc_source[ 7: 0]
// CMD_SET_DATETIME
// -----------------
// Port: CMD_SET_DATETIME
#define CMD_SET_DATETIME 0x21
// Downlink (command):
// byte0: unixtime[31:24]
// byte1: unixtime[23:16]
// byte2: unixtime[15: 8]
// byte3: unixtime[ 7: 0]
// Uplink: n.a.
// CMD_SET_SLEEP_INTERVAL
// -----------------------
// Note: Set normal sleep interval in seconds
// Port: CMD_SET_SLEEP_INTERVAL
#define CMD_SET_SLEEP_INTERVAL 0x31
// Downlink (command):
// byte0: sleep_interval[15:8]
// byte1: sleep_interval[ 7:0]
// Response: n.a.
// CMD_SET_SLEEP_INTERVAL_LONG
// ----------------------------
// Note: Set long sleep interval in seconds (energy saving mode)
// Port: CMD_SET_SLEEP_INTERVAL_LONG
#define CMD_SET_SLEEP_INTERVAL_LONG 0x33
// Downlink (command):
// byte0: sleep_interval_long[15:8]
// byte1: sleep_interval_long[ 7:0]
// Uplink: n.a.
// CMD_SET_LW_STATUS_INTERVAL
// ---------------------------
// Note: Set LoRaWAN status interval in frame counts
// Port: CMD_SET_LW_STATUS_INTERVAL
#define CMD_SET_LW_STATUS_INTERVAL 0x35
// Downlink (command):
// byte0: lw_status_interval[7:0]
// Uplink: n.a.
// CMD_GET_LW_CONFIG
// ------------------
// Port: CMD_GET_LW_CONFIG
#define CMD_GET_LW_CONFIG 0x36
// Downlink (command):
// byte0: 0x00
// Uplink (response):
// byte0: sleep_interval[15: 8]
// byte1: sleep_interval[ 7:0]
// byte2: sleep_interval_long[15:8]
// byte3: sleep_interval_long[ 7:0]
// CMD_GET_LW_STATUS
// ------------------
// Port: CMD_GET_LW_STATUS
// Note: Get LoRaWAN device status
#define CMD_GET_LW_STATUS 0x38
// Downlink (command):
// byte0: 0x00
// Uplink (response):
// byte0: u_batt[15:8]
// byte1: u_batt[ 7:0]
// byte2: flags[ 7:0]
// -----------------------
// -- Application layer --
// -----------------------
// CMD_GET_APP_STATUS_INTERVAL
// ------------------------
// Note: Get status interval in frame counts
// Port: CMD_GET_APP_STATUS_INTERVAL
#define CMD_GET_APP_STATUS_INTERVAL 0x40
// Downlink (command):
// byte0: 0x00
// Uplink (response):
// byte0: status_interval[7:0]
// CMD_SET_APP_STATUS_INTERVAL
// ------------------------
// Note: Set status interval in frame counts
// Port: CMD_SET_APP_STATUS_INTERVAL
#define CMD_SET_APP_STATUS_INTERVAL 0x41
// Downlink (command):
// byte0: status_interval[7:0]
// Uplink: n.a.
// CMD_GET_SENSORS_STAT
// ---------------------
// Port: CMD_GET_SENSORS_STAT
#define CMD_GET_SENSORS_STAT 0x42
// CMD_GET_APP_PAYLOAD_CFG
// -----------------------
// Port: CMD_GET_APP_PAYLOAD_CFG
#define CMD_GET_APP_PAYLOAD_CFG 0x46
// Downlink (command):
// byte0: 0x00
// Response: n.a.
// Uplink (command):
// byte00: type00[7:0]
// byte01: type01[7:0]
// byte02: type02[7:0]
// byte03: type03[7:0]
// byte04: type04[7:0]
// byte05: type05[7:0]
// byte06: type06[7:0]
// byte07: type07[7:0]
// byte08: type08[7:0]
// byte09: type09[7:0]
// byte10: type10[7:0]
// byte11: type11[7:0]
// byte12: type12[7:0]
// byte13: type13[7:0]
// byte14: type14[7:0]
// byte15: type15[7:0]
// byte16: onewire[15:8]
// byte17: onewire[7:0]
// byte18: analog[15:8]
// byte19: analog[7:0]
// byte20: digital[31:24]
// byte21: digital[23:16]
// byte22: digital[15:8]
// byte23: digital[7:0]
// CMD_SET_APP_PAYLOAD_CFG
// Port: CMD_SET_APP_PAYLOAD_CFG
#define CMD_SET_APP_PAYLOAD_CFG 0x47
// Uplink (command):
// byte00: type00[7:0]
// byte01: type01[7:0]
// byte02: type02[7:0]
// byte03: type03[7:0]
// byte04: type04[7:0]
// byte05: type05[7:0]
// byte06: type06[7:0]
// byte07: type07[7:0]
// byte08: type08[7:0]
// byte09: type09[7:0]
// byte10: type10[7:0]
// byte11: type11[7:0]
// byte12: type12[7:0]
// byte13: type13[7:0]
// byte14: type14[7:0]
// byte15: type15[7:0]
// byte16: onewire[15:8]
// byte17: onewire[7:0]
// byte18: analog[15:8]
// byte19: analog[7:0]
// byte20: digital[31:24]
// byte21: digital[23:16]
// byte22: digital[15:8]
// byte23: digital[7:0]
// Response: n.a.
// CMD_GET_WS_TIMEOUT
// -------------------
// Note: Get weather sensor RX timeout in seconds
// Port: CMD_GET_WS_TIMEOUT
#define CMD_GET_WS_TIMEOUT 0xC0
// Downlink (command)
// byte0: 0x00
// Uplink (response):
// byte0: ws_timeout[ 7: 0]
// CMD_SET_WS_TIMEOUT
// -------------------
// Note: Set weather sensor RX timeout in seconds
// Port: CMD_SET_WS_TIMEOUT
#define CMD_SET_WS_TIMEOUT 0xC1
// Downlink (command):
// byte0: ws_timeout[ 7: 0]
// Uplink: n.a.
// CMD_RESET_WS_POSTPROC
// ----------------------
// Port: CMD_RESET_WS_POSTPROC
#define CMD_RESET_WS_POSTPROC 0xC3
// Downlink (command):
// byte0: flags[ 7: 0]
// Uplink: n.a.
// CMD_SCAN_SENSORS
// -----------------
// Note: Scan for 868 MHz sensors
// Port: CMD_SCAN_SENSORS
#define CMD_SCAN_SENSORS 0xC4
// Downlink (command):
// byte0: ws_scantime[ 7: 0]
// Uplink (response):
// byte0: id0[31:24]
// byte1: id0[23:16]
// byte2: id0[15: 8]
// byte3: id0[ 7: 0]
// byte4: decoder0[3:0] << 4 | type0[3:0]
// byte5: ch0[7:0]
// byte6: data_flags0[7:0]
// byte7: rssi0[7:0]
// ...
// CMD_GET_SENSORS_INC
// --------------------
// Note: Get sensors include list (0...12 IDs)
// Port: CMD_GET_SENSORS_INC
#define CMD_GET_SENSORS_INC 0xC6
// Downlink (command):
// byte0: 0x00
// Uplink (response):
// byte0: sensors_inc0[31:24]
// byte1: sensors_inc0[23:16]
// byte2: sensors_inc0[15: 8]
// byte3: sensors_inc0[ 7: 0]
// ...
// CMD_SET_SENSORS_INC
// --------------------
// Note: Set sensors include list (0...12 IDs)
// Port: CMD_SET_SENSORS_INC
#define CMD_SET_SENSORS_INC 0xC7
// Downlink (command):
// byte0: sensors_inc0[31:24]
// byte1: sensors_inc0[23:16]
// byte2: sensors_inc0[15: 8]
// byte3: sensors_inc0[ 7: 0]
// ...
// Uplink: n.a.
// CMD_GET_SENSORS_EXC
// --------------------
// Note: Get sensors exclude list (0...12 * 4 bytes)
// Port: CMD_GET_SENSORS_EXC
#define CMD_GET_SENSORS_EXC 0xC8
// Downlink (command):
// byte0: 0x00
// Uplink (response):
// byte0: sensors_exc0[31:24]
// byte1: sensors_exc0[23:16]
// byte2: sensors_exc0[15: 8]
// byte3: sensors_exc0[ 7: 0]
// ...
// CMD_SET_SENSORS_EXC
// --------------------
// Note: Set sensors exclude list (0...12 * 4 bytes)
// Port: CMD_SET_SENSORS_EXC
#define CMD_SET_SENSORS_EXC 0xC9
// Downlink (command):
// byte0: sensors_exc0[31:24]
// byte1: sensors_exc0[23:16]
// byte2: sensors_exc0[15: 8]
// byte3: sensors_exc0[ 7: 0]
// ...
// Uplink: n.a.
// CMD_GET_SENSORS_CFG
// --------------------
// Port: CMD_GET_SENSORS_CFG
#define CMD_GET_SENSORS_CFG 0xCA
// Downlink (command):
// byte0: 0x00
// Uplink (response):
// byte0: max_sensors
// byte1: rx_flags
// byte2: en_decoders
// CMD_SET_SENSORS_CFG
// --------------------
// Port: CMD_SET_SENSORS_CFG
#define CMD_SET_SENSORS_CFG 0xCB
// Downlink (command):
// byte0: max_sensors
// byte1: rx_flags
// byte2: en_decoders
// Uplink: n.a.
// CMD_GET_BLE_CONFIG
// -------------------
// Note: Scan time in seconds
// Port: CMD_GET_BLE_CONFIG
#define CMD_GET_BLE_CONFIG 0xD0
// Downlink (command):
// byte0: 0x00
// Uplink (response):
// byte0: 0x01 (active scan) / 0x00 (passive scan)
// byte1: scan_time[7:0]
// CMD_SET_BLE_CONFIG
// -------------------
// Note: Scan time in seconds
// Port: CMD_SET_BLE_CONFIG
#define CMD_SET_BLE_CONFIG 0xD1
// Uplink (command):
// byte0: active_scan - 0x01 (active scan) / 0x00 (passive scan)
// byte1: scan_time[7:0]
// Response: n.a.
// CMD_GET_BLE_ADDR
// -----------------
// Note: Get BLE sensors MAC addresses (0..8 * 6 bytes)
// Port: CMD_GET_BLE_ADDR
#define CMD_GET_BLE_ADDR 0xD2
// Downlink (command):
// byte0: 0x00
// Uplink (response):
// byte0: ble_addr0[47:24]
// byte1: ble_addr0[23:32]
// byte2: ble_addr0[31:24]
// byte3: ble_addr0[23:16]
// byte4: ble_addr0[15: 8]
// byte5: ble_addr0[ 7: 0]
// ...
// CMD_SET_BLE_ADDR
// -----------------
// Note: Set BLE sensors MAC addresses (0..8 * 6 bytes)
// Port: CMD_SET_BLE_ADDR
#define CMD_SET_BLE_ADDR 0xD3
// Downlink (command):
// byte0: ble_addr0[47:24]
// byte1: ble_addr0[23:32]
// byte2: ble_addr0[31:24]
// byte3: ble_addr0[23:16]
// byte4: ble_addr0[15: 8]
// byte5: ble_addr0[ 7: 0]
// ...
// Response: n.a.
// ===========================
/*!
* \brief Decode downlink
*
* \param port downlink message port
* \param payload downlink message payload
* \param size downlink message size in bytes
*
* \returns command ID, if downlink message requests a response, otherwise 0
*/
uint8_t decodeDownlink(uint8_t port, uint8_t *payload, size_t size);
/*!
* \brief Encode configuration uplink
*
* \param port uplink request port
* \param uplinkPayload uplink payload
* \param payloadSize uplink payload size in bytes
* \param uplinkInterval uplink interval in seconds
*/
void encodeCfgUplink(uint8_t port, uint8_t *uplinkPayload, uint8_t &payloadSize);
#endif