-
Notifications
You must be signed in to change notification settings - Fork 1
/
PanasonicHeatpumpController.ino
821 lines (723 loc) · 22.9 KB
/
PanasonicHeatpumpController.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
// Simple web form based application to control a
// Panasonic CKP-series heat pump
//
// Connect an IR led (with 1k resistor in series)
// between GND and digital pin 3
//
// Browse to http://192.168.0.210 (or whatever you set as the address)
// Requires the Ethernet shield and Webduino:
// https://github.com/sirleech/Webduino
#include <Arduino.h>
#include "SPI.h"
#include "avr/pgmspace.h"
#include "Ethernet.h"
#include "WebServer.h"
// Infrared LED on PIN digital 3
// Connect with 1 kOhm resistor in series to GND
#define IR_LED_PIN 3
// Panasonic CKP timing constants
#define PANASONIC_AIRCON1_HDR_MARK 3400
#define PANASONIC_AIRCON1_HDR_SPACE 3500
#define PANASONIC_AIRCON1_BIT_MARK 800
#define PANASONIC_AIRCON1_ONE_SPACE 2700
#define PANASONIC_AIRCON1_ZERO_SPACE 1000
#define PANASONIC_AIRCON1_MSG_SPACE 14000
// Panasonic CKP codes
#define PANASONIC_AIRCON1_MODE_AUTO 0x06 // Operating mode
#define PANASONIC_AIRCON1_MODE_HEAT 0x04
#define PANASONIC_AIRCON1_MODE_COOL 0x02
#define PANASONIC_AIRCON1_MODE_DRY 0x03
#define PANASONIC_AIRCON1_MODE_FAN 0x01
#define PANASONIC_AIRCON1_MODE_ONOFF 0x00 // Toggle ON/OFF
#define PANASONIC_AIRCON1_MODE_KEEP 0x08 // Do not toggle ON/OFF
#define PANASONIC_AIRCON1_FAN_AUTO 0xF0 // Fan speed
#define PANASONIC_AIRCON1_FAN1 0x20
#define PANASONIC_AIRCON1_FAN2 0x30
#define PANASONIC_AIRCON1_FAN3 0x40
#define PANASONIC_AIRCON1_FAN4 0x50
#define PANASONIC_AIRCON1_FAN5 0x60
#define PANASONIC_AIRCON1_VS_AUTO 0xF0 // Vertical swing
#define PANASONIC_AIRCON1_VS_UP 0x90
#define PANASONIC_AIRCON1_VS_MUP 0xA0
#define PANASONIC_AIRCON1_VS_MIDDLE 0xB0
#define PANASONIC_AIRCON1_VS_MDOWN 0xC0
#define PANASONIC_AIRCON1_VS_DOWN 0xD0
#define PANASONIC_AIRCON1_HS_AUTO 0x08 // Horizontal swing
#define PANASONIC_AIRCON1_HS_MANUAL 0x00
// Panasonic DKE timing constants
#define PANASONIC_AIRCON2_HDR_MARK 3500
#define PANASONIC_AIRCON2_HDR_SPACE 1800
#define PANASONIC_AIRCON2_BIT_MARK 420
#define PANASONIC_AIRCON2_ONE_SPACE 1350
#define PANASONIC_AIRCON2_ZERO_SPACE 470
#define PANASONIC_AIRCON2_MSG_SPACE 10000
// Panasonic DKE codes
#define PANASONIC_AIRCON2_MODE_AUTO 0x00 // Operating mode
#define PANASONIC_AIRCON2_MODE_HEAT 0x40
#define PANASONIC_AIRCON2_MODE_COOL 0x30
#define PANASONIC_AIRCON2_MODE_DRY 0x20
#define PANASONIC_AIRCON2_MODE_FAN 0x60
#define PANASONIC_AIRCON2_MODE_OFF 0x00 // Power OFF
#define PANASONIC_AIRCON2_MODE_ON 0x01
#define PANASONIC_AIRCON2_TIMER_CNL 0x08
#define PANASONIC_AIRCON2_FAN_AUTO 0xA0 // Fan speed
#define PANASONIC_AIRCON2_FAN1 0x30
#define PANASONIC_AIRCON2_FAN2 0x40
#define PANASONIC_AIRCON2_FAN3 0x50
#define PANASONIC_AIRCON2_FAN4 0x60
#define PANASONIC_AIRCON2_FAN5 0x70
#define PANASONIC_AIRCON2_VS_AUTO 0x0F // Vertical swing
#define PANASONIC_AIRCON2_VS_UP 0x01
#define PANASONIC_AIRCON2_VS_MUP 0x02
#define PANASONIC_AIRCON2_VS_MIDDLE 0x03
#define PANASONIC_AIRCON2_VS_MDOWN 0x04
#define PANASONIC_AIRCON2_VS_DOWN 0x05
#define PANASONIC_AIRCON2_HS_AUTO 0x0D // Horizontal swing
#define PANASONIC_AIRCON2_HS_MIDDLE 0x06
#define PANASONIC_AIRCON2_HS_LEFT 0x09
#define PANASONIC_AIRCON2_HS_MLEFT 0x0A
#define PANASONIC_AIRCON2_HS_MRIGHT 0x0B
#define PANASONIC_AIRCON2_HS_RIGHT 0x0C
// flash-based web pages to save precious RAM
P(indexpage) = "<!DOCTYPE html>\n"
"<html>\n"
"<body>\n"
"\n"
"\n"
"<table border=\"1\">\n"
"<tr><td>\n"
"PANASONIC CPK\n"
"<form name=\"input\" action=\"send_ir_ckp.html\" method=\"get\">\n"
"<table border=\"1\">\n"
"<tr><td>\n"
"<input type=\"checkbox\" name=\"power\" value=\"power\">\n"
"</td><td>\n"
"Switch power state\n"
"</td></tr>\n"
"\n"
"<tr><td>\n"
"<select name=\"mode\">\n"
" <option value=\"1\">AUTO</option>\n"
" <option value=\"2\" selected=\"selected\">HEAT</option>\n"
" <option value=\"3\">COOL</option>\n"
" <option value=\"4\">DRY</option>\n"
" <option value=\"5\">FAN</option>\n"
"</select> \n"
"</td><td>\n"
"Mode\n"
"</td></tr>\n"
"\n"
"<tr><td>\n"
"<select name=\"fan\">\n"
" <option value=\"1\" selected=\"selected\">AUTO</option>\n"
" <option value=\"2\">1</option>\n"
" <option value=\"3\">2</option>\n"
" <option value=\"4\">3</option>\n"
" <option value=\"5\">4</option>\n"
" <option value=\"6\">5</option>\n"
"</select> \n"
"</td><td>\n"
"Fan speed\n"
"</td></tr>\n"
"\n"
"<tr><td>\n"
"<select name=\"temperature\">\n"
" <option value=\"16\">16</option>\n"
" <option value=\"17\">17</option>\n"
" <option value=\"18\">18</option>\n"
" <option value=\"19\">19</option>\n"
" <option value=\"20\">20</option>\n"
" <option value=\"21\">21</option>\n"
" <option value=\"22\">22</option>\n"
" <option value=\"23\" selected=\"selected\">23</option>\n"
" <option value=\"24\">24</option>\n"
" <option value=\"25\">25</option>\n"
" <option value=\"26\">26</option>\n"
" <option value=\"27\">27</option>\n"
" <option value=\"28\">28</option>\n"
" <option value=\"29\">29</option>\n"
" <option value=\"30\">30</option>\n"
"</select> \n"
"</td><td>\n"
"Temperature\n"
"</td></tr>\n"
"\n"
"<tr><td>\n"
"<select name=\"vswing\">\n"
" <option value=\"1\" >AUTO</option>\n"
" <option value=\"2\" selected=\"selected\">UP</option>\n"
" <option value=\"3\" >MIDDLE UP</option>\n"
" <option value=\"4\" >MIDDLE</option>\n"
" <option value=\"5\" >MIDDLE DOWN</option>\n"
" <option value=\"6\" >DOWN</option>\n"
"</select>\n"
"</td><td>\n"
"Vertical swing\n"
"</td></tr>\n"
"\n"
"<tr><td>\n"
"<select name=\"hswing\">\n"
" <option value=\"1\" >AUTO</option>\n"
" <option value=\"2\" selected=\"selected\">MANUAL</option>\n"
"</select>\n"
"</td><td>\n"
"Horizontal swing\n"
"</td></tr>\n"
"\n"
"</table>\n"
"\n"
"<input type=\"submit\" value=\"Submit CKP\">\n"
"</form>\n"
"</td>\n"
"\n"
"<td>\n"
"PANASONIC DKE\n"
"<form name=\"input\" action=\"send_ir_dke.html\" method=\"get\">\n"
"<table border=\"1\">\n"
"<tr><td>\n"
"<input type=\"radio\" name=\"power\" value=\"1\" checked>ON\n"
"<input type=\"radio\" name=\"power\" value=\"0\">OFF\n"
"</td><td>\n"
"Power state\n"
"</td></tr>\n"
"\n"
"<tr><td>\n"
"<select name=\"mode\">\n"
" <option value=\"1\">AUTO</option>\n"
" <option value=\"2\" selected=\"selected\">HEAT</option>\n"
" <option value=\"3\">COOL</option>\n"
" <option value=\"4\">DRY</option>\n"
" <option value=\"5\">FAN</option>\n"
"</select> \n"
"</td><td>\n"
"Mode\n"
"</td></tr>\n"
"\n"
"<tr><td>\n"
"<select name=\"fan\">\n"
" <option value=\"1\" selected=\"selected\">AUTO</option>\n"
" <option value=\"2\">1</option>\n"
" <option value=\"3\">2</option>\n"
" <option value=\"4\">3</option>\n"
" <option value=\"5\">4</option>\n"
" <option value=\"6\">5</option>\n"
"</select> \n"
"</td><td>\n"
"Fan speed\n"
"</td></tr>\n"
"\n"
"<tr><td>\n"
"<select name=\"temperature\">\n"
" <option value=\"16\">16</option>\n"
" <option value=\"17\">17</option>\n"
" <option value=\"18\">18</option>\n"
" <option value=\"19\">19</option>\n"
" <option value=\"20\">20</option>\n"
" <option value=\"21\">21</option>\n"
" <option value=\"22\">22</option>\n"
" <option value=\"23\" selected=\"selected\">23</option>\n"
" <option value=\"24\">24</option>\n"
" <option value=\"25\">25</option>\n"
" <option value=\"26\">26</option>\n"
" <option value=\"27\">27</option>\n"
" <option value=\"28\">28</option>\n"
" <option value=\"29\">29</option>\n"
" <option value=\"30\">30</option>\n"
"</select> \n"
"</td><td>\n"
"Temperature\n"
"</td></tr>\n"
"\n"
"<tr><td>\n"
"<select name=\"vswing\">\n"
" <option value=\"1\" >AUTO</option>\n"
" <option value=\"2\" selected=\"selected\">UP</option>\n"
" <option value=\"3\" >MIDDLE UP</option>\n"
" <option value=\"4\" >MIDDLE</option>\n"
" <option value=\"5\" >MIDDLE DOWN</option>\n"
" <option value=\"6\" >DOWN</option>\n"
"</select>\n"
"</td><td>\n"
"Vertical swing\n"
"</td></tr>\n"
"\n"
"<tr><td>\n"
"<select name=\"hswing\">\n"
" <option value=\"1\" selected=\"selected\">AUTO</option>\n"
" <option value=\"2\" >MIDDLE</option>\n"
" <option value=\"3\" >LEFT</option>\n"
" <option value=\"4\" >LEFT MIDDLE</option>\n"
" <option value=\"5\" >RIGHT</option>\n"
" <option value=\"6\" >RIGHT MIDDLE</option>\n"
"</select>\n"
"</td><td>\n"
"Horizontal swing\n"
"</td></tr>\n"
"\n"
"</td></tr>\n"
"</table>\n"
"<input type=\"submit\" value=\"Submit DKE\">\n"
"</form>\n"
"</td></tr>\n"
"\n"
"</table>\n"
"\n"
"</body>\n"
"</html>\n";
P(formactionpage_header) = "<!DOCTYPE html>"
"<html>"
"<body>"
"<h1>Parameters</h1>";
P(formactionpage_footer) = ""
"</body>"
"</html>";
// Lenght parameters
// * name of parameter
// * value of parameter
// * overall lenght of the 'GET' type URL
#define NAMELEN 32
#define VALUELEN 32
#define URLLEN 128
// Webserver instance initialization on port 80
WebServer webserver("",80);
// Send the Panasonic CKP code
void sendPanasonicCKP(byte operatingMode, byte fanSpeed, byte temperature, byte swingV, byte swingH)
{
byte sendBuffer[4];
// Fan speed & temperature, temperature needs to be 27 in FAN mode
if (operatingMode == PANASONIC_AIRCON1_MODE_FAN || operatingMode == (PANASONIC_AIRCON1_MODE_FAN | PANASONIC_AIRCON1_MODE_KEEP ))
{
temperature = 27;
}
sendBuffer[0] = fanSpeed | (temperature - 15);
// Power toggle & operation mode
sendBuffer[1] = operatingMode;
// Swings
sendBuffer[2] = swingV | swingH;
// Always 0x36
sendBuffer[3] = 0x36;
// Send the code
sendPanasonicCKPraw(sendBuffer);
}
// Send the Panasonic CKP raw code
void sendPanasonicCKPraw(byte sendBuffer[])
{
// 40 kHz PWM frequency
enableIROut(40);
// Header, two first bytes repeated
mark(PANASONIC_AIRCON1_HDR_MARK);
space(PANASONIC_AIRCON1_HDR_SPACE);
for (int i=0; i<2; i++) {
sendIRByte(sendBuffer[0], PANASONIC_AIRCON1_BIT_MARK, PANASONIC_AIRCON1_ZERO_SPACE, PANASONIC_AIRCON1_ONE_SPACE);
sendIRByte(sendBuffer[0], PANASONIC_AIRCON1_BIT_MARK, PANASONIC_AIRCON1_ZERO_SPACE, PANASONIC_AIRCON1_ONE_SPACE);
sendIRByte(sendBuffer[1], PANASONIC_AIRCON1_BIT_MARK, PANASONIC_AIRCON1_ZERO_SPACE, PANASONIC_AIRCON1_ONE_SPACE);
sendIRByte(sendBuffer[1], PANASONIC_AIRCON1_BIT_MARK, PANASONIC_AIRCON1_ZERO_SPACE, PANASONIC_AIRCON1_ONE_SPACE);
mark(PANASONIC_AIRCON1_HDR_MARK);
space(PANASONIC_AIRCON1_HDR_SPACE);
}
// Pause
mark(PANASONIC_AIRCON1_BIT_MARK);
space(PANASONIC_AIRCON1_MSG_SPACE);
// Header, two last bytes repeated
mark(PANASONIC_AIRCON1_HDR_MARK);
space(PANASONIC_AIRCON1_HDR_SPACE);
for (int i=0; i<2; i++) {
sendIRByte(sendBuffer[2], PANASONIC_AIRCON1_BIT_MARK, PANASONIC_AIRCON1_ZERO_SPACE, PANASONIC_AIRCON1_ONE_SPACE);
sendIRByte(sendBuffer[2], PANASONIC_AIRCON1_BIT_MARK, PANASONIC_AIRCON1_ZERO_SPACE, PANASONIC_AIRCON1_ONE_SPACE);
sendIRByte(sendBuffer[3], PANASONIC_AIRCON1_BIT_MARK, PANASONIC_AIRCON1_ZERO_SPACE, PANASONIC_AIRCON1_ONE_SPACE);
sendIRByte(sendBuffer[3], PANASONIC_AIRCON1_BIT_MARK, PANASONIC_AIRCON1_ZERO_SPACE, PANASONIC_AIRCON1_ONE_SPACE);
mark(PANASONIC_AIRCON1_HDR_MARK);
space(PANASONIC_AIRCON1_HDR_SPACE);
}
mark(PANASONIC_AIRCON1_BIT_MARK);
space(0);
}
// Send the Panasonic DKE raw code
void sendPanasonicDKEraw(byte operatingMode, byte fanSpeed, byte temperature, byte swingV, byte swingH)
{
byte DKE_template[] = { 0x02, 0x20, 0xE0, 0x04, 0x00, 0x00, 0x00, 0x06, 0x02, 0x20, 0xE0, 0x04, 0x00, 0x48, 0x2E, 0x80, 0xA3, 0x0D, 0x00, 0x0E, 0xE0, 0x00, 0x00, 0x01, 0x00, 0x06, 0xA2 };
byte checksum = 0xF4;
DKE_template[13] = operatingMode;
DKE_template[14] = temperature << 1;
DKE_template[16] = fanSpeed | swingV;
DKE_template[17] = swingH;
// Checksum
for (int i=0; i<26; i++) {
checksum += DKE_template[i];
}
DKE_template[26] = checksum;
// 40 kHz PWM frequency
enableIROut(40);
// Header
mark(PANASONIC_AIRCON2_HDR_MARK);
space(PANASONIC_AIRCON2_HDR_SPACE);
// First 8 bytes
for (int i=0; i<8; i++) {
sendIRByte(DKE_template[i], PANASONIC_AIRCON2_BIT_MARK, PANASONIC_AIRCON2_ZERO_SPACE, PANASONIC_AIRCON2_ONE_SPACE);
}
// Pause
mark(PANASONIC_AIRCON2_BIT_MARK);
space(PANASONIC_AIRCON2_MSG_SPACE);
// Header
mark(PANASONIC_AIRCON2_HDR_MARK);
space(PANASONIC_AIRCON2_HDR_SPACE);
// Last 19 bytes
for (int i=8; i<27; i++) {
sendIRByte(DKE_template[i], PANASONIC_AIRCON2_BIT_MARK, PANASONIC_AIRCON2_ZERO_SPACE, PANASONIC_AIRCON2_ONE_SPACE);
}
mark(PANASONIC_AIRCON2_BIT_MARK);
space(0);
}
// Send a byte over IR
void sendIRByte(byte sendByte, int bitMarkLength, int zeroSpaceLength, int oneSpaceLength)
{
for (int i=0; i<8 ; i++)
{
if (sendByte & 0x01)
{
mark(bitMarkLength);
space(oneSpaceLength);
}
else
{
mark(bitMarkLength);
space(zeroSpaceLength);
}
sendByte >>= 1;
}
}
// 'mark', 'space' and 'enableIROut' have been taken
// from Ken Shirriff's IRRemote library:
// https://github.com/shirriff/Arduino-IRremote
void mark(int time) {
// Sends an IR mark for the specified number of microseconds.
// The mark output is modulated at the PWM frequency.
(TCCR2A |= _BV(COM2B1)); // Enable pin 3 PWM output
delayMicroseconds(time);
}
void space(int time) {
// Sends an IR space for the specified number of microseconds.
// A space is no output, so the PWM output is disabled.
(TCCR2A &= ~(_BV(COM2B1))); // Disable pin 3 PWM output
delayMicroseconds(time);
}
void enableIROut(int khz) {
pinMode(IR_LED_PIN, OUTPUT);
digitalWrite(IR_LED_PIN, LOW); // When not sending PWM, we want it low
const uint8_t pwmval = F_CPU / 2000 / (khz);
TCCR2A = _BV(WGM20);
TCCR2B = _BV(WGM22) | _BV(CS20);
OCR2A = pwmval;
OCR2B = pwmval / 3;
}
// The index.html web page. This presents the HTML form
void indexCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
server.httpSuccess();
server.printP(indexpage);
}
// The send_ir_ckp.html. This handles the parameters submitted by the form
void ckpFormCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
URLPARAM_RESULT rc;
char name[NAMELEN];
char value[VALUELEN];
int param = 0;
// Sensible defaults for the heat pump mode
byte operatingMode = PANASONIC_AIRCON1_MODE_HEAT | PANASONIC_AIRCON1_MODE_KEEP;
byte fanSpeed = PANASONIC_AIRCON1_FAN_AUTO;
byte temperature = 23;
byte swingV = PANASONIC_AIRCON1_VS_UP;
byte swingH = PANASONIC_AIRCON1_HS_AUTO;
server.httpSuccess();
server.printP(formactionpage_header);
if (strlen(url_tail))
{
while (strlen(url_tail))
{
rc = server.nextURLparam(&url_tail, name, NAMELEN, value, VALUELEN);
if (rc != URLPARAM_EOS)
{
if (strcmp(name, "power") == 0 )
{
operatingMode ^= PANASONIC_AIRCON1_MODE_KEEP;
}
else if (strcmp(name, "mode") == 0 )
{
operatingMode &= PANASONIC_AIRCON1_MODE_KEEP;
param = atoi(value);
switch (param)
{
case 1:
operatingMode |= PANASONIC_AIRCON1_MODE_AUTO;
break;
case 2:
operatingMode |= PANASONIC_AIRCON1_MODE_HEAT;
break;
case 3:
operatingMode |= PANASONIC_AIRCON1_MODE_COOL;
break;
case 4:
operatingMode |= PANASONIC_AIRCON1_MODE_DRY;
break;
case 5:
operatingMode |= PANASONIC_AIRCON1_MODE_FAN;
break;
}
}
else if (strcmp(name, "fan") == 0 )
{
param = atoi(value);
switch (param)
{
case 1:
fanSpeed = PANASONIC_AIRCON1_FAN_AUTO;
break;
case 2:
fanSpeed = PANASONIC_AIRCON1_FAN1;
break;
case 3:
fanSpeed = PANASONIC_AIRCON1_FAN2;
break;
case 4:
fanSpeed = PANASONIC_AIRCON1_FAN3;
break;
case 5:
fanSpeed = PANASONIC_AIRCON1_FAN4;
break;
case 6:
fanSpeed = PANASONIC_AIRCON1_FAN5;
break;
}
}
else if (strcmp(name, "temperature") == 0 )
{
param = atoi(value);
if ( param >= 15 && param <= 31)
{
temperature = param;
}
}
else if (strcmp(name, "vswing") == 0 )
{
param = atoi(value);
switch (param)
{
case 1:
swingV = PANASONIC_AIRCON1_VS_AUTO;
break;
case 2:
swingV = PANASONIC_AIRCON1_VS_UP;
break;
case 3:
swingV = PANASONIC_AIRCON1_VS_MUP;
break;
case 4:
swingV = PANASONIC_AIRCON1_VS_MIDDLE;
break;
case 5:
swingV = PANASONIC_AIRCON1_VS_MDOWN;
break;
case 6:
swingV = PANASONIC_AIRCON1_VS_DOWN;
break;
}
}
else if (strcmp(name, "hswing") == 0 )
{
param = atoi(value);
switch (param)
{
case 1:
swingH = PANASONIC_AIRCON1_HS_AUTO;
break;
case 2:
swingH = PANASONIC_AIRCON1_HS_MANUAL;
break;
}
}
server.print(name);
server.print(" = ");
server.print(param);
server.print("<br>");
}
}
}
server.printP(formactionpage_footer);
sendPanasonicCKP(operatingMode, fanSpeed, temperature, swingV, swingH);
}
// The send_ir_dke.html. This handles the parameters submitted by the form
void dkeFormCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
URLPARAM_RESULT rc;
char name[NAMELEN];
char value[VALUELEN];
int param = 0;
// Sensible defaults for the heat pump mode
byte operatingMode = PANASONIC_AIRCON2_TIMER_CNL;
byte fanSpeed = PANASONIC_AIRCON2_FAN_AUTO;
byte temperature = 23;
byte swingV = PANASONIC_AIRCON2_VS_UP;
byte swingH = PANASONIC_AIRCON2_HS_AUTO;
server.httpSuccess();
server.printP(formactionpage_header);
if (strlen(url_tail))
{
while (strlen(url_tail))
{
rc = server.nextURLparam(&url_tail, name, NAMELEN, value, VALUELEN);
if (rc != URLPARAM_EOS)
{
if (strcmp(name, "power") == 0 )
{
param = atoi(value);
switch (param)
{
case 1:
operatingMode |= PANASONIC_AIRCON2_MODE_ON;
}
}
else if (strcmp(name, "mode") == 0 )
{
param = atoi(value);
switch (param)
{
case 1:
operatingMode |= PANASONIC_AIRCON2_MODE_AUTO;
break;
case 2:
operatingMode |= PANASONIC_AIRCON2_MODE_HEAT;
break;
case 3:
operatingMode |= PANASONIC_AIRCON2_MODE_COOL;
break;
case 4:
operatingMode |= PANASONIC_AIRCON2_MODE_DRY;
break;
case 5:
operatingMode |= PANASONIC_AIRCON2_MODE_FAN;
temperature = 27; // Temperature is always 27 in FAN mode
break;
}
}
else if (strcmp(name, "fan") == 0 )
{
param = atoi(value);
switch (param)
{
case 1:
fanSpeed = PANASONIC_AIRCON2_FAN_AUTO;
break;
case 2:
fanSpeed = PANASONIC_AIRCON2_FAN1;
break;
case 3:
fanSpeed = PANASONIC_AIRCON2_FAN2;
break;
case 4:
fanSpeed = PANASONIC_AIRCON2_FAN3;
break;
case 5:
fanSpeed = PANASONIC_AIRCON2_FAN4;
break;
case 6:
fanSpeed = PANASONIC_AIRCON2_FAN5;
break;
}
}
else if (strcmp(name, "temperature") == 0 )
{
param = atoi(value);
if ( param >= 15 && param <= 31 && temperature == 23)
{
temperature = param;
}
}
else if (strcmp(name, "vswing") == 0 )
{
param = atoi(value);
switch (param)
{
case 1:
swingV = PANASONIC_AIRCON2_VS_AUTO;
break;
case 2:
swingV = PANASONIC_AIRCON2_VS_UP;
break;
case 3:
swingV = PANASONIC_AIRCON2_VS_MUP;
break;
case 4:
swingV = PANASONIC_AIRCON2_VS_MIDDLE;
break;
case 5:
swingV = PANASONIC_AIRCON2_VS_MDOWN;
break;
case 6:
swingV = PANASONIC_AIRCON2_VS_DOWN;
break;
}
}
else if (strcmp(name, "hswing") == 0 )
{
param = atoi(value);
switch (param)
{
case 1:
swingH = PANASONIC_AIRCON2_HS_AUTO;
break;
case 2:
swingH = PANASONIC_AIRCON2_HS_MIDDLE;
break;
case 3:
swingH = PANASONIC_AIRCON2_HS_LEFT;
break;
case 4:
swingH = PANASONIC_AIRCON2_HS_MLEFT;
break;
case 5:
swingH = PANASONIC_AIRCON2_HS_RIGHT;
break;
case 6:
swingH = PANASONIC_AIRCON2_HS_MRIGHT;
break;
}
}
server.print(name);
server.print(" = ");
server.print(param);
server.print("<br>");
}
}
}
server.printP(formactionpage_footer);
sendPanasonicDKEraw(operatingMode, fanSpeed, temperature, swingV, swingH);
}
// The setup
void setup()
{
// MAC address of the Arduino, this needs to be unique within
// your home network
static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// IP address of the Arduino. Make sure this is outside of the DHCP pool
static uint8_t ip[] = { 192, 168, 0, 210 };
// initialize the Ethernet adapter
Ethernet.begin(mac, ip);
// Setup the default and the index page
webserver.setDefaultCommand(&indexCmd);
webserver.addCommand("index.html", &indexCmd);
// The form handlers
webserver.addCommand("send_ir_ckp.html", &ckpFormCmd);
webserver.addCommand("send_ir_dke.html", &dkeFormCmd);
// start the webserver
webserver.begin();
}
// The loop
void loop()
{
// URL buffer for GET parameters
char buff[URLLEN];
int len = URLLEN;
// process incoming connections one at a time forever
webserver.processConnection(buff, &len);
}