-
Notifications
You must be signed in to change notification settings - Fork 34
/
OTGW-Core.ino
2099 lines (1899 loc) · 99.4 KB
/
OTGW-Core.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
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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
***************************************************************************
** Program : OTGW-Core.ino
** Version : v0.10.4-alpha
**
** Copyright (c) 2021-2024 Robert van den Breemen
** Borrowed from OpenTherm library from:
** https://github.com/jpraus/arduino-opentherm
**
** TERMS OF USE: MIT License. See bottom of file.
***************************************************************************
*/
#define OTGWDebugTln(...) ({ if (bDebugOTmsg) DebugTln(__VA_ARGS__); })
#define OTGWDebugln(...) ({ if (bDebugOTmsg) Debugln(__VA_ARGS__); })
#define OTGWDebugTf(...) ({ if (bDebugOTmsg) DebugTf(__VA_ARGS__); })
#define OTGWDebugf(...) ({ if (bDebugOTmsg) Debugf(__VA_ARGS__); })
#define OTGWDebugT(...) ({ if (bDebugOTmsg) DebugT(__VA_ARGS__); })
#define OTGWDebug(...) ({ if (bDebugOTmsg) Debug(__VA_ARGS__); })
#define OTGWDebugFlush() ({ if (bDebugOTmsg) DebugFlush(); })
//define Nodoshop OTGW hardware
#define OTGW_BUTTON 0 //D3
#define OTGW_RESET 14 //D5
#define OTGW_LED1 2 //D4
#define OTGW_LED2 16 //D0
//external watchdog
#define EXT_WD_I2C_ADDRESS 0x26
#define PIN_I2C_SDA 4 //D2
#define PIN_I2C_SCL 5 //D1
//used by update firmware functions
const char *hexheaders[] = {
"Last-Modified",
"X-Version"
};
//Macro to Feed the Watchdog
#define FEEDWATCHDOGNOW Wire.beginTransmission(EXT_WD_I2C_ADDRESS); Wire.write(0xA5); Wire.endTransmission();
/* --- PRINTF_BYTE_TO_BINARY macro's --- */
#define PRINTF_BINARY_PATTERN_INT8 "%c%c%c%c%c%c%c%c"
#define PRINTF_BYTE_TO_BINARY_INT8(i) \
(((i) & 0x80ll) ? '1' : '0'), \
(((i) & 0x40ll) ? '1' : '0'), \
(((i) & 0x20ll) ? '1' : '0'), \
(((i) & 0x10ll) ? '1' : '0'), \
(((i) & 0x08ll) ? '1' : '0'), \
(((i) & 0x04ll) ? '1' : '0'), \
(((i) & 0x02ll) ? '1' : '0'), \
(((i) & 0x01ll) ? '1' : '0')
#define PRINTF_BINARY_PATTERN_INT16 PRINTF_BINARY_PATTERN_INT8 PRINTF_BINARY_PATTERN_INT8
#define PRINTF_BYTE_TO_BINARY_INT16(i) PRINTF_BYTE_TO_BINARY_INT8((i) >> 8), PRINTF_BYTE_TO_BINARY_INT8(i)
#define PRINTF_BINARY_PATTERN_INT32 PRINTF_BINARY_PATTERN_INT16 PRINTF_BINARY_PATTERN_INT16
#define PRINTF_BYTE_TO_BINARY_INT32(i) PRINTF_BYTE_TO_BINARY_INT16((i) >> 16), PRINTF_BYTE_TO_BINARY_INT16(i)
#define PRINTF_BINARY_PATTERN_INT64 PRINTF_BINARY_PATTERN_INT32 PRINTF_BINARY_PATTERN_INT32
#define PRINTF_BYTE_TO_BINARY_INT64(i) PRINTF_BYTE_TO_BINARY_INT32((i) >> 32), PRINTF_BYTE_TO_BINARY_INT32(i)
/* --- Endf of macro's --- */
/* --- LOG marcro's ---*/
#define OT_LOG_BUFFER_SIZE 512
char ot_log_buffer[OT_LOG_BUFFER_SIZE];
#define ClrLog() ({ ot_log_buffer[0] = '\0'; })
#define AddLogf(...) ({ snprintf(ot_log_buffer+strlen(ot_log_buffer), OT_LOG_BUFFER_SIZE-strlen(ot_log_buffer), __VA_ARGS__); })
#define AddLog(logstring) ({ strlcat(ot_log_buffer, logstring, OT_LOG_BUFFER_SIZE); })
#define AddLogln() ({ strlcat(ot_log_buffer, "\r\n", OT_LOG_BUFFER_SIZE); })
/* --- End of LOG marcro's ---*/
//some variable's
OpenthermData_t OTdata, delayedOTdata, tmpOTdata;
#define OTGW_BANNER "OpenTherm Gateway"
//===================[ Send useful information to MQWTT ]=====================
/*
Publish usefull firmware version information to MQTT broker.
*/
void sendMQTTversioninfo(){
sendMQTTData("otgw-firmware/version", _SEMVER_FULL);
sendMQTTData("otgw-firmware/reboot_count", String(rebootCount));
sendMQTTData("otgw-firmware/reboot_reason", lastReset);
sendMQTTData("otgw-pic/version", sPICfwversion);
sendMQTTData("otgw-pic/deviceid", sPICdeviceid);
sendMQTTData("otgw-pic/firmwaretype", sPICdeviceid);
sendMQTTData("otgw-pic/picavailable", CONOFF(bPICavailable));
}
/*
Publish state information of PIC firmware version information to MQTT broker.
*/
void sendMQTTstateinformation(){
sendMQTTData(F("otgw-pic/boiler_connected"), CCONOFF(bOTGWboilerstate));
sendMQTTData(F("otgw-pic/thermostat_connected"), CCONOFF(bOTGWthermostatstate));
sendMQTTData(F("otgw-pic/gateway_mode"), CCONOFF(bOTGWgatewaystate));
sendMQTTData(F("otgw-pic/otgw_connected"), CCONOFF(bOTGWonline));
sendMQTT(CSTR(MQTTPubNamespace), CONLINEOFFLINE(bOTGWonline));
}
//===================[ Reset OTGW ]===============================
void resetOTGW() {
OTGWSerial.resetPic();
}
/*
To detect the pic, reset the pic, then find ETX in the response after reset (within 1 second).
The ETX response is send by the bootload, when received it also means you have a pic connected.
*/
void detectPIC(){
OTGWSerial.registerFirmwareCallback(fwreportinfo); //register the callback to report version, type en device ID
OTGWSerial.resetPic(); // make sure it the firmware is detected
bPICavailable = OTGWSerial.find(ETX);
if (bPICavailable) {
DebugTln("ETX found after reset: Pic detected!");
} else {
DebugTln("No ETX found after reset: no Pic detected!");
}
}
//===================[ getpicfwversion ]===========================
/*
Get the information of the pic firmware: version number, device type and firmware type.
This is done by sending a PR=A command, requesting a banner from the PIC. This will trigger detection of version.
*/
String getpicfwversion(){
String _ret="";
String line = executeCommand("PR=A");
int p = line.indexOf(OTGW_BANNER);
if (p >= 0) {
p += sizeof(OTGW_BANNER);
_ret = line.substring(p);
} else {
_ret ="No version found";
}
OTGWDebugTf(PSTR("getpicfwversion: Current firmware version: %s\r\n"), CSTR(_ret));
_ret.trim();
return _ret;
}
//===================[ checkOTWGpicforupdate ]=====================
void checkOTWGpicforupdate(){
if (sPICfwversion.isEmpty()) {
sMessage = ""; //no firmware version found for some reason
} else {
OTGWDebugTf(PSTR("OTGW PIC firmware version = [%s]\r\n"), CSTR(sPICfwversion));
String latest = checkforupdatepic("gateway.hex");
if (!bOTGWonline) {
sMessage = sPICfwversion;
} else if (latest.isEmpty()) {
sMessage = ""; //two options: no internet connection OR no firmware version
} else if (latest != sPICfwversion) {
sMessage = "New PIC version " + latest + " available!";
}
}
//check if the esp8266 and the littlefs versions match
//if (!checklittlefshash()) sMessage = "Flash your littleFS with matching version!";
}
//===================[ sendOTGWbootcmd ]=====================
void sendOTGWbootcmd(){
if (!settingOTGWcommandenable) return;
OTGWDebugTf(PSTR("OTGW boot message = [%s]\r\n"), CSTR(settingOTGWcommands));
// parse and execute commands
char bootcmds[settingOTGWcommands.length() + 1];
settingOTGWcommands.toCharArray(bootcmds, settingOTGWcommands.length() + 1);
char* cmd;
int i = 0;
cmd = strtok(bootcmds, ";");
while (cmd != NULL) {
OTGWDebugTf(PSTR("Boot command[%d]: %s\r\n"), i++, cmd);
addOTWGcmdtoqueue(cmd, strlen(cmd), true);
cmd = strtok(NULL, ";");
}
}
//===================[ OTGW Command & Response ]===================
String executeCommand(const String sCmd){
//send command to OTGW
OTGWDebugTf(PSTR("OTGW Send Cmd [%s]\r\n"), CSTR(sCmd));
OTGWSerial.setTimeout(1000);
DECLARE_TIMER_MS(tmrWaitForIt, 1000);
while((OTGWSerial.availableForWrite() < (int)(sCmd.length()+2)) && !DUE(tmrWaitForIt)){
feedWatchDog();
}
OTGWSerial.write(CSTR(sCmd));
OTGWSerial.write("\r\n");
OTGWSerial.flush();
//wait for response
RESTART_TIMER(tmrWaitForIt);
while(!OTGWSerial.available() && !DUE(tmrWaitForIt)) {
feedWatchDog();
}
String _cmd = sCmd.substring(0,2);
OTGWDebugTf(PSTR("Send command: [%s]\r\n"), CSTR(_cmd));
//fetch a line
String line = OTGWSerial.readStringUntil('\n');
line.trim();
String _ret ="";
if (line.startsWith(_cmd)){
// Responses: When a serial command is accepted by the gateway, it responds with the two letters of the command code, a colon, and the interpreted data value.
// Command: "TT=19.125"
// Response: "TT: 19.13"
// [XX:response string]
_ret = line.substring(3);
} else if (line.startsWith("NG")){
_ret = "NG - No Good. The command code is unknown.";
} else if (line.startsWith("SE")){
_ret = "SE - Syntax Error. The command contained an unexpected character or was incomplete.";
} else if (line.startsWith("BV")){
_ret = "BV - Bad Value. The command contained a data value that is not allowed.";
} else if (line.startsWith("OR")){
_ret = "OR - Out of Range. A number was specified outside of the allowed range.";
} else if (line.startsWith("NS")){
_ret = "NS - No Space. The alternative Data-ID could not be added because the table is full.";
} else if (line.startsWith("NF")){
_ret = "NF - Not Found. The specified alternative Data-ID could not be removed because it does not exist in the table.";
} else if (line.startsWith("OE")){
_ret = "OE - Overrun Error. The processor was busy and failed to process all received characters.";
} else if (line.length()==0) {
//just an empty line... most likely it's a timeout situation
_ret = "TO - Timeout. No response.";
} else {
_ret = line; //some commands return a string, just return that.
}
OTGWDebugTf(PSTR("Command send [%s]-[%s] - Response line: [%s] - Returned value: [%s]\r\n"), CSTR(sCmd), CSTR(_cmd), CSTR(line), CSTR(_ret));
return _ret;
}
//===================[ Watchdog OTGW ]===============================
String initWatchDog() {
// Hardware WatchDog is based on:
// https://github.com/rvdbreemen/ESPEasySlaves/tree/master/TinyI2CWatchdog
// Code here is based on ESPEasy code, modified to work in the project.
// configure hardware pins according to eeprom settings.
OTGWDebugTln(F("Setup Watchdog"));
OTGWDebugTln(F("INIT : I2C"));
Wire.begin(PIN_I2C_SDA, PIN_I2C_SCL); //configure the I2C bus
//=============================================
// I2C Watchdog boot status check
String ReasonReset = "";
delay(100);
Wire.beginTransmission(EXT_WD_I2C_ADDRESS); // OTGW WD address
Wire.write(0x83); // command to set pointer
Wire.write(17); // pointer value to status byte
Wire.endTransmission();
Wire.requestFrom((uint8_t)EXT_WD_I2C_ADDRESS, (uint8_t)1);
if (Wire.available())
{
byte status = Wire.read();
if (status & 0x1)
{
OTGWDebugTln(F("INIT : Reset by WD!"));
ReasonReset = "Reset by External WD\r\n";
//lastReset = BOOT_CAUSE_EXT_WD;
}
}
return ReasonReset;
//===========================================
}
void WatchDogEnabled(byte stateWatchdog){
Wire.beginTransmission(EXT_WD_I2C_ADDRESS); //Nodoshop design uses the hardware WD on I2C, address 0x26
Wire.write(7); //Write to register 7, the action register
Wire.write(stateWatchdog); //1 = armed to reset, 0 = turned off
Wire.endTransmission(); //That's all there is...
}
//===[ Feed the WatchDog before it bites! (1x per second) ]===
void feedWatchDog() {
//make sure to do this at least once a second
//==== feed the WD over I2C ====
// Address: 0x26
// I2C Watchdog feed
DECLARE_TIMER_MS(timerWD, 1000, SKIP_MISSED_TICKS);
if DUE(timerWD)
{
Wire.beginTransmission(EXT_WD_I2C_ADDRESS); //Nodoshop design uses the hardware WD on I2C, address 0x26
Wire.write(0xA5); //Feed the dog, before it bites.
Wire.endTransmission(); //That's all there is...
blinkLEDnow(LED1);
}
//yield();
}
//===================[ END Watchdog OTGW ]===============================
//=======================================================================
float OpenthermData_t::f88() {
float value = (int8_t) valueHB;
return value + (float)valueLB / 256.0f;
}
void OpenthermData_t::f88(float value) {
if (value >= 0) {
valueHB = (byte) value;
float fraction = (value - valueHB);
valueLB = fraction * 256.0f;
}
else {
valueHB = (byte)(value - 1);
float fraction = (value - valueHB - 1);
valueLB = fraction * 256.0f;
}
}
uint16_t OpenthermData_t::u16() {
uint16_t value = valueHB;
return ((value << 8) + valueLB);
}
void OpenthermData_t::u16(uint16_t value) {
valueLB = value & 0xFF;
valueHB = (value >> 8) & 0xFF;
}
int16_t OpenthermData_t::s16() {
int16_t value = valueHB;
return ((value << 8) + valueLB);
}
void OpenthermData_t::s16(int16_t value) {
valueLB = value & 0xFF;
valueHB = (value >> 8) & 0xFF;
}
//parsing helpers
const char *statusToString(OpenThermResponseStatus status)
{
switch (status) {
case OT_NONE: return "NONE";
case OT_SUCCESS: return "SUCCESS";
case OT_INVALID: return "INVALID";
case OT_TIMEOUT: return "TIMEOUT";
default: return "UNKNOWN";
}
}
const char *messageTypeToString(OpenThermMessageType message_type)
{
switch (message_type) {
case OT_READ_DATA: return "READ_DATA";
case OT_WRITE_DATA: return "WRITE_DATA";
case OT_INVALID_DATA: return "INVALID_DATA";
case OT_RESERVED: return "RESERVED";
case OT_READ_ACK: return "READ_ACK";
case OT_WRITE_ACK: return "WRITE_ACK";
case OT_DATA_INVALID: return "DATA_INVALID";
case OT_UNKNOWN_DATA_ID: return "UNKNOWN_DATA_ID";
default: return "UNKNOWN";
}
}
const char *messageIDToString(OpenThermMessageID message_id){
if (message_id <= OT_MSGID_MAX) {
PROGMEM_readAnything (&OTmap[message_id], OTlookupitem);
return OTlookupitem.label;
} else return "Undefined";}
OpenThermMessageType getMessageType(unsigned long message)
{
OpenThermMessageType msg_type = static_cast<OpenThermMessageType>((message >> 28) & 7);
return msg_type;
}
OpenThermMessageID getDataID(unsigned long frame)
{
return (OpenThermMessageID)((frame >> 16) & 0xFF);
}
//parsing responses - helper functions
// bit: description [ clear/0, set/1]
// 0: CH enable [ CH is disabled, CH is enabled]
// 1: DHW enable [ DHW is disabled, DHW is enabled]
// 2: Cooling enable [ Cooling is disabled, Cooling is enabled]
// 3: OTC active [OTC not active, OTC is active]
// 4: CH2 enable [CH2 is disabled, CH2 is enabled]
// 5: reserved
// 6: reserved
// 7: reserved
bool isCentralHeatingEnabled() {
return OTcurrentSystemState.MasterStatus & 0x01;
}
bool isDomesticHotWaterEnabled() {
return OTcurrentSystemState.MasterStatus & 0x02;
}
bool isCoolingEnabled() {
return OTcurrentSystemState.MasterStatus & 0x04;
}
bool isOutsideTemperatureCompensationActive() {
return OTcurrentSystemState.MasterStatus & 0x08;
}
bool isCentralHeating2enabled() {
return OTcurrentSystemState.MasterStatus & 0x10;
}
//Slave
// bit: description [ clear/0, set/1]
// 0: fault indication [ no fault, fault ]
// 1: CH mode [CH not active, CH active]
// 2: DHW mode [ DHW not active, DHW active]
// 3: Flame status [ flame off, flame on ]
// 4: Cooling status [ cooling mode not active, cooling mode active ]
// 5: CH2 mode [CH2 not active, CH2 active]
// 6: diagnostic indication [no diagnostics, diagnostic event]
// 7: reserved
bool isFaultIndicator() {
return OTcurrentSystemState.SlaveStatus & 0x01;
}
bool isCentralHeatingActive() {
return OTcurrentSystemState.SlaveStatus & 0x02;
}
bool isDomesticHotWaterActive() {
return OTcurrentSystemState.SlaveStatus & 0x04;
}
bool isFlameStatus() {
return OTcurrentSystemState.SlaveStatus & 0x08;
}
bool isCoolingActive() {
return OTcurrentSystemState.SlaveStatus & 0x10;
}
bool isCentralHeating2Active() {
return OTcurrentSystemState.SlaveStatus & 0x20;
}
bool isDiagnosticIndicator() {
return OTcurrentSystemState.SlaveStatus & 0x40;
}
//bit: [clear/0, set/1]
//0: Service request [service not req’d, service required]
//1: Lockout-reset [ remote reset disabled, rr enabled]
//2: Low water press [ no WP fault, water pressure fault]
//3: Gas/flame fault [ no G/F fault, gas/flame fault ]
//4: Air press fault [ no AP fault, air pressure fault ]
//5: Water over-temp[ no OvT fault, over-temperat. Fault]
//6: reserved
//7: reserved
bool isServiceRequest() {
return OTcurrentSystemState.ASFflags & 0x0100;
}
bool isLockoutReset() {
return OTcurrentSystemState.ASFflags & 0x0200;
}
bool isLowWaterPressure() {
return OTcurrentSystemState.ASFflags & 0x0400;
}
bool isGasFlameFault() {
return OTcurrentSystemState.ASFflags & 0x0800;
}
bool isAirTemperature() {
return OTcurrentSystemState.ASFflags & 0x1000;
}
bool isWaterOverTemperature() {
return OTcurrentSystemState.ASFflags & 0x2000;
}
const char *byte_to_binary(int x)
{
static char b[9];
b[0] = '\0';
int z;
for (z = 128; z > 0; z >>= 1) {
strcat(b, ((x & z) == z) ? "1" : "0");
}
return b;
} //byte_to_binary
/*
This determines if the value in the OpenTherm message is valid and can be used in the data object, MQTT or REST API.
Rules are:
- if the message is overriden (R and A messages override B and T messages), then the value is not valid for use.
- if the OT message is a READ message, and the received OT msg is being read and acknowledged, then the value is valid.
- if the OT message is a WRITE message, and the received OT msg is being written (OT_WRITE_DATA), then the value is valid.
- if the OT message is a READ/WRITE message, and receive OT msg is being read and ackownledge, or, is being written, then the value is valid.
- if the OT message is a status message (from Heating, HAVC or Solar), then the message is always valid.
*/
bool is_value_valid(OpenthermData_t OT, OTlookup_t OTlookup) {
if (OT.skipthis) return false;
bool _valid = false;
_valid = _valid || (OTlookup.msgcmd==OT_READ && OT.type==OT_READ_ACK);
_valid = _valid || (OTlookup.msgcmd==OT_WRITE && OTdata.type==OT_WRITE_DATA);
_valid = _valid || (OTlookup.msgcmd==OT_RW && (OT.type==OT_READ_ACK || OTdata.type==OT_WRITE_DATA));
_valid = _valid || (OTdata.id==OT_Statusflags) || (OTdata.id==OT_StatusVH) || (OTdata.id==OT_SolarStorageMaster);;
return _valid;
}
void print_f88(float& value)
{
//function to print data
float _value = roundf(OTdata.f88()*100.0f) / 100.0f; // round float 2 digits, like this: x.xx
// AddLog("%s = %3.2f %s", OTlookupitem.label, _value , OTlookupitem.unit);
char _msg[15] {0};
dtostrf(_value, 3, 2, _msg);
AddLogf("%s = %s %s", OTlookupitem.label, _msg , OTlookupitem.unit);
//SendMQTT
if (is_value_valid(OTdata, OTlookupitem)){
sendMQTTData(messageIDToString(static_cast<OpenThermMessageID>(OTdata.id)), _msg);
value = _value;
}
}
void print_s16(int16_t& value)
{
int16_t _value = OTdata.s16();
// AddLogf("%s = %5d %s", OTlookupitem.label, _value, OTlookupitem.unit);
//Build string for MQTT
char _msg[15] {0};
itoa(_value, _msg, 10);
AddLogf("%s = %s %s", OTlookupitem.label, _msg, OTlookupitem.unit);
//SendMQTT
if (is_value_valid(OTdata, OTlookupitem)){
sendMQTTData(messageIDToString(static_cast<OpenThermMessageID>(OTdata.id)), _msg);
value = _value;
}
}
void print_s8s8(uint16_t& value)
{
AddLogf("%s = %3d / %3d %s", OTlookupitem.label, (int8_t)OTdata.valueHB, (int8_t)OTdata.valueLB, OTlookupitem.unit);
//Build string for MQTT
char _msg[15] {0};
char _topic[50] {0};
itoa((int8_t)OTdata.valueHB, _msg, 10);
strlcpy(_topic, messageIDToString(static_cast<OpenThermMessageID>(OTdata.id)), sizeof(_topic));
strlcat(_topic, "_value_hb", sizeof(_topic));
//AddLogf("%s = %s %s", OTlookupitem.label, _msg, OTlookupitem.unit);
if (is_value_valid(OTdata, OTlookupitem)){
sendMQTTData(_topic, _msg);
}
//Build string for MQTT
itoa((int8_t)OTdata.valueLB, _msg, 10);
strlcpy(_topic, messageIDToString(static_cast<OpenThermMessageID>(OTdata.id)), sizeof(_topic));
strlcat(_topic, "_value_lb", sizeof(_topic));
//AddLogf("%s = %s %s", OTlookupitem.label, _msg, OTlookupitem.unit);
if (is_value_valid(OTdata, OTlookupitem)){
sendMQTTData(_topic, _msg);
value = OTdata.u16();
}
}
void print_u16(uint16_t& value)
{
uint16_t _value = OTdata.u16();
//Build string for MQTT
char _msg[15] {0};
utoa(_value, _msg, 10);
AddLogf("%s = %s %s", OTlookupitem.label, _msg, OTlookupitem.unit);
//SendMQTT
if (is_value_valid(OTdata, OTlookupitem)){
sendMQTTData(messageIDToString(static_cast<OpenThermMessageID>(OTdata.id)), _msg);
value = _value;
}
}
void print_status(uint16_t& value)
{
char _flag8_master[9] {0};
char _flag8_slave[9] {0};
if (OTdata.masterslave == 0) {
// Parse master bits
//bit: [clear/0, set/1]
// 0: CH enable [ CH is disabled, CH is enabled]
// 1: DHW enable [ DHW is disabled, DHW is enabled]
// 2: Cooling enable [ Cooling is disabled, Cooling is enabled]]
// 3: OTC active [OTC not active, OTC is active]
// 4: CH2 enable [CH2 is disabled, CH2 is enabled]
// 5: Summer/winter mode [Summertime, Wintertime]
// 6: DHW blocking [ DHW not blocking, DHW blocking ]
// 7: reserved
_flag8_master[0] = (((OTdata.valueHB) & 0x01) ? 'C' : '-');
_flag8_master[1] = (((OTdata.valueHB) & 0x02) ? 'D' : '-');
_flag8_master[2] = (((OTdata.valueHB) & 0x04) ? 'C' : '-');
_flag8_master[3] = (((OTdata.valueHB) & 0x08) ? 'O' : '-');
_flag8_master[4] = (((OTdata.valueHB) & 0x10) ? '2' : '-');
_flag8_master[5] = (((OTdata.valueHB) & 0x20) ? 'S' : 'W');
_flag8_master[6] = (((OTdata.valueHB) & 0x40) ? 'B' : '-');
_flag8_master[7] = (((OTdata.valueHB) & 0x80) ? '.' : '-');
_flag8_master[8] = '\0';
AddLogf("%s = Master [%s]", OTlookupitem.label, _flag8_master);
//Master Status
if (is_value_valid(OTdata, OTlookupitem)){
sendMQTTData("status_master", _flag8_master);
sendMQTTData("ch_enable", (((OTdata.valueHB) & 0x01) ? "ON" : "OFF"));
sendMQTTData("dhw_enable", (((OTdata.valueHB) & 0x02) ? "ON" : "OFF"));
sendMQTTData("cooling_enable", (((OTdata.valueHB) & 0x04) ? "ON" : "OFF"));
sendMQTTData("otc_active", (((OTdata.valueHB) & 0x08) ? "ON" : "OFF"));
sendMQTTData("ch2_enable", (((OTdata.valueHB) & 0x10) ? "ON" : "OFF"));
sendMQTTData("summerwintertime", (((OTdata.valueHB) & 0x20) ? "ON" : "OFF"));
sendMQTTData("dhw_blocking", (((OTdata.valueHB) & 0x40) ? "ON" : "OFF"));
OTcurrentSystemState.MasterStatus = OTdata.valueHB;
}
} else {
// Parse slave bits
// 0: fault indication [ no fault, fault ]
// 1: CH mode [CH not active, CH active]
// 2: DHW mode [ DHW not active, DHW active]
// 3: Flame status [ flame off, flame on ]
// 4: Cooling status [ cooling mode not active, cooling mode active ]
// 5: CH2 mode [CH2 not active, CH2 active]
// 6: diagnostic indication [no diagnostics, diagnostic event]
// 7: Electricity production [no eletric production, eletric production]
_flag8_slave[0] = (((OTdata.valueLB) & 0x01) ? 'E' : '-');
_flag8_slave[1] = (((OTdata.valueLB) & 0x02) ? 'C' : '-');
_flag8_slave[2] = (((OTdata.valueLB) & 0x04) ? 'W' : '-');
_flag8_slave[3] = (((OTdata.valueLB) & 0x08) ? 'F' : '-');
_flag8_slave[4] = (((OTdata.valueLB) & 0x10) ? 'C' : '-');
_flag8_slave[5] = (((OTdata.valueLB) & 0x20) ? '2' : '-');
_flag8_slave[6] = (((OTdata.valueLB) & 0x40) ? 'D' : '-');
_flag8_slave[7] = (((OTdata.valueLB) & 0x80) ? 'P' : '-');
_flag8_slave[8] = '\0';
AddLogf("%s = Slave [%s]", OTlookupitem.label, _flag8_slave);
//Slave Status
if (is_value_valid(OTdata, OTlookupitem)){
sendMQTTData("status_slave", _flag8_slave);
sendMQTTData("fault", (((OTdata.valueLB) & 0x01) ? "ON" : "OFF")); //delayms(5);
sendMQTTData("centralheating", (((OTdata.valueLB) & 0x02) ? "ON" : "OFF")); //delayms(5);
sendMQTTData("domestichotwater", (((OTdata.valueLB) & 0x04) ? "ON" : "OFF")); //delayms(5);
sendMQTTData("flame", (((OTdata.valueLB) & 0x08) ? "ON" : "OFF")); //delayms(5);
sendMQTTData("cooling", (((OTdata.valueLB) & 0x10) ? "ON" : "OFF")); //delayms(5);
sendMQTTData("centralheating2", (((OTdata.valueLB) & 0x20) ? "ON" : "OFF")); //delayms(5);
sendMQTTData("diagnostic_indicator", (((OTdata.valueLB) & 0x40) ? "ON" : "OFF")); //delayms(5);
sendMQTTData("eletric_production", (((OTdata.valueLB) & 0x80) ? "ON" : "OFF")); //delayms(5);
OTcurrentSystemState.SlaveStatus = OTdata.valueLB;
}
}
if (is_value_valid(OTdata, OTlookupitem)){
// AddLogf("Status u16 [%04x] _value [%04x] hb [%02x] lb [%02x]", OTdata.u16(), _value, OTdata.valueHB, OTdata.valueLB);
value = (OTcurrentSystemState.MasterStatus<<8) | OTcurrentSystemState.SlaveStatus;
}
}
void print_solar_storage_status(uint16_t& value)
{
char _msg[15] {0};
if (OTdata.masterslave == 0) {
// Master Solar Storage
// ID101:HB012: Master Solar Storage: Solar mode
uint8_t MasterSolarMode = (OTdata.valueHB) & 0x7;
AddLogf("%s = Solar Storage Master Mode [%d] ", OTlookupitem.label, MasterSolarMode);
if (is_value_valid(OTdata, OTlookupitem)){
sendMQTTData(F("solar_storage_master_mode"), itoa(MasterSolarMode, _msg, 10)); //delayms(5);
OTcurrentSystemState.SolarMasterStatus = OTdata.valueHB;
}
} else {
//Slave
// ID101:LB0: Slave Solar Storage: Fault indication
uint8_t SlaveSolarFaultIndicator = (OTdata.valueLB) & 0x01;
// ID101:LB123: Slave Solar Storage: Solar mode status
uint8_t SlaveSolarModeStatus = (OTdata.valueLB>>1) & 0x07;
// ID101:LB45: Slave Solar Storage: Solar status
uint8_t SlaveSolarStatus = (OTdata.valueLB>>4)& 0x03;
AddLogf("\r\n%s = Slave Solar Fault Indicator [%d] ", OTlookupitem.label, SlaveSolarFaultIndicator);
AddLogf("\r\n%s = Slave Solar Mode Status [%d] ", OTlookupitem.label, SlaveSolarModeStatus);
AddLogf("\r\n%s = Slave Solar Status [%d] ", OTlookupitem.label, SlaveSolarStatus);
if (is_value_valid(OTdata, OTlookupitem)){
sendMQTTData(F("solar_storage_slave_fault_incidator"), ((SlaveSolarFaultIndicator) ? "ON" : "OFF"));
sendMQTTData(F("solar_storage_mode_status"), itoa(SlaveSolarModeStatus, _msg, 10));
sendMQTTData(F("solar_storage_slave_status"), itoa(SlaveSolarStatus, _msg, 10));
OTcurrentSystemState.SolarSlaveStatus = OTdata.valueLB;
}
}
if (is_value_valid(OTdata, OTlookupitem)){
//OTGWDebugTf(PSTR("Solar Storage Master / Slave Mode u16 [%04x] _value [%04x] hb [%02x] lb [%02x]"), OTdata.u16(), _value, OTdata.valueHB, OTdata.valueLB);
value = (OTcurrentSystemState.SolarMasterStatus<<8) | OTcurrentSystemState.SolarSlaveStatus;
}
}
void print_statusVH(uint16_t& value)
{
char _flag8_master[9] {0};
char _flag8_slave[9] {0};
if (OTdata.masterslave == 0){
// Parse master bits
//bit: [clear/0, set/1]
// ID70:HB0: Master status ventilation / heat-recovery: Ventilation enable
// ID70:HB1: Master status ventilation / heat-recovery: Bypass postion
// ID70:HB2: Master status ventilation / heat-recovery: Bypass mode
// ID70:HB3: Master status ventilation / heat-recovery: Free ventilation mode
// 4: reserved
// 5: reserved
// 6: reserved
// 7: reserved
_flag8_master[0] = (((OTdata.valueHB) & 0x01) ? 'V' : '-');
_flag8_master[1] = (((OTdata.valueHB) & 0x02) ? 'P' : '-');
_flag8_master[2] = (((OTdata.valueHB) & 0x04) ? 'M' : '-');
_flag8_master[3] = (((OTdata.valueHB) & 0x08) ? 'F' : '-');
_flag8_master[4] = (((OTdata.valueHB) & 0x10) ? '.' : '-');
_flag8_master[5] = (((OTdata.valueHB) & 0x20) ? '.' : '-');
_flag8_master[6] = (((OTdata.valueHB) & 0x40) ? '.' : '-');
_flag8_master[7] = (((OTdata.valueHB) & 0x80) ? '.' : '-');
_flag8_master[8] = '\0';
AddLogf("%s = VH Master [%s]", OTlookupitem.label, _flag8_master);
//Master Status
if (is_value_valid(OTdata, OTlookupitem)){
sendMQTTData(F("status_vh_master"), _flag8_master);
sendMQTTData(F("vh_ventilation_enabled"), (((OTdata.valueHB) & 0x01) ? "ON" : "OFF"));
sendMQTTData(F("vh_bypass_position"), (((OTdata.valueHB) & 0x02) ? "ON" : "OFF"));
sendMQTTData(F("vh_bypass_mode"), (((OTdata.valueHB) & 0x04) ? "ON" : "OFF"));
sendMQTTData(F("vh_free_ventlation_mode"), (((OTdata.valueHB) & 0x08) ? "ON" : "OFF"));
OTcurrentSystemState.MasterStatusVH = OTdata.valueHB;
}
} else {
// Parse slave bits
// ID70:LB0: Slave status ventilation / heat-recovery: Fault indication
// ID70:LB1: Slave status ventilation / heat-recovery: Ventilation mode
// ID70:LB2: Slave status ventilation / heat-recovery: Bypass status
// ID70:LB3: Slave status ventilation / heat-recovery: Bypass automatic status
// ID70:LB4: Slave status ventilation / heat-recovery: Free ventilation status
// ID70:LB6: Slave status ventilation / heat-recovery: Diagnostic indication
_flag8_slave[0] = (((OTdata.valueLB) & 0x01) ? 'F' : '-');
_flag8_slave[1] = (((OTdata.valueLB) & 0x02) ? 'V' : '-');
_flag8_slave[2] = (((OTdata.valueLB) & 0x04) ? 'P' : '-');
_flag8_slave[3] = (((OTdata.valueLB) & 0x08) ? 'A' : '-');
_flag8_slave[4] = (((OTdata.valueLB) & 0x10) ? 'F' : '-');
_flag8_slave[5] = (((OTdata.valueLB) & 0x20) ? '.' : '-');
_flag8_slave[6] = (((OTdata.valueLB) & 0x40) ? 'D' : '-');
_flag8_slave[7] = (((OTdata.valueLB) & 0x80) ? '.' : '-');
_flag8_slave[8] = '\0';
AddLogf("%s = VH Slave [%s]", OTlookupitem.label, _flag8_slave);
//Slave Status
if (is_value_valid(OTdata, OTlookupitem)){
sendMQTTData(F("status_vh_slave"), _flag8_slave);
sendMQTTData(F("vh_fault"), (((OTdata.valueLB) & 0x01) ? "ON" : "OFF"));
sendMQTTData(F("vh_ventlation_mode"), (((OTdata.valueLB) & 0x02) ? "ON" : "OFF"));
sendMQTTData(F("vh_bypass_status"), (((OTdata.valueLB) & 0x04) ? "ON" : "OFF"));
sendMQTTData(F("vh_bypass_automatic_status"), (((OTdata.valueLB) & 0x08) ? "ON" : "OFF"));
sendMQTTData(F("vh_free_ventliation_status"), (((OTdata.valueLB) & 0x10) ? "ON" : "OFF"));
sendMQTTData(F("vh_diagnostic_indicator"), (((OTdata.valueLB) & 0x40) ? "ON" : "OFF"));
OTcurrentSystemState.SlaveStatusVH = OTdata.valueLB;
}
}
if (is_value_valid(OTdata, OTlookupitem)){
//OTGWDebugTf(PSTR("Status u16 [%04x] _value [%04x] hb [%02x] lb [%02x]"), OTdata.u16(), _value, OTdata.valueHB, OTdata.valueLB);
value = (OTcurrentSystemState.MasterStatusVH<<8) | OTcurrentSystemState.SlaveStatusVH;
}
}
void print_ASFflags(uint16_t& value)
{
AddLogf("%s = ASF flags[%s] OEM faultcode [%3d]", OTlookupitem.label, byte_to_binary(OTdata.valueHB), OTdata.valueLB);
if (is_value_valid(OTdata, OTlookupitem)){
//Build string for MQTT
char _msg[15] {0};
//Application Specific Fault
sendMQTTData(F("ASF_flags"), byte_to_binary(OTdata.valueHB));
//OEM fault code
utoa(OTdata.valueLB, _msg, 10);
sendMQTTData(F("OEMFaultCode"), _msg);
//bit: [clear/0, set/1]
//0: Service request [service not req’d, service required]
//1: Lockout-reset [ remote reset disabled, rr enabled]
//2: Low water press [ no WP fault, water pressure fault]
//3: Gas/flame fault [ no G/F fault, gas/flame fault ]
//4: Air press fault [ no AP fault, air pressure fault ]
//5: Water over-temp[ no OvT fault, over-temperat. Fault]
//6: reserved
//7: reserved
sendMQTTData(F("service_request"), (((OTdata.valueHB) & 0x01) ? "ON" : "OFF"));
sendMQTTData(F("lockout_reset"), (((OTdata.valueHB) & 0x02) ? "ON" : "OFF"));
sendMQTTData(F("low_water_pressure"), (((OTdata.valueHB) & 0x04) ? "ON" : "OFF"));
sendMQTTData(F("gas_flame_fault"), (((OTdata.valueHB) & 0x08) ? "ON" : "OFF"));
sendMQTTData(F("air_pressure_fault"), (((OTdata.valueHB) & 0x10) ? "ON" : "OFF"));
sendMQTTData(F("water_over_temperature"),(((OTdata.valueHB) & 0x20) ? "ON" : "OFF"));
value = OTdata.u16();
}
}
void print_RBPflags(uint16_t& value)
{
AddLogf("%s = M[%s] OEM fault code [%3d]", OTlookupitem.label, byte_to_binary(OTdata.valueHB), OTdata.valueLB);
if (is_value_valid(OTdata, OTlookupitem)){
//Build string for MQTT
//Remote Boiler Paramaters
sendMQTTData(F("RBP_flags_transfer_enable"), byte_to_binary(OTdata.valueHB));
sendMQTTData(F("RBP_flags_read_write"), byte_to_binary(OTdata.valueLB));
//bit: [clear/0, set/1]
//0: DHW setpoint
//1: max CH setpoint
//2: reserved
//3: reserved
//4: reserved
//5: reserved
//6: reserved
//7: reserved
sendMQTTData(F("rbp_dhw_setpoint"), (((OTdata.valueHB) & 0x01) ? "ON" : "OFF"));
sendMQTTData(F("rbp_max_ch_setpoint"), (((OTdata.valueHB) & 0x02) ? "ON" : "OFF"));
//bit: [clear/0, set/1]
//0: read write DHW setpoint
//1: read write max CH setpoint
//2: reserved
//3: reserved
//4: reserved
//5: reserved
//6: reserved
//7: reserved
sendMQTTData(F("rbp_rw_dhw_setpoint"), (((OTdata.valueLB) & 0x01) ? "ON" : "OFF"));
sendMQTTData(F("rbp_rw_max_ch_setpoint"), (((OTdata.valueLB) & 0x02) ? "ON" : "OFF"));
value = OTdata.u16();
}
}
void print_slavememberid(uint16_t& value)
{
AddLogf("%s = Slave Config[%s] MemberID code [%3d]", OTlookupitem.label, byte_to_binary(OTdata.valueHB), OTdata.valueLB);
if (is_value_valid(OTdata, OTlookupitem)){
//Build string for SendMQTT
sendMQTTData(F("slave_configuration"), byte_to_binary(OTdata.valueHB));
char _msg[15] {0};
utoa(OTdata.valueLB, _msg, 10);
sendMQTTData(F("slave_memberid_code"), _msg);
// bit: description [ clear/0, set/1]
// 0: DHW present [ dhw not present, dhw is present ]
// 1: Control type [ modulating, on/off ]
// 2: Cooling config [ cooling not supported,
// cooling supported]
// 3: DHW config [instantaneous or not-specified,
// storage tank]
// 4: Master low-off&pump control function [allowed,
// not allowed]
// 5: CH2 present [CH2 not present, CH2 present]
// 6: Remote water filling function
// 7: Heat/cool mode control
sendMQTTData(F("dhw_present"), (((OTdata.valueHB) & 0x01) ? "ON" : "OFF"));
sendMQTTData(F("control_type_modulation"), (((OTdata.valueHB) & 0x02) ? "ON" : "OFF"));
sendMQTTData(F("cooling_config"), (((OTdata.valueHB) & 0x04) ? "ON" : "OFF"));
sendMQTTData(F("dhw_config"), (((OTdata.valueHB) & 0x08) ? "ON" : "OFF"));
sendMQTTData(F("master_low_off_pump_control_function"), (((OTdata.valueHB) & 0x10) ? "ON" : "OFF"));
sendMQTTData(F("ch2_present"), (((OTdata.valueHB) & 0x20) ? "ON" : "OFF"));
sendMQTTData(F("remote_water_filling_function"), (((OTdata.valueHB) & 0x40) ? "ON" : "OFF"));
sendMQTTData(F("heat_cool_mode_control"), (((OTdata.valueHB) & 0x80) ? "ON" : "OFF"));
value = OTdata.u16();
}
}
void print_mastermemberid(uint16_t& value)
{
AddLogf("%s = Master Config[%s] MemberID code [%3d]", OTlookupitem.label, byte_to_binary(OTdata.valueHB), OTdata.valueLB);
if (is_value_valid(OTdata, OTlookupitem)){
//Build string for MQTT
char _msg[15] {0};
sendMQTTData(F("master_configuration"), byte_to_binary(OTdata.valueHB));
sendMQTTData(F("master_configuration_smart_power"), (((OTdata.valueHB) & 0x01) ? "ON" : "OFF"));
utoa(OTdata.valueLB, _msg, 10);
sendMQTTData(F("master_memberid_code"), _msg);
value = OTdata.u16();
}
}
void print_vh_configmemberid(uint16_t& value)
{
AddLogf("%s = VH Config[%s] MemberID code [%3d]", OTlookupitem.label, byte_to_binary(OTdata.valueHB), OTdata.valueLB);
if (is_value_valid(OTdata, OTlookupitem)){
//Build string for MQTT
char _msg[15] {0};
sendMQTTData(F("vh_configuration"), byte_to_binary(OTdata.valueHB));
sendMQTTData(F("vh_configuration_system_type"), (((OTdata.valueHB) & 0x01) ? "ON" : "OFF"));
sendMQTTData(F("vh_configuration_bypass"), (((OTdata.valueHB) & 0x02) ? "ON" : "OFF"));
sendMQTTData(F("vh_configuration_speed_control"), (((OTdata.valueHB) & 0x04) ? "ON" : "OFF"));
utoa(OTdata.valueLB, _msg, 10);
sendMQTTData(F("vh_memberid_code"), _msg);
value = OTdata.u16();
}
}
void print_solarstorage_slavememberid(uint16_t& value)
{
AddLogf("%s = Solar Storage Slave Config[%s] MemberID code [%3d]", OTlookupitem.label, byte_to_binary(OTdata.valueHB), OTdata.valueLB);
if (is_value_valid(OTdata, OTlookupitem)){
//Build string for SendMQTT
sendMQTTData(F("solar_storage_slave_configuration"), byte_to_binary(OTdata.valueHB));
char _msg[15] {0};
utoa(OTdata.valueLB, _msg, 10);
sendMQTTData(F("solar_storage_slave_memberid_code"), _msg);
//ID103:HB0: Slave Configuration Solar Storage: System type1
sendMQTTData(F("solar_storage_system_type"), (((OTdata.valueHB) & 0x01) ? "ON" : "OFF"));
value = OTdata.u16();
}
}
void print_remoteoverridefunction(uint16_t& value)
{
// MsdID 100 Remote override room setpoint
// LB: Remote override function
// bit: description [ clear/0, set/1]
// 0: Manual change priority [disable overruling remote
// setpoint by manual setpoint change, enable overruling
// remote setpoint by manual setpoint change ]
// 1: Program change priority [disable overruling remote
// setpoint by program setpoint change, enable overruling
// remote setpoint by program setpoint change ]
// 2: reserved
// 3: reserved
// 4: reserved
// 5: reserved
// 6: reserved
// 7: reserved
// HB: reserved
AddLogf("%s = flag8 = [%s] - decimal = [%3d]", OTlookupitem.label, byte_to_binary(OTdata.valueLB), OTdata.valueLB);
if (is_value_valid(OTdata, OTlookupitem)){
//Build string for MQTT
char _topic[50] {0};
//flag8 value
strlcpy(_topic, messageIDToString(static_cast<OpenThermMessageID>(OTdata.id)), sizeof(_topic));
strlcat(_topic, "_flag8", sizeof(_topic));
sendMQTTData(_topic, byte_to_binary(OTdata.valueLB));
//report remote override flags to MQTT
sendMQTTData(F("remote_override_manual_change_priority"), (((OTdata.valueLB) & 0x01) ? "ON" : "OFF"));
sendMQTTData(F("remote_override_program_change_priority"), (((OTdata.valueLB) & 0x02) ? "ON" : "OFF"));
value = OTdata.u16();
}
}
void print_flag8u8(uint16_t& value)
{
AddLogf("%s = M[%s] - [%3d]", OTlookupitem.label, byte_to_binary(OTdata.valueHB), OTdata.valueLB);
if (is_value_valid(OTdata, OTlookupitem)){
//Build string for MQTT
char _topic[50] {0};
//flag8 value
strlcpy(_topic, messageIDToString(static_cast<OpenThermMessageID>(OTdata.id)), sizeof(_topic));
strlcat(_topic, "_flag8", sizeof(_topic));
sendMQTTData(_topic, byte_to_binary(OTdata.valueHB));
//u8 value
char _msg[15] {0};
utoa(OTdata.valueLB, _msg, 10);
strlcpy(_topic, messageIDToString(static_cast<OpenThermMessageID>(OTdata.id)), sizeof(_topic));
strlcat(_topic, "_code", sizeof(_topic));
sendMQTTData(_topic, _msg);
value = OTdata.u16();
}
}