forked from 1technophile/OpenMQTTGateway
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ZgatewayIR.ino
797 lines (766 loc) · 26.9 KB
/
ZgatewayIR.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
/*
OpenMQTTGateway - ESP8266 or Arduino program for home automation
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker
Send and receiving command by MQTT
This gateway enables to:
- receive MQTT data from a topic and send IR signal corresponding to the received MQTT data
- publish MQTT data to a different topic related to received IR signal
Copyright: (c)Florian ROBERT
This file is part of OpenMQTTGateway.
OpenMQTTGateway is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenMQTTGateway is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef ZgatewayIR
#ifdef ESP8266
#include <IRremoteESP8266.h>
#include <IRsend.h> // Needed if you want to send IR commands.
#include <IRrecv.h> // Needed if you want to receive IR commands.
#ifdef DumpMode // in dump mode we increase the size of the buffer to catch big codes
IRrecv irrecv(IR_RECEIVER_PIN, 1024, 15U, true);
#else
IRrecv irrecv(IR_RECEIVER_PIN);
#endif
IRsend irsend(IR_EMITTER_PIN);
#else
#include <IRremote.h>
IRrecv irrecv(IR_RECEIVER_PIN);
IRsend irsend; //connect IR emitter pin to D9 on arduino, you need to comment #define IR_USE_TIMER2 and uncomment #define IR_USE_TIMER1 on library IRremote.h so as to free pin D3 for RF RECEIVER PIN
#endif
// IR protocol bits definition for Arduino (for ESP9266 they are defined in IRRemoteESP8266.h)
#ifndef NEC_BITS
#define NEC_BITS 32U
#endif
#ifndef SAMSUNG_BITS
#define SAMSUNG_BITS 32U
#endif
#ifndef SHARP_BITS
#define SHARP_ADDRESS_BITS 5U
#define SHARP_COMMAND_BITS 8U
#define SHARP_BITS (SHARP_ADDRESS_BITS + SHARP_COMMAND_BITS + 2) // 15U
#endif
#ifndef RC5_BITS
#define RC5_RAW_BITS 14U
#define RC5_BITS RC5_RAW_BITS - 2U
#endif
#ifndef DISH_BITS
#define DISH_BITS 16U
#endif
#ifndef SONY_12_BITS
#define SONY_12_BITS 12U
#endif
#ifndef LG_BITS
#define LG_BITS 28U
#endif
#ifndef WHYNTER_BITS
#define WHYNTER_BITS 32U
#endif
void setupIR()
{
//IR init parameters
#ifdef ESP8266
irsend.begin();
#endif
irrecv.enableIRIn(); // Start the receiver
trc(F("IR_EMITTER_PIN "));
trc(IR_EMITTER_PIN);
trc(F("IR_RECEIVER_PIN "));
trc(IR_RECEIVER_PIN);
trc(F("ZgatewayIR setup done "));
}
void IRtoMQTT(){
decode_results results;
if (irrecv.decode(&results)){
trc(F("Creating IR buffer"));
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
JsonObject& IRdata = jsonBuffer.createObject();
trc(F("Rcv. IR"));
#ifdef ESP32
String taskMessage = "Task running on core ";
taskMessage = taskMessage + xPortGetCoreID();
trc(taskMessage);
#endif
IRdata.set("value", (unsigned long)(results.value));
IRdata.set("protocol", (int)(results.decode_type));
IRdata.set("bits",(int)(results.bits));
trc(F("LED MNG"));
digitalWrite(led_receive, LOW);
timer_led_receive = millis();
String rawCode = "";
// Dump data
for (uint16_t i = 1; i < results.rawlen; i++) {
#ifdef ESP8266
if (i % 100 == 0) yield(); // Preemptive yield every 100th entry to feed the WDT.
rawCode = rawCode + (results.rawbuf[i] * RAWTICK);
#else
rawCode = rawCode + (results.rawbuf[i] * USECPERTICK);
#endif
if ( i < results.rawlen-1 ) rawCode = rawCode + ","; // ',' not needed on last one
}
trc(rawCode);
IRdata.set("raw", rawCode);
// if needed we directly resend the raw code
if (RawDirectForward){
#ifdef ESP8266
uint16_t rawsend[results.rawlen];
for (uint16_t i = 1; i < results.rawlen; i++) {
if (i % 100 == 0) yield(); // Preemptive yield every 100th entry to feed the WDT.
#else
unsigned int rawsend[results.rawlen];
for (int i = 1; i < results.rawlen; i++) {
#endif
rawsend[i] = results.rawbuf[i];
}
irsend.sendRaw(rawsend, results.rawlen, RawFrequency);
trc(F("raw signal redirected"));
}
irrecv.resume(); // Receive the next value
unsigned long MQTTvalue = IRdata.get<unsigned long>("value");
if (pubIRunknownPrtcl == false && IRdata.get<int>("protocol") == -1){ // don't publish unknown IR protocol
trc(F("--no pub. unknown protocol--"));
} else if (!isAduplicate(MQTTvalue) && MQTTvalue!=0) {// conditions to avoid duplications of RF -->MQTT
trc(F("Adv data IRtoMQTT"));
pub(subjectIRtoMQTT,IRdata);
if (repeatIRwMQTT){
trc(F("Pub. IR for repeat"));
pub(subjectMQTTtoIR,MQTTvalue);
}
}
}
}
#ifdef simplePublishing
void MQTTtoIR(char * topicOri, char * datacallback) {
// IR DATA ANALYSIS
//send received MQTT value by IR signal
boolean signalSent = false;
uint64_t data = 0;
String strcallback = String(datacallback);
trc(datacallback);
unsigned int s = strcallback.length();
//number of "," value count
int count = 0;
for(int i = 0; i < s; i++)
{
if (datacallback[i] == ',') {
count++;
}
}
if(count == 0){
data = strtoul(datacallback, NULL, 10); // standard sending with unsigned long, we will not be able to pass values > 4294967295
}
#ifdef IR_GC
else if(strstr(topicOri, "IR_GC") != NULL){ // sending GC data from https://irdb.globalcache.com
trc("IR_GC");
//buffer allocation from char datacallback
uint16_t GC[count+1];
String value = "";
int j = 0;
for(int i = 0; i < s; i++)
{
if (datacallback[i] != ',') {
value = value + String(datacallback[i]);
}
if ((datacallback[i] == ',') || (i == s - 1))
{
GC[j]= value.toInt();
value = "";
j++;
}
}
irsend.sendGC(GC, j);
signalSent = true;
}
#endif
#ifdef IR_Raw
else if(strstr(topicOri, "IR_Raw") != NULL){ // sending Raw data
trc("IR_Raw");
//buffer allocation from char datacallback
#ifdef ESP8266
uint16_t Raw[count+1];
#else
unsigned int Raw[count+1];
#endif
String value = "";
int j = 0;
for(int i = 0; i < s; i++)
{
if (datacallback[i] != ',') {
value = value + String(datacallback[i]);
}
if ((datacallback[i] == ',') || (i == s - 1))
{
Raw[j]= value.toInt();
value = "";
j++;
}
}
irsend.sendRaw(Raw, j, RawFrequency);
signalSent = true;
}
#endif
//We look into the subject to see if a special Bits number is defined
String topic = topicOri;
unsigned int valueBITS = 0;
int pos = topic.lastIndexOf(IRbitsKey);
if (pos != -1){
pos = pos + +strlen(IRbitsKey);
valueBITS = (topic.substring(pos,pos + 2)).toInt();
trc(F("Bits nb:"));
trc(valueBITS);
}
//We look into the subject to see if a special repeat number is defined
uint16_t valueRPT = 0;
int pos2 = topic.lastIndexOf(IRRptKey);
if (pos2 != -1) {
pos2 = pos2 + strlen(IRRptKey);
valueRPT = (topic.substring(pos2,pos2 + 1)).toInt();
trc(F("IR repeat:"));
trc(valueRPT);
}
#ifdef ESP8266 // send coolix not available for arduino IRRemote library
#ifdef IR_COOLIX
if (strstr(topicOri, "IR_COOLIX") != NULL){
if (valueBITS == 0) valueBITS = COOLIX_BITS;
irsend.sendCOOLIX(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#endif
if (strstr(topicOri, "IR_NEC") != NULL || strstr(topicOri, subjectMQTTtoIR) != NULL ){
if (valueBITS == 0) valueBITS = NEC_BITS;
#ifdef ESP8266
irsend.sendNEC(data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendNEC(data, valueBITS);
#endif
signalSent = true;
}
#ifdef IR_Whynter
if (strstr(topicOri, "IR_Whynter") != NULL){
if (valueBITS == 0) valueBITS = WHYNTER_BITS;
#ifdef ESP8266
irsend.sendWhynter(data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendWhynter(data, valueBITS);
#endif
signalSent = true;
}
#endif
#ifdef IR_LG
if (strstr(topicOri, "IR_LG") != NULL){
if (valueBITS == 0) valueBITS = LG_BITS;
#ifdef ESP8266
irsend.sendLG(data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendLG(data, valueBITS);
#endif
signalSent = true;
}
#endif
#ifdef IR_Sony
if (strstr(topicOri, "IR_Sony") != NULL){
if (valueBITS == 0) valueBITS = SONY_12_BITS;
if (valueRPT == 0) valueRPT = repeatIRwNumber;
#ifdef ESP8266
irsend.sendSony(data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendSony(data, valueBITS);
#endif
signalSent = true;
}
#endif
#ifdef IR_DISH
if (strstr(topicOri, "IR_DISH") != NULL){
if (valueBITS == 0) valueBITS = DISH_BITS;
#ifdef ESP8266
irsend.sendDISH(data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendDISH(data, valueBITS);
#endif
signalSent = true;
}
#endif
#ifdef IR_RC5
if (strstr(topicOri, "IR_RC5") != NULL){
if (valueBITS == 0) valueBITS = RC5_BITS;
#ifdef ESP8266
irsend.sendRC5(data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendRC5(data, valueBITS);
#endif
signalSent = true;
}
#endif
#ifdef IR_RC6
if (strstr(topicOri, "IR_RC6") != NULL){
if (valueBITS == 0) valueBITS = RC6_MODE0_BITS;
#ifdef ESP8266
irsend.sendRC6(data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendRC6(data, valueBITS);
#endif
signalSent = true;
}
#endif
#ifdef IR_Sharp
if (strstr(topicOri, "IR_Sharp") != NULL){
if (valueBITS == 0) valueBITS = SHARP_BITS;
#ifdef ESP8266
irsend.sendSharpRaw(data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendSharpRaw(data, valueBITS);
#endif
signalSent = true;
}
#endif
#ifdef IR_SAMSUNG
if (strstr(topicOri, "IR_SAMSUNG") != NULL){
if (valueBITS == 0) valueBITS = SAMSUNG_BITS;
#ifdef ESP8266
irsend.sendSAMSUNG(data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendSAMSUNG(data, valueBITS);
#endif
signalSent = true;
}
#endif
#ifdef IR_JVC
if (strstr(topicOri, "IR_JVC") != NULL){
if (valueBITS == 0) valueBITS = JVC_BITS;
if (valueRPT == 0) valueRPT = repeatIRwNumber;
#ifdef ESP8266
irsend.sendJVC(data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendJVC(data, valueBITS);
#endif
signalSent = true;
}
#endif
#ifdef IR_PANASONIC
if (strstr(topicOri, "IR_PANASONIC") != NULL){
if (valueRPT == 0) valueRPT = repeatIRwNumber;
#ifdef ESP8266
if (valueBITS == 0) valueBITS = PANASONIC_BITS;
irsend.sendPanasonic(PanasonicAddress, data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendPanasonic(PanasonicAddress, data);
#endif
signalSent = true;
}
#endif
#ifdef ESP8266 // sendings not available on arduino
#ifdef IR_RCMM
if (strstr(topicOri, "IR_RCMM") != NULL){
if (valueBITS == 0) valueBITS = RCMM_BITS;
irsend.sendRCMM(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#ifdef IR_DENON
if (strstr(topicOri, "IR_DENON") != NULL){
if (valueBITS == 0) valueBITS = DENON_BITS;
irsend.sendDenon(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#ifdef IR_GICABLE
if (strstr(topicOri, "IR_GICABLE") != NULL){
if (valueBITS == 0) valueBITS = GICABLE_BITS;
if (valueRPT == 0) valueRPT = std::max(valueRPT, (uint16_t) GICABLE_MIN_REPEAT);
irsend.sendGICable(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#ifdef IR_SHERWOOD
if (strstr(topicOri, "IR_SHERWOOD") != NULL){
if (valueBITS == 0) valueBITS = SHERWOOD_BITS;
if (valueRPT == 0) valueRPT = std::max(valueRPT, (uint16_t) SHERWOOD_MIN_REPEAT);
irsend.sendSherwood(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#ifdef IR_MITSUBISHI
if (strstr(topicOri, "IR_MITSUBISHI") != NULL){
if (valueBITS == 0) valueBITS = MITSUBISHI_BITS;
if (valueRPT == 0) valueRPT = std::max(valueRPT, (uint16_t) MITSUBISHI_MIN_REPEAT);
irsend.sendMitsubishi(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#ifdef IR_NIKAI
if (strstr(topicOri, "IR_NIKAI") != NULL){
if (valueBITS == 0) valueBITS = NIKAI_BITS;
irsend.sendNikai(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#ifdef IR_MIDEA
if (strstr(topicOri, "IR_MIDEA") != NULL){
if (valueBITS == 0) valueBITS = MIDEA_BITS;
irsend.sendMidea(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#ifdef IR_MAGIQUEST
if (strstr(topicOri, "IR_MAGIQUEST") != NULL){
if (valueBITS == 0) valueBITS = MAGIQUEST_BITS;
irsend.sendMagiQuest(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#ifdef IR_LASERTAG
if (strstr(topicOri, "IR_LASERTAG") != NULL){
if (valueBITS == 0) valueBITS = LASERTAG_BITS;
irsend.sendLasertag(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#ifdef IR_CARRIER_AC
if (strstr(topicOri, "IR_CARRIER_AC") != NULL){
if (valueBITS == 0) valueBITS = CARRIER_AC_BITS;
irsend.sendCarrierAC(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#ifdef IR_MITSUBISHI2
if (strstr(topicOri, "IR_MITSUBISHI2") != NULL){
if (valueBITS == 0) valueBITS = MITSUBISHI_BITS;
if (valueRPT == 0) valueRPT = std::max(valueRPT, (uint16_t) MITSUBISHI_MIN_REPEAT);
irsend.sendMitsubishi2(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#ifdef IR_AIWA_RC_T501
if (strstr(topicOri, "IR_MITSUBISHI") != NULL){
if (valueBITS == 0) valueBITS = AIWA_RC_T501_BITS;
if (valueRPT == 0) valueRPT = std::max(valueRPT, (uint16_t) AIWA_RC_T501_MIN_REPEAT);
irsend.sendAiwaRCT501(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#endif
if (signalSent){ // we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
pub(subjectGTWIRtoMQTT, datacallback);
}
irrecv.enableIRIn(); // ReStart the IR receiver (if not restarted it is not able to receive data)
}
#endif
#ifdef jsonPublishing
void MQTTtoIR(char * topicOri, JsonObject& IRdata) {
String topic = topicOri;
if (topic == subjectMQTTtoIR) {
trc(F("MQTTtoIR json data analysis"));
unsigned long data = IRdata["value"];
const char * raw = IRdata["raw"];
if (data != 0||raw) {
trc(F("MQTTtoIR data || raw ok"));
boolean signalSent = false;
trc(data);
const char * protocol_name = IRdata["protocol_name"];
if(raw){
unsigned int s = strlen(raw);
//number of "," value count
int count = 0;
for(int i = 0; i < s; i++)
{
if (raw[i] == ',') {
count++;
}
}
#ifdef IR_GC
if(strstr(protocol_name, "IR_GC") != NULL){ // sending GC data from https://irdb.globalcache.com
trc("IR_GC");
//buffer allocation from char datacallback
uint16_t GC[count+1];
String value = "";
int j = 0;
for(int i = 0; i < s; i++)
{
if (raw[i] != ',') {
value = value + String(raw[i]);
}
if ((raw[i] == ',') || (i == s - 1))
{
GC[j]= value.toInt();
value = "";
j++;
}
}
irsend.sendGC(GC, j);
signalSent = true;
}
#endif
#ifdef IR_Raw
if(strstr(protocol_name, "IR_Raw") != NULL){ // sending Raw data
trc("IR_Raw");
//buffer allocation from char datacallback
#ifdef ESP8266
uint16_t Raw[count+1];
#else
unsigned int Raw[count+1];
#endif
String value = "";
int j = 0;
for(int i = 0; i < s; i++)
{
if (raw[i] != ',') {
value = value + String(raw[i]);
}
if ((raw[i] == ',') || (i == s - 1))
{
Raw[j]= value.toInt();
value = "";
j++;
}
}
irsend.sendRaw(Raw, j, RawFrequency);
signalSent = true;
}
#endif
}else if(protocol_name){
unsigned int valueBITS = IRdata["bits"];
trc(F("Bits nb:"));
trc(valueBITS);
uint16_t valueRPT = IRdata["repeat"]|repeatIRwNumber;
trc(F("IR repeat:"));
trc(valueRPT);
#ifdef ESP8266 // send coolix not available for arduino IRRemote library
#ifdef IR_COOLIX
if (strstr(protocol_name, "IR_COOLIX") != NULL){
if (valueBITS == 0) valueBITS = COOLIX_BITS;
irsend.sendCOOLIX(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#endif
if (strstr(protocol_name, "IR_NEC") != NULL || !protocol_name ){
if (valueBITS == 0) valueBITS = NEC_BITS;
#ifdef ESP8266
irsend.sendNEC(data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendNEC(data, valueBITS);
#endif
signalSent = true;
}
#ifdef IR_Whynter
if (strstr(protocol_name, "IR_Whynter") != NULL){
if (valueBITS == 0) valueBITS = WHYNTER_BITS;
#ifdef ESP8266
irsend.sendWhynter(data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendWhynter(data, valueBITS);
#endif
signalSent = true;
}
#endif
#ifdef IR_LG
if (strstr(protocol_name, "IR_LG") != NULL){
if (valueBITS == 0) valueBITS = LG_BITS;
#ifdef ESP8266
irsend.sendLG(data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendLG(data, valueBITS);
#endif
signalSent = true;
}
#endif
#ifdef IR_Sony
if (strstr(protocol_name, "IR_Sony") != NULL){
if (valueBITS == 0) valueBITS = SONY_12_BITS;
#ifdef ESP8266
irsend.sendSony(data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendSony(data, valueBITS);
#endif
signalSent = true;
}
#endif
#ifdef IR_DISH
if (strstr(protocol_name, "IR_DISH") != NULL){
if (valueBITS == 0) valueBITS = DISH_BITS;
#ifdef ESP8266
irsend.sendDISH(data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendDISH(data, valueBITS);
#endif
signalSent = true;
}
#endif
#ifdef IR_RC5
if (strstr(protocol_name, "IR_RC5") != NULL){
if (valueBITS == 0) valueBITS = RC5_BITS;
#ifdef ESP8266
irsend.sendRC5(data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendRC5(data, valueBITS);
#endif
signalSent = true;
}
#endif
#ifdef IR_RC6
if (strstr(protocol_name, "IR_RC6") != NULL){
if (valueBITS == 0) valueBITS = RC6_MODE0_BITS;
#ifdef ESP8266
irsend.sendRC6(data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendRC6(data, valueBITS);
#endif
signalSent = true;
}
#endif
#ifdef IR_Sharp
if (strstr(protocol_name, "IR_Sharp") != NULL){
if (valueBITS == 0) valueBITS = SHARP_BITS;
#ifdef ESP8266
irsend.sendSharpRaw(data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendSharpRaw(data, valueBITS);
#endif
signalSent = true;
}
#endif
#ifdef IR_SAMSUNG
if (strstr(protocol_name, "IR_SAMSUNG") != NULL){
if (valueBITS == 0) valueBITS = SAMSUNG_BITS;
#ifdef ESP8266
irsend.sendSAMSUNG(data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendSAMSUNG(data, valueBITS);
#endif
signalSent = true;
}
#endif
#ifdef IR_JVC
if (strstr(protocol_name, "IR_JVC") != NULL){
if (valueBITS == 0) valueBITS = JVC_BITS;
#ifdef ESP8266
irsend.sendJVC(data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendJVC(data, valueBITS);
#endif
signalSent = true;
}
#endif
#ifdef IR_PANASONIC
if (strstr(protocol_name, "IR_PANASONIC") != NULL){
#ifdef ESP8266
if (valueBITS == 0) valueBITS = PANASONIC_BITS;
irsend.sendPanasonic(PanasonicAddress, data, valueBITS, valueRPT);
#else
for (int i=0; i <= valueRPT; i++) irsend.sendPanasonic(PanasonicAddress, data);
#endif
signalSent = true;
}
#endif
#ifdef ESP8266 // sendings not available on arduino
#ifdef IR_RCMM
if (strstr(protocol_name, "IR_RCMM") != NULL){
if (valueBITS == 0) valueBITS = RCMM_BITS;
irsend.sendRCMM(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#ifdef IR_DENON
if (strstr(protocol_name, "IR_DENON") != NULL){
if (valueBITS == 0) valueBITS = DENON_BITS;
irsend.sendDenon(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#ifdef IR_GICABLE
if (strstr(protocol_name, "IR_GICABLE") != NULL){
if (valueBITS == 0) valueBITS = GICABLE_BITS;
if (valueRPT == repeatIRwNumber) valueRPT = std::max(valueRPT, (uint16_t) GICABLE_MIN_REPEAT);
irsend.sendGICable(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#ifdef IR_SHERWOOD
if (strstr(protocol_name, "IR_SHERWOOD") != NULL){
if (valueBITS == 0) valueBITS = SHERWOOD_BITS;
if (valueRPT == repeatIRwNumber) valueRPT = std::max(valueRPT, (uint16_t) SHERWOOD_MIN_REPEAT);
irsend.sendSherwood(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#ifdef IR_MITSUBISHI
if (strstr(protocol_name, "IR_MITSUBISHI") != NULL){
if (valueBITS == 0) valueBITS = MITSUBISHI_BITS;
if (valueRPT == repeatIRwNumber) valueRPT = std::max(valueRPT, (uint16_t) MITSUBISHI_MIN_REPEAT);
irsend.sendMitsubishi(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#ifdef IR_NIKAI
if (strstr(protocol_name, "IR_NIKAI") != NULL){
if (valueBITS == 0) valueBITS = NIKAI_BITS;
irsend.sendNikai(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#ifdef IR_MIDEA
if (strstr(protocol_name, "IR_MIDEA") != NULL){
if (valueBITS == 0) valueBITS = MIDEA_BITS;
irsend.sendMidea(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#ifdef IR_MAGIQUEST
if (strstr(protocol_name, "IR_MAGIQUEST") != NULL){
if (valueBITS == 0) valueBITS = MAGIQUEST_BITS;
irsend.sendMagiQuest(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#ifdef IR_LASERTAG
if (strstr(protocol_name, "IR_LASERTAG") != NULL){
if (valueBITS == 0) valueBITS = LASERTAG_BITS;
irsend.sendLasertag(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#ifdef IR_CARRIER_AC
if (strstr(protocol_name, "IR_CARRIER_AC") != NULL){
if (valueBITS == 0) valueBITS = CARRIER_AC_BITS;
irsend.sendCarrierAC(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#ifdef IR_MITSUBISHI2
if (strstr(protocol_name, "IR_MITSUBISHI2") != NULL){
if (valueBITS == 0) valueBITS = MITSUBISHI_BITS;
if (valueRPT == repeatIRwNumber) valueRPT = std::max(valueRPT, (uint16_t) MITSUBISHI_MIN_REPEAT);
irsend.sendMitsubishi2(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#ifdef IR_AIWA_RC_T501
if (strstr(protocol_name, "IR_MITSUBISHI") != NULL){
if (valueBITS == 0) valueBITS = AIWA_RC_T501_BITS;
if (valueRPT == repeatIRwNumber) valueRPT = std::max(valueRPT, (uint16_t) AIWA_RC_T501_MIN_REPEAT);
irsend.sendAiwaRCT501(data, valueBITS, valueRPT);
signalSent = true;
}
#endif
#endif
if (signalSent){ // we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
pub(subjectGTWIRtoMQTT, IRdata);
}
irrecv.enableIRIn(); // ReStart the IR receiver (if not restarted it is not able to receive data)
}else{
trc(F("MQTTtoIR Fail reading protocol name from json"));
}
}else{
trc(F("MQTTtoIR Fail reading from json"));
}
}
}
#endif
#endif