-
Notifications
You must be signed in to change notification settings - Fork 3
/
ohs_httpdhandler.h
2351 lines (2305 loc) · 122 KB
/
ohs_httpdhandler.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
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
/*
* ohs_httpdhandler.h
*
* Created on: 6. 12. 2019
* Author: vysocan
*/
#ifndef OHS_HTTPDHANDLER_H_
#define OHS_HTTPDHANDLER_H_
#include "lwip/opt.h"
#include "lwip/apps/fs.h"
#include "lwip/def.h"
#include "lwip/mem.h"
#include <stdio.h>
#include <string.h>
#include "memstreams.h"
#include "ohs_http_const.h"
#include "ohs_http_print.h"
#if !LWIP_HTTPD_CUSTOM_FILES
#error This needs LWIP_HTTPD_CUSTOM_FILES
#endif
#if !LWIP_HTTPD_FILE_EXTENSION
#error This needs LWIP_HTTPD_FILE_EXTENSION
#endif
#if !LWIP_HTTPD_DYNAMIC_HEADERS
#error This needs LWIP_HTTPD_DYNAMIC_HEADERS
#endif
#if !LWIP_HTTPD_SUPPORT_POST
#error This needs LWIP_HTTPD_SUPPORT_POST
#endif
#if !LWIP_HTTPD_SUPPORT_COOKIES
#error This needs LWIP_HTTPD_SUPPORT_COOKIES
#endif
#if !LWIP_HTTPD_SUPPORT_FS_OPEN_AUTH
#error This needs LWIP_HTTPD_SUPPORT_FS_OPEN_AUTH
#endif
#ifndef HTTP_DEBUG
#define HTTP_DEBUG 0
#endif
#if HTTP_DEBUG
#define DBG_HTTP(...) {chprintf(console, __VA_ARGS__);}
#else
#define DBG_HTTP(...)
#endif
#define HTTP_POST_DATA_SIZE 1024
#define HTTP_ALERT_MSG_SIZE 80
#define HTTP_SET_COOKIE_SIZE 48
static void *currentConn;
char current_uri[LWIP_HTTPD_MAX_REQUEST_URI_LEN] __attribute__((section(".ram4")));
char postData[HTTP_POST_DATA_SIZE] __attribute__((section(".ram4")));
char httpAlertMsg[HTTP_ALERT_MSG_SIZE] __attribute__((section(".ram4")));
char setCookie[HTTP_SET_COOKIE_SIZE] __attribute__((section(".ram4")));
void *verifiedConn = NULL;
typedef struct {
uint32_t id;
void *conn;
} authorizedConn_t;
static authorizedConn_t authorizedConn = {0, 0};
// Size of dynamic HTML page
#define HTML_PAGE_SIZE 1024 * 28
#if HTML_PAGE_SIZE > (MEM_SIZE - 1600)
#error HTML_PAGE_SIZE needs to be smaller then lwip MEM_SIZE!
#endif
#define PAGE_HOME 0
#define PAGE_SETTING 1
#define PAGE_ZONE 2
#define PAGE_GROUP 3
#define PAGE_USER 4
#define PAGE_KEY 5
#define PAGE_ALERT 6
#define PAGE_NODE 7
#define PAGE_LOG 8
#define PAGE_TIMER 9
#define PAGE_TRIGGER 10
#define PAGE_TCL 11
#define PAGE_LOGIN 12
typedef struct {
char link[14];
char name[9];
} webPage_t;
static const webPage_t webPage[] = {
// 123456789012345 123456789012345
{"/index.html", "Home"},
{"/setting.html", "Settings"},
{"/zone.html", "Zones"},
{"/group.html", "Groups"},
{"/user.html", "Users"},
{"/key.html", "Keys"},
{"/alert.html", "Alerts"},
{"/node.html", "Nodes"},
{"/log.html", "Log"},
{"/timer.html", "Timers"},
{"/trigger.html", "Triggers"},
{"/tcl.html", "Scripts"},
{"/login.html", "Login"}
};
// HTML pages global variables to remember elements user works with last
static uint8_t webNode = 0, webContact = 0, webKey = 0, webZone = 0,
webGroup = 0, webTimer = 0, webScript = DUMMY_NO_VALUE, webTrigger = 0;
static char scriptName[NAME_LENGTH];
static uint16_t webLog = 0;
/*
* LWIP custom file init.
*/
void genfiles_ex_init(void) {
/* nothing to do here yet */
}
/*
* LWIP open custom file
*/
int fs_open_custom(struct fs_file *file, const char *name){
char temp[3] = "";
uint16_t logAddress;
uint8_t number;
time_t tempTime; // Temp time
for (uint8_t htmlPage = 0; htmlPage < ARRAY_SIZE(webPage); ++htmlPage) {
if (!strcmp(name, webPage[htmlPage].link)) {
/* initialize fs_file correctly */
memset(file, 0, sizeof(struct fs_file));
file->pextension = mem_malloc(HTML_PAGE_SIZE);
MemoryStream ms;
BaseSequentialStream *chp;
// Memory stream object to be used as a string writer, reserving one byte for the final zero.
msObjectInit(&ms, (uint8_t *)file->pextension, HTML_PAGE_SIZE-1, 0);
// Performing the print operation using the common code.
chp = (BaseSequentialStream *)(void *)&ms;
// Common html page start
chprintf(chp, "<!DOCTYPE html><html lang='en'><head><meta charset='utf-8'><title>Open home security</title>\r\n");
chprintf(chp, "<link rel='stylesheet' href='/css/OHS.css'>\r\n");
chprintf(chp, "%sEnDis.js'>%s", html_script_src, html_e_script);
chprintf(chp, "</head>\r\n<body onload=\"");
// JavaScript enable/disable on body load
switch (htmlPage) {
case PAGE_USER:
GET_CONF_CONTACT_IS_GLOBAL(conf.contact[webContact].setting) ? chprintf(chp, JSen1) : chprintf(chp, JSdis1);
break;
case PAGE_ZONE:
GET_CONF_ZONE_TYPE(conf.zone[webZone]) ? chprintf(chp, JSen1) : chprintf(chp, JSdis1);
break;
case PAGE_TIMER:
GET_CONF_TIMER_TYPE(conf.timer[webTimer].setting) ? chprintf(chp, JSen1) : chprintf(chp, JSdis1);
break;
case PAGE_TRIGGER:
GET_CONF_TRIGGER_PASS(conf.trigger[webTrigger].setting) ? chprintf(chp, JSen1) : chprintf(chp, JSdis1);
GET_CONF_TRIGGER_PASS_OFF(conf.trigger[webTrigger].setting) ? chprintf(chp, JSen2) : chprintf(chp, JSdis2);
chprintf(chp, "sd(document.getElementById('y'));"); // Type select
break;
case PAGE_TCL:
case PAGE_LOGIN:
chprintf(chp, "ca();"); // Close alerts
break;
}
chprintf(chp, "\"><div class='wrp'><div class='sb'>\r\n");
chprintf(chp, "<div class='tt'>OHS %u.%u.%u</div>\r\n", OHS_MAJOR, OHS_MINOR, OHS_MOD);
// Navigation
chprintf(chp, "<ul class='nav'>\r\n");
// Loop through pages in given order, except last one (login.html).
for (uint8_t i = 0; i < (ARRAY_SIZE(webPage) - 1); ++i) {
if (htmlPage == i) chprintf(chp, "<li><a class='active' href='%s'>%s</a></li>\r\n", webPage[i].link, webPage[i].name);
else chprintf(chp, "<li><a href='%s'>%s</a></li>\r\n", webPage[i].link, webPage[i].name);
}
// Main Body
chprintf(chp, "</ul></div><div class='mb'>\r\n");
// Alert div
if (strlen(httpAlertMsg)) {
chprintf(chp, "<div class='alrt' id='at'><span class='cbtn' onclick=\"this.parentElement.style.display='none';\">×</span>");
chprintf(chp, "<b>Error!</b><br><br>");
chprintf(chp, "%s.%s", httpAlertMsg, html_div_e);
memset(httpAlertMsg, 0 , HTTP_ALERT_MSG_SIZE); // Empty alert message
}
// Header
chprintf(chp, "<h1>%s</h1>\r\n", webPage[htmlPage].name);
chprintf(chp, "%s%s%s%s", html_form_1, webPage[htmlPage].link, html_form_2, html_table);
// Common html page end
// Custom html page start
switch (htmlPage) {
case PAGE_NODE:
chprintf(chp, "%s#", html_tr_th);
chprintf(chp, "%s%s", html_e_th_th, text_Address);
chprintf(chp, "%s%s", html_e_th_th, text_On);
chprintf(chp, "%s%s", html_e_th_th, text_MQTT);
chprintf(chp, "%s%s %s", html_e_th_th, text_Last, text_message);
chprintf(chp, "%s%s", html_e_th_th, text_Queued);
chprintf(chp, "%s%s", html_e_th_th, text_Type);
chprintf(chp, "%s%s", html_e_th_th, text_Function);
chprintf(chp, "%s%s", html_e_th_th, text_Value);
chprintf(chp, "%s%s%s\r\n", html_e_th_th, text_Group, html_e_th_e_tr);
// Information table
for (uint8_t i = 0; i < NODE_SIZE; i++) {
if (node[i].address != 0) {
chprintf(chp, "%s%u.%s", html_tr_td, i + 1, html_e_td_td);
printNodeAddress(chp, node[i].address, node[i].type, node[i].function, node[i].number, true);
chprintf(chp, "%s", html_e_td_td);
printOkNok(chp, GET_NODE_ENABLED(node[i].setting));
chprintf(chp, "%s", html_e_td_td);
printOkNok(chp, GET_NODE_MQTT(node[i].setting));
chprintf(chp, "%s", html_e_td_td);
printFrmTimestamp(chp, &node[i].lastOK);
chprintf(chp, "%s", html_e_td_td);
if (node[i].queue) number = 1;
else number = 0;
printOkNok(chp, number); // queued
chprintf(chp, "%s", html_e_td_td);
printNodeType(chp, node[i].type);
chprintf(chp, "%s", html_e_td_td);
printNodeFunction(chp, node[i].function);
chprintf(chp, "%s", html_e_td_td);
printNodeValue(chp, i);
chprintf(chp, "%s", html_e_td_td);
printGroup(chp, GET_NODE_GROUP(node[i].setting));
chprintf(chp, "%s", html_e_td_e_tr);
}
}
chprintf(chp, "%s", html_e_table);
chprintf(chp, "%s", html_table);
chprintf(chp, "%s%s%s", html_tr_td, text_Node, html_e_td_td);
chprintf(chp, "%sP%s", html_select_submit, html_e_tag);
for (uint8_t i = 0; i < NODE_SIZE; i++) {
if (node[i].address != 0) {
chprintf(chp, "%s%u", html_option, i);
if (webNode == i) { chprintf(chp, "%s", html_selected); }
else { chprintf(chp, "%s", html_e_tag); }
chprintf(chp, "%u. %s%s", i + 1, node[i].name, html_e_option);
}
}
chprintf(chp, "%s%s", html_e_select, html_e_td_e_tr_tr_td);
chprintf(chp, "%s%s", text_Name, html_e_td_td);
printTextInput(chp, 'n', node[webNode].name, NAME_LENGTH);
chprintf(chp, "%s%s%s", html_e_td_e_tr_tr_td, text_Address, html_e_td_td);
printNodeAddress(chp, node[webNode].address, node[webNode].type, node[webNode].function, node[webNode].number, true);
chprintf(chp, "%s%s%s", html_e_td_e_tr_tr_td, text_Type, html_e_td_td);
printNodeType(chp, node[webNode].type);
chprintf(chp, "%s%s%s", html_e_td_e_tr_tr_td, text_Function, html_e_td_td);
printNodeFunction(chp, node[webNode].function);
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_Node, text_is, html_e_td_td);
printOnOffButton(chp, "0", GET_NODE_ENABLED(node[webNode].setting));
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_MQTT, text_publish, html_e_td_td);
printOnOffButton(chp, "7", GET_NODE_MQTT(node[webNode].setting));
chprintf(chp, "%s%s%s", html_e_td_e_tr_tr_td, text_Group, html_e_td_td);
selectGroup(chp, GET_NODE_GROUP(node[webNode].setting), 'g');
chprintf(chp, "%s%s", html_e_td_e_tr, html_e_table);
// Buttons
chprintf(chp, "%s%s", html_Apply, html_Reregister);
break;
case PAGE_USER:
chprintf(chp, "%s#", html_tr_th);
chprintf(chp, "%s%s", html_e_th_th, text_Name);
chprintf(chp, "%s%s", html_e_th_th, text_On);
chprintf(chp, "%s%s", html_e_th_th, text_Number);
chprintf(chp, "%s%s", html_e_th_th, text_Email);
chprintf(chp, "%s%s", html_e_th_th, text_Global);
chprintf(chp, "%s%s(s)", html_e_th_th, text_Key);
chprintf(chp, "%s%s%s\r\n", html_e_th_th, text_Group, html_e_th_e_tr);
// Information table
for (uint8_t i = 0; i < CONTACTS_SIZE; i++) {
chprintf(chp, "%s%u.%s", html_tr_td, i + 1, html_e_td_td);
chprintf(chp, "%s%s", conf.contact[i].name, html_e_td_td);
printOkNok(chp, GET_CONF_CONTACT_ENABLED(conf.contact[i].setting));
chprintf(chp, "%s%s", html_e_td_td, conf.contact[i].phone);
chprintf(chp, "%s%s", html_e_td_td, conf.contact[i].email);
chprintf(chp, "%s", html_e_td_td);
printOkNok(chp, GET_CONF_CONTACT_IS_GLOBAL(conf.contact[i].setting));
chprintf(chp, "%s", html_e_td_td);
logAddress = 0; // Just temp. var.
for (uint8_t j = 0; j < KEYS_SIZE; j++) {
if (conf.key[j].contact == i) {
logAddress++;
}
}
chprintf(chp, "%u%s", logAddress, html_e_td_td);
if (!GET_CONF_CONTACT_IS_GLOBAL(conf.contact[i].setting))
printGroup(chp, GET_CONF_CONTACT_GROUP(conf.contact[i].setting));
else chprintf(chp, "%s", text_all);
chprintf(chp, "%s", html_e_td_e_tr);
}
chprintf(chp, "%s", html_e_table);
chprintf(chp, "%s", html_table);
chprintf(chp, "%s%s%s", html_tr_td, text_User, html_e_td_td);
chprintf(chp, "%sP%s", html_select_submit, html_e_tag);
for (uint8_t i = 0; i < CONTACTS_SIZE; i++) {
chprintf(chp, "%s%u", html_option, i);
if (webContact == i) { chprintf(chp, "%s", html_selected); }
else { chprintf(chp, "%s", html_e_tag); }
chprintf(chp, "%u. %s%s", i + 1, conf.contact[i].name, html_e_option);
}
chprintf(chp, "%s%s", html_e_select, html_e_td_e_tr_tr_td);
chprintf(chp, "%s%s", text_Name, html_e_td_td);
printTextInput(chp, 'n', conf.contact[webContact].name, NAME_LENGTH);
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_User, text_is, html_e_td_td);
printOnOffButton(chp, "0", GET_CONF_CONTACT_ENABLED(conf.contact[webContact].setting));
chprintf(chp, "%s%s%s", html_e_td_e_tr_tr_td, text_Number, html_e_td_td);
printTextInput(chp, 'p', conf.contact[webContact].phone, PHONE_LENGTH);
chprintf(chp, "%s%s%s", html_e_td_e_tr_tr_td, text_Email, html_e_td_td);
printTextInput(chp, 'm', conf.contact[webContact].email, EMAIL_LENGTH);
chprintf(chp, "%s%s%s", html_e_td_e_tr_tr_td, text_Global, html_e_td_td);
printOnOffButtonWJS(chp, "5", GET_CONF_CONTACT_IS_GLOBAL(conf.contact[webContact].setting), 1, 0b10);
chprintf(chp, "%s%s%s", html_e_td_e_tr_tr_td, text_Group, html_e_td_td);
selectGroup(chp, GET_CONF_CONTACT_GROUP(conf.contact[webContact].setting), 'g');
chprintf(chp, "%s%s", html_e_td_e_tr, html_e_table);
// JavaScript
chprintf(chp, "%s%s%s", html_script, JSContact, html_e_script);
// Buttons
chprintf(chp, "%s%s", html_Apply, html_Save);
break;
case PAGE_KEY:
chprintf(chp, "%s#", html_tr_th);
chprintf(chp, "%s%s", html_e_th_th, text_User);
chprintf(chp, "%s%s", html_e_th_th, text_On);
chprintf(chp, "%s%s%s\r\n", html_e_th_th, text_Hash, html_e_th_e_tr);
// Information table
for (uint8_t i = 0; i < KEYS_SIZE; i++) {
chprintf(chp, "%s%u.%s", html_tr_td, i + 1, html_e_td_td);
if (conf.key[i].contact == DUMMY_NO_VALUE) chprintf(chp, "%s", NOT_SET);
else chprintf(chp, "%s", conf.contact[conf.key[i].contact].name);
chprintf(chp, "%s", html_e_td_td);
printOkNok(chp, GET_CONF_KEY_ENABLED(conf.key[i].setting));
chprintf(chp, "%s", html_e_td_td);
uint32Conv.val = conf.key[i].value;
printKey(chp, (uint8_t *)&uint32Conv.byte[0]);
chprintf(chp, "%s", html_e_td_e_tr);
}
chprintf(chp, "%s", html_e_table);
chprintf(chp, "%s", html_table);
chprintf(chp, "%s%s%s", html_tr_td, text_Key, html_e_td_td);
chprintf(chp, "%sP%s", html_select_submit, html_e_tag);
for (uint8_t i = 0; i < KEYS_SIZE; i++) {
chprintf(chp, "%s%u", html_option, i);
if (webKey == i) { chprintf(chp, "%s", html_selected); }
else { chprintf(chp, "%s", html_e_tag); }
chprintf(chp, "%u.%s", i + 1, html_e_option);
}
chprintf(chp, "%s%s", html_e_select, html_e_td_e_tr_tr_td);
chprintf(chp, "%s%s", text_User, html_e_td_td);
chprintf(chp, "%sc%s", html_select, html_e_tag);
for (uint8_t i = 0; i <= CONTACTS_SIZE; i++) {
if (i < CONTACTS_SIZE) {
chprintf(chp, "%s%u", html_option, i);
if (conf.key[webKey].contact == i) { chprintf(chp, "%s", html_selected); }
else { chprintf(chp, "%s", html_e_tag); }
chprintf(chp, "%u. %s%s", i + 1, conf.contact[i].name, html_e_option);
} else {
chprintf(chp, "%s%u", html_option, DUMMY_NO_VALUE);
if (conf.key[webKey].contact == DUMMY_NO_VALUE) { chprintf(chp, "%s", html_selected); }
else { chprintf(chp, "%s", html_e_tag); }
chprintf(chp, "%s%s", NOT_SET, html_e_option);
}
}
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_Key, text_is, html_e_td_td);
printOnOffButton(chp, "0", GET_CONF_KEY_ENABLED(conf.key[webKey].setting));
chprintf(chp, "%s%s%s", html_e_td_e_tr_tr_td, text_Hash, html_e_td_td);
chprintf(chp, "%s%u%s%u", html_t_tag_1, KEY_LENGTH * 2, html_s_tag_2, KEY_LENGTH * 2);
chprintf(chp, "%sk%s", html_s_tag_3, html_m_tag);
uint32Conv.val = conf.key[webKey].value;
printKey(chp, (uint8_t *)&uint32Conv.byte[0]);
chprintf(chp, "%s%k%s", html_id_tag, html_e_tag);
chprintf(chp, "%s%s", html_e_td_e_tr, html_e_table);
// Buttons
chprintf(chp, "%s%s", html_Apply, html_Save);
break;
case PAGE_ZONE:
chprintf(chp, "%s#", html_tr_th);
chprintf(chp, "%s%s", html_e_th_th, text_Name);
chprintf(chp, "%s%s", html_e_th_th, text_On);
chprintf(chp, "%s%s", html_e_th_th, text_Type);
chprintf(chp, "%s%s %s", html_e_th_th, text_Arm, text_home);
chprintf(chp, "%s%s %s", html_e_th_th, text_Open, text_alarm);
chprintf(chp, "%s%s %s %s", html_e_th_th, text_Alarm, text_as, text_tamper);
chprintf(chp, "%s%s", html_e_th_th, text_Delay);
chprintf(chp, "%s%s %s", html_e_th_th, text_Last, text_alarm);
chprintf(chp, "%s%s %s", html_e_th_th, text_Last, text_OK);
chprintf(chp, "%s%s", html_e_th_th, text_MQTT);
chprintf(chp, "%s%s", html_e_th_th, text_HAD);
chprintf(chp, "%s%s", html_e_th_th, text_Status);
chprintf(chp, "%s%s%s\r\n", html_e_th_th, text_Group, html_e_th_e_tr);
// Information table
for (uint8_t i = 0; i < ALARM_ZONES; i++) {
if (GET_CONF_ZONE_IS_PRESENT(conf.zone[i])) {
chprintf(chp, "%s%u.%s", html_tr_td, i + 1, html_e_td_td);
chprintf(chp, "%s%s", conf.zoneName[i], html_e_td_td);
printOkNok(chp, GET_CONF_ZONE_ENABLED(conf.zone[i]));
chprintf(chp, "%s", html_e_td_td);
if (GET_CONF_ZONE_ENABLED(conf.zone[i])) {
GET_CONF_ZONE_BALANCED(conf.zone[i]) ? chprintf(chp, "%s ", text_balanced) : chprintf(chp, "un%s ", text_balanced);
(i >= HW_ZONES) ? chprintf(chp, "%s ", text_remote) : chprintf(chp, "%s ", text_local);
GET_CONF_ZONE_TYPE(conf.zone[i]) ? chprintf(chp, "%s", text_analog) : chprintf(chp, "%s", text_digital);
}
chprintf(chp, "%s", html_e_td_td);
printOkNok(chp, GET_CONF_ZONE_ARM_HOME(conf.zone[i]));
chprintf(chp, "%s", html_e_td_td);
printOkNok(chp, GET_CONF_ZONE_OPEN_ALARM(conf.zone[i]));
chprintf(chp, "%s", html_e_td_td);
printOkNok(chp, GET_CONF_ZONE_PIR_AS_TMP(conf.zone[i]));
chprintf(chp, "%s", html_e_td_td);
chprintf(chp, "%u %s%s", GET_CONF_ZONE_AUTH_TIME(conf.zone[i])*conf.armDelay/4,
durationSelect[0], html_e_td_td);
if (GET_CONF_ZONE_ENABLED(conf.zone[i])) printFrmTimestamp(chp, &zone[i].lastPIR);
chprintf(chp, "%s", html_e_td_td);
if (GET_CONF_ZONE_ENABLED(conf.zone[i])) printFrmTimestamp(chp, &zone[i].lastOK);
chprintf(chp, "%s", html_e_td_td);
if (GET_CONF_ZONE_ENABLED(conf.zone[i])) printOkNok(chp, GET_CONF_ZONE_MQTT_PUB(conf.zone[i]));
chprintf(chp, "%s", html_e_td_td);
if (GET_CONF_ZONE_ENABLED(conf.zone[i])) printOkNok(chp, GET_CONF_ZONE_MQTT_HAD(conf.zone[i]));
chprintf(chp, "%s", html_e_td_td);
if (GET_CONF_ZONE_ENABLED(conf.zone[i])) {
switch(zone[i].lastEvent){
case 'O': chprintf(chp, "%s", html_i_OK); break;
case 'P': chprintf(chp, "%s", html_i_alarm); break;
case 'N': chprintf(chp, "%s", html_i_starting); break;
default: chprintf(chp, "%s", text_tamper); break;
}
} else { chprintf(chp, "%s", html_i_disabled); }
chprintf(chp, "%s", html_e_td_td);
printGroup(chp, GET_CONF_ZONE_GROUP(conf.zone[i]));
chprintf(chp, "%s", html_e_td_e_tr);
}
}
chprintf(chp, "%s", html_e_table);
chprintf(chp, "%s", html_table);
chprintf(chp, "%s%s%s", html_tr_td, text_Zone, html_e_td_td);
chprintf(chp, "%sP%s", html_select_submit, html_e_tag);
for (uint8_t i = 0; i < ALARM_ZONES; i++) {
if (GET_CONF_ZONE_IS_PRESENT(conf.zone[i])) {
chprintf(chp, "%s%u", html_option, i);
if (webZone == i) { chprintf(chp, "%s", html_selected); }
else { chprintf(chp, "%s", html_e_tag); }
chprintf(chp, "%u. %s%s", i + 1, conf.zoneName[i], html_e_option);
}
}
chprintf(chp, "%s%s", html_e_select, html_e_td_e_tr_tr_td);
chprintf(chp, "%s%s", text_Name, html_e_td_td);
printTextInput(chp, 'n', conf.zoneName[webZone], NAME_LENGTH);
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_Zone, text_is, html_e_td_td);
printOnOffButton(chp, "0", GET_CONF_ZONE_ENABLED(conf.zone[webZone]));
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_Arm, text_home, html_e_td_td);
printOnOffButton(chp, "7", GET_CONF_ZONE_ARM_HOME(conf.zone[webZone]));
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_Open, text_alarm, html_e_td_td);
printOnOffButton(chp, "8", GET_CONF_ZONE_OPEN_ALARM(conf.zone[webZone]));
chprintf(chp, "%s%s %s %s%s", html_e_td_e_tr_tr_td, text_Alarm, text_as, text_tamper, html_e_td_td);
printOnOffButton(chp, "9", GET_CONF_ZONE_PIR_AS_TMP(conf.zone[webZone]));
chprintf(chp, "%s%s%s", html_e_td_e_tr_tr_td, text_Balanced, html_e_td_td);
printOnOffButton(chp, "a", GET_CONF_ZONE_BALANCED(conf.zone[webZone]));
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_Authentication, text_delay, html_e_td_td);
printFourButton(chp, "D", GET_CONF_ZONE_AUTH_TIME(conf.zone[webZone]), 0, 0b0000,
text_0x, text_1x, text_2x, text_3x, 0);
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_MQTT, text_publish, html_e_td_td);
printOnOffButton(chp, "d", GET_CONF_ZONE_MQTT_PUB(conf.zone[webZone]));
chprintf(chp, "%s%s %s %s%s", html_e_td_e_tr_tr_td, text_MQTT, text_HA, text_Discovery, html_e_td_td);
printOnOffButton(chp, "c", GET_CONF_ZONE_MQTT_HAD(conf.zone[webZone]));
chprintf(chp, "%s%s%s", html_e_td_e_tr_tr_td, text_Group, html_e_td_td);
selectGroup(chp, GET_CONF_ZONE_GROUP(conf.zone[webZone]), 'g');
chprintf(chp, "%s%s", html_e_td_e_tr, html_e_table);
// JavaScript
chprintf(chp, "%s%s%s", html_script, JSZone, html_e_script);
// Buttons
chprintf(chp, "%s%s", html_Apply, html_Save);
break;
case PAGE_ALERT:
chprintf(chp, "%s%s", html_tr_th, text_Name);
for (uint8_t j = 0; j < ARRAY_SIZE(alertType); j++) {
chprintf(chp, "%s%s", html_e_th_th, alertType[j].name);
}
chprintf(chp, "%s\r\n", html_e_th_e_tr);
// Information table
for (uint8_t i = 0; i < ARRAY_SIZE(alertDef); i++) {
chprintf(chp, "%s", html_tr_td);
decodeLog((char*)alertDef[i], logText, 0);
chprintf(chp, "%s%s", logText, html_e_td_td);
for (uint8_t j = 0; j < ARRAY_SIZE(alertType); j++) {
temp[0] = '0' + j;
temp[1] = 'A' + i;
printOnOffButton(chp, temp, (conf.alert[j] >> i) & 0b1);
if (j < (ARRAY_SIZE(alertType) - 1)) chprintf(chp, "%s", html_e_td_td);
}
}
chprintf(chp, "%s%s", html_e_td_e_tr, html_e_table);
// Buttons
chprintf(chp, "%s%s%s", html_Apply, html_Save, html_SendDummy);
break;
case PAGE_LOG:
chprintf(chp, "%s#", html_tr_th);
chprintf(chp, "%s%s", html_e_th_th, text_Date);
chprintf(chp, "%s%s", html_e_th_th, text_Entry);
chprintf(chp, "%s%s%s\r\n", html_e_th_th, text_Alert, html_e_th_e_tr);
// Information table
spiAcquireBus(&SPID1); // Acquire ownership of the bus.
for (uint8_t i = 0; i < LOGGER_OUTPUT_LEN; i++) {
logAddress = webLog + (i * FRAM_MSG_SIZE);
chprintf(chp, "%s%u.%s", html_tr_td, (logAddress / FRAM_MSG_SIZE) + 1 , html_e_td_td);
getLogEntry(logAddress);
memcpy(&timeConv.ch[0], &rxBuffer[0], sizeof(timeConv.ch)); // Prepare timestamp
decodeLog(&rxBuffer[4], logText, 1);
printFrmTimestamp(chp, &timeConv.val);
chprintf(chp, "%s%s.", html_e_td_td, logText);
chprintf(chp, "%s", html_e_td_td);
for (uint8_t j = 0; j < ARRAY_SIZE(alertType); j++) {
if ((((uint8_t)rxBuffer[FRAM_MSG_SIZE-1] >> j) & 0b1) == 1)
chprintf(chp, "%s ", alertType[j].name);
}
}
spiReleaseBus(&SPID1); // Ownership release.
chprintf(chp, "%s%s", html_e_td_e_tr, html_e_table);
// Buttons
chprintf(chp, "%s%s%s", html_FR, html_Now, html_FF);
break;
case PAGE_GROUP:
chprintf(chp, "%s#", html_tr_th);
chprintf(chp, "%s%s", html_e_th_th, text_Name);
chprintf(chp, "%s%s", html_e_th_th, text_On);
chprintf(chp, "%s%s %s", html_e_th_th, text_Auto, text_arm);
chprintf(chp, "%s%s %s", html_e_th_th, text_Arm, text_chain);
chprintf(chp, "%s%s %s", html_e_th_th, text_Disarm, text_chain);
chprintf(chp, "%s%ss", html_e_th_th, text_Zone);
chprintf(chp, "%s%ss", html_e_th_th, text_Authentication);
chprintf(chp, "%s%ss", html_e_th_th, text_Sensor);
chprintf(chp, "%s%ss", html_e_th_th, text_Contact);
chprintf(chp, "%s%s", html_e_th_th, text_Siren);
chprintf(chp, "%s%s", html_e_th_th, text_MQTT);
chprintf(chp, "%s%s", html_e_th_th, text_HAD);
chprintf(chp, "%s%s", html_e_th_th, text_Armed);
chprintf(chp, "%s%s%s\r\n", html_e_th_th, text_Status, html_e_th_e_tr);
// Information table
for (uint8_t i = 0; i < ALARM_GROUPS; i++) {
chprintf(chp, "%s%u.%s", html_tr_td, i + 1, html_e_td_td);
chprintf(chp, "%s%s", conf.group[i].name, html_e_td_td);
printOkNok(chp, GET_CONF_GROUP_ENABLED(conf.group[i].setting));
chprintf(chp, "%s", html_e_td_td);
if (GET_CONF_GROUP_ENABLED(conf.group[i].setting))
printOkNok(chp, GET_CONF_GROUP_AUTO_ARM(conf.group[i].setting));
chprintf(chp, "%s", html_e_td_td);
if (GET_CONF_GROUP_ENABLED(conf.group[i].setting))
printGroup(chp, GET_CONF_GROUP_ARM_CHAIN(conf.group[i].setting));
chprintf(chp, "%s", html_e_td_td);
if (GET_CONF_GROUP_ENABLED(conf.group[i].setting))
printGroup(chp, GET_CONF_GROUP_DISARM_CHAIN(conf.group[i].setting));
chprintf(chp, "%s", html_e_td_td);
if (GET_CONF_GROUP_ENABLED(conf.group[i].setting)) {
logAddress = 0; // Just temp. var.
for (uint8_t j = 0; j < ALARM_ZONES; j++) {
if ((GET_CONF_ZONE_ENABLED(conf.zone[j])) &&
(GET_CONF_ZONE_IS_PRESENT(conf.zone[j])) &&
(GET_CONF_ZONE_GROUP(conf.zone[j]) == i)) {
if (logAddress > 0) chprintf(chp, "%s", html_br);
chprintf(chp, "%u. %s", j+1, conf.zoneName[j]);
logAddress++;
}
}
}
chprintf(chp, "%s", html_e_td_td);
if (GET_CONF_GROUP_ENABLED(conf.group[i].setting)) {
logAddress = 0; // Just temp. var.
for (uint8_t j = 0; j < NODE_SIZE; j++) {
if (GET_NODE_ENABLED(node[j].setting) &&
(GET_NODE_GROUP(node[j].setting) == i) &&
(node[j].type == 'K')) {
if (logAddress > 0) chprintf(chp, "%s", html_br);
chprintf(chp, "%u. %s", j+1, node[j].name);
logAddress++;
}
}
}
chprintf(chp, "%s", html_e_td_td);
if (GET_CONF_GROUP_ENABLED(conf.group[i].setting)) {
logAddress = 0; // Just temp. var.
for (uint8_t j = 0; j < NODE_SIZE; j++) {
if (GET_NODE_ENABLED(node[j].setting) &&
(GET_NODE_GROUP(node[j].setting) == i) &&
(node[j].type == 'S')) {
if (logAddress > 0) chprintf(chp, "%s", html_br);
chprintf(chp, "%u. %s", j+1, node[j].name);
logAddress++;
}
}
}
chprintf(chp, "%s", html_e_td_td);
if (GET_CONF_GROUP_ENABLED(conf.group[i].setting)) {
logAddress = 0; // Just temp. var.
for (uint8_t j = 0; j < CONTACTS_SIZE; j++) {
if (GET_CONF_CONTACT_ENABLED(conf.contact[j].setting) &&
((GET_CONF_CONTACT_GROUP(conf.contact[j].setting) == i) ||
(GET_CONF_CONTACT_IS_GLOBAL(conf.contact[j].setting)))){
if (logAddress > 0) chprintf(chp, "%s", html_br);
chprintf(chp, "%s", conf.contact[j].name);
logAddress++;
}
}
}
chprintf(chp, "%s", html_e_td_td); // show relays
if (GET_CONF_GROUP_ENABLED(conf.group[i].setting)) {
chprintf(chp, "%s:", text_Alarm);
if (GET_CONF_GROUP_PIR1(conf.group[i].setting)) chprintf(chp, " %s 1", text_relay);
if (GET_CONF_GROUP_PIR2(conf.group[i].setting)) chprintf(chp, " %s 2", text_relay);
chprintf(chp, "%s%s:", html_br, text_Tamper);
if (GET_CONF_GROUP_TAMPER1(conf.group[i].setting)) chprintf(chp, " %s 1", text_relay);
if (GET_CONF_GROUP_TAMPER2(conf.group[i].setting)) chprintf(chp, " %s 2", text_relay);
// Remote Siren/Horn
for (uint8_t j=0; j < NODE_SIZE; j++) {
if ((node[j].type == 'H') && (GET_NODE_GROUP(node[j].setting) == i)){
chprintf(chp, "%s", html_br);
printNodeAddress(chp, node[j].address, node[j].type, node[j].function, node[j].number, 1);
}
}
}
chprintf(chp, "%s", html_e_td_td);
if (GET_CONF_GROUP_ENABLED(conf.group[i].setting))
printOkNok(chp, GET_CONF_GROUP_MQTT(conf.group[i].setting));
chprintf(chp, "%s", html_e_td_td);
if (GET_CONF_GROUP_ENABLED(conf.group[i].setting))
printOkNok(chp, GET_CONF_GROUP_MQTT_HAD(conf.group[i].setting));
chprintf(chp, "%s", html_e_td_td);
if (GET_CONF_GROUP_ENABLED(conf.group[i].setting)) {
if (GET_GROUP_ARMED(group[i].setting)) {
if GET_GROUP_ARMED_HOME(group[i].setting) { chprintf(chp, "%s", html_i_home); }
else { chprintf(chp, "%s", html_i_OK); }
} else {
if (group[i].armDelay > 0) { chprintf(chp, "%s", html_i_starting); }
else { chprintf(chp, "%s", html_i_disabled); }
}
}
chprintf(chp, "%s", html_e_td_td);
if (GET_CONF_GROUP_ENABLED(conf.group[i].setting)) {
if (GET_GROUP_ALARM(group[i].setting) == 0) {
if (GET_GROUP_WAIT_AUTH(group[i].setting)) { chprintf(chp, "%s", html_i_starting); }
else { chprintf(chp, "%s", html_i_OK); }
} else { chprintf(chp, "%s", html_i_alarm); }
}
chprintf(chp, "%s", html_e_td_e_tr);
} // end for ...
chprintf(chp, "%s%s", html_e_table, html_table);
chprintf(chp, "%s%s%s", html_tr_td, text_Group, html_e_td_td);
chprintf(chp, "%sP%s", html_select_submit, html_e_tag);
for (uint8_t i = 0; i < ALARM_GROUPS; i++) {
chprintf(chp, "%s%u", html_option, i);
if (webGroup == i) { chprintf(chp, "%s", html_selected); }
else { chprintf(chp, "%s", html_e_tag); }
chprintf(chp, "%u. %s%s", i + 1, conf.group[i].name, html_e_option);
}
chprintf(chp, "%s%s", html_e_select, html_e_td_e_tr_tr_td);
chprintf(chp, "%s%s", text_Name, html_e_td_td);
printTextInput(chp, 'n', conf.group[webGroup].name, NAME_LENGTH);
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_Group, text_is, html_e_td_td);
printOnOffButton(chp, "0", GET_CONF_GROUP_ENABLED(conf.group[webGroup].setting));
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_Auto, text_arm, html_e_td_td);
printOnOffButton(chp, "5", GET_CONF_GROUP_AUTO_ARM(conf.group[webGroup].setting));
chprintf(chp, "%s%s %ss %s 1%s", html_e_td_e_tr_tr_td, text_Alarm, text_trigger, text_relay, html_e_td_td);
printOnOffButton(chp, "4", GET_CONF_GROUP_PIR1(conf.group[webGroup].setting));
chprintf(chp, "%s%s %ss %s 2%s", html_e_td_e_tr_tr_td, text_Alarm, text_trigger, text_relay, html_e_td_td);
printOnOffButton(chp, "3", GET_CONF_GROUP_PIR2(conf.group[webGroup].setting));
chprintf(chp, "%s%s %ss %s 1%s", html_e_td_e_tr_tr_td, text_Tamper, text_trigger, text_relay, html_e_td_td);
printOnOffButton(chp, "2", GET_CONF_GROUP_TAMPER1(conf.group[webGroup].setting));
chprintf(chp, "%s%s %ss %s 2%s", html_e_td_e_tr_tr_td, text_Tamper, text_trigger, text_relay, html_e_td_td);
printOnOffButton(chp, "1", GET_CONF_GROUP_TAMPER2(conf.group[webGroup].setting));
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_MQTT, text_publish, html_e_td_td);
printOnOffButton(chp, "7", GET_CONF_GROUP_MQTT(conf.group[webGroup].setting));
chprintf(chp, "%s%s %s %s%s", html_e_td_e_tr_tr_td, text_MQTT, text_HA, text_Discovery, html_e_td_td);
printOnOffButton(chp, "6", GET_CONF_GROUP_MQTT_HAD(conf.group[webGroup].setting));
chprintf(chp, "%s%s %s %s%s", html_e_td_e_tr_tr_td, text_Arm, text_group, text_chain, html_e_td_td);
selectGroup(chp, GET_CONF_GROUP_ARM_CHAIN(conf.group[webGroup].setting), 'a');
chprintf(chp, "%s%s %s %s%s", html_e_td_e_tr_tr_td, text_Disarm, text_group, text_chain, html_e_td_td);
selectGroup(chp, GET_CONF_GROUP_DISARM_CHAIN(conf.group[webGroup].setting), 'd');
chprintf(chp, "%s%s", html_e_td_e_tr, html_e_table);
// Buttons
chprintf(chp, "%s%s%s", html_Apply, html_Save, html_Disarm);
break;
case PAGE_HOME:
// Information table
chprintf(chp, "%s%s%s", html_tr_td, text_Time, html_e_td_td);
tempTime = getTimeUnixSec(); printFrmTimestamp(chp, &tempTime);
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_Start, text_time, html_e_td_td);
printFrmTimestamp(chp, &startTime);
chprintf(chp, "%s%s%s%s", html_e_td_e_tr_tr_td, text_Up, text_time, html_e_td_td);
tempTime -= startTime; printFrmUpTime(chp, &tempTime);
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_AC, text_power, html_e_td_td);
printOkNok(chp, !(palReadPad(GPIOD, GPIOD_AC_OFF)));
chprintf(chp, "%s%s%s", html_e_td_e_tr_tr_td, text_Battery, html_e_td_td);
printOkNok(chp, palReadPad(GPIOD, GPIOD_BAT_OK));
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_RTC, text_battery, html_e_td_td);
printOkNok(chp, ((rtcVbat > ADC_VBAT_HIGH_VOLTAGE)?1:0));
chprintf(chp, " (%.2f V)", rtcVbat);
chprintf(chp, "%s%s", html_e_td_e_tr, html_e_table);
chprintf(chp, "<h1>%s</h1>\r\n", text_Modem);
chprintf(chp, "%s%s", html_table, html_tr_td);
chprintf(chp, "%s%s%s", text_Type, html_e_td_td, gprsModemInfo);
chprintf(chp, "%s%s%s", html_e_td_e_tr_tr_td, text_On, html_e_td_td);
printOkNok(chp, !palReadPad(GPIOD, GPIOD_GSM_STATUS));
chprintf(chp, "%s%s%s", html_e_td_e_tr_tr_td, text_Alive, html_e_td_td);
printOkNok(chp, gprsIsAlive);
chprintf(chp, "%s%sed%s", html_e_td_e_tr_tr_td, text_Register, html_e_td_td);
switch(gprsReg){
case 0 : chprintf(chp, "%s", html_i_OK); break;
case 1 : chprintf(chp, "%s", html_i_home); break;
case 2 : chprintf(chp, "%s", html_i_starting); break;
case 3 : chprintf(chp, "%s", html_i_disabled); break;
case 5 : chprintf(chp, "%s", html_i_globe); break;
default : chprintf(chp, "%s", html_i_question);; break; // case 4
}
chprintf(chp, "%s%s %s%s%u%%", html_e_td_e_tr_tr_td, text_Signal, text_strength, html_e_td_td, gprsStrength);
// +CPSI: GSM,Online,230-02,0x0726,4285,69 // remove +CPSI: &[7]
chprintf(chp, "%s%s %s%s%s%", html_e_td_e_tr_tr_td, text_System, text_info, html_e_td_td, &gprsSystemInfo[7]);
chprintf(chp, "%s%s", html_e_td_e_tr, html_e_table);
// Buttons
chprintf(chp, "%s%s", html_LoadDefault, html_Save);
// TODO OHS add configuration download/upload
//chprintf(chp, "<a href='config.bin' download>");
break;
case PAGE_SETTING:
// Information table
chprintf(chp, "%s%s / %s %s%s", html_tr_td, text_Arm, text_Authentication, text_time,
html_e_td_td);
printIntInput(chp, 'C', conf.armDelay / 4, 3, 5, 60);
chprintf(chp, " %s%s%s %s %s %s%s", durationSelect[0], html_e_td_e_tr_tr_td, text_Auto,
text_arm, text_zone, text_delay, html_e_td_td);
printIntInput(chp, 'E', conf.autoArm, 3, 1, 240);
chprintf(chp, " %s%s%s %s %s %s%s", durationSelect[1], html_e_td_e_tr_tr_td, text_Zone,
text_open, text_alarm, text_delay, html_e_td_td);
printIntInput(chp, 'F', conf.openAlarm, 3, 1, 240);
chprintf(chp, " %s%s%s %s%s", durationSelect[1], html_e_td_e_tr_tr_td, text_Admin,
text_user, html_e_td_td);
printTextInputWMin(chp, 'u', conf.user, NAME_LENGTH, MIN_PASS_LNEGTH);
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_Admin, text_password,
html_e_td_td);
printPassInput(chp, 'p', conf.password, NAME_LENGTH, MIN_PASS_LNEGTH); chprintf(chp, "%s", html_br);
printPassInput(chp, 'P', conf.password, NAME_LENGTH, MIN_PASS_LNEGTH);
chprintf(chp, "%s%s", html_e_td_e_tr, html_e_table);
chprintf(chp, "<h1>%s</h1>\r\n%s", text_Radio, html_table);
chprintf(chp, "%s%s%s", html_tr_td, text_Key, html_e_td_td);
printTextInputWMin(chp, 'K', conf.radioKey, RADIO_KEY_SIZE - 1, RADIO_KEY_SIZE - 1);
chprintf(chp, "%s%s%s", html_e_td_e_tr_tr_td, text_Frequency, html_e_td_td);
printTwoButton(chp, "i", GET_CONF_SYSTEM_FLAG_RADIO_FREQ(conf.systemFlags), 0, 0b00,
"868 Mhz", "915 Mhz");
chprintf(chp, "%s%s", html_e_td_e_tr, html_e_table);
chprintf(chp, "<h1>%s</h1>\r\n%s", text_SMTP, html_table);
chprintf(chp, "%s%s %s%s", html_tr_td, text_Server, text_address, html_e_td_td);
printTextInput(chp, 'a', conf.SMTPAddress, URL_LENGTH);
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_Server, text_port, html_e_td_td);
printIntInput(chp, 'b', conf.SMTPPort, 5, 0, 65535);
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_User, text_name, html_e_td_td);
printTextInput(chp, 'c', conf.SMTPUser, EMAIL_LENGTH);
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_User, text_password, html_e_td_td);
printPassInput(chp, 'd', conf.SMTPPassword, NAME_LENGTH, MIN_PASS_LNEGTH);
// chprintf(chp, "%s", html_br); printPassInput(chp, 'D', conf.SMTPPassword, NAME_LENGTH, MIN_PASS_LNEGTH);
chprintf(chp, "%s%s", html_e_td_e_tr, html_e_table);
chprintf(chp, "<h1>%s</h1>\r\n%s", text_MQTT, html_table);
chprintf(chp, "%s%s %s%s", html_tr_td, text_Server, text_address, html_e_td_td);
printTextInput(chp, 'y', conf.mqtt.address, URL_LENGTH);
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_Server, text_port, html_e_td_td);
printIntInput(chp, 'q', conf.mqtt.port, 5, 0, 65535);
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_User, text_name, html_e_td_td);
printTextInput(chp, 't', conf.mqtt.user, NAME_LENGTH);
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_User, text_password, html_e_td_td);
printPassInput(chp, 'r', conf.mqtt.password, NAME_LENGTH, MIN_PASS_LNEGTH);
// chprintf(chp, "%s", html_br); printPassInput(chp, 'R', conf.mqtt.password, NAME_LENGTH, MIN_PASS_LNEGTH);
chprintf(chp, "%s%s%s", html_e_td_e_tr_tr_td, text_Connected, html_e_td_td);
printOkNok(chp, !(GET_CONF_MQTT_CONNECT_ERROR(conf.mqtt.setting) | GET_CONF_MQTT_ADDRESS_ERROR(conf.mqtt.setting)));
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_Global, text_Subscribe, html_e_td_td);
printOnOffButton(chp, "0", GET_CONF_MQTT_SUBSCRIBE(conf.mqtt.setting));
chprintf(chp, "%s%s %s %s %s%s", html_e_td_e_tr_tr_td, text_Global, text_Home, text_Assistant, text_Discovery, html_e_td_td);
printOnOffButton(chp, "1", GET_CONF_MQTT_HAD(conf.mqtt.setting));
chprintf(chp, "%s%s", html_e_td_e_tr, html_e_table);
chprintf(chp, "<h1>%s</h1>\r\n%s", text_NTP, html_table);
chprintf(chp, "%s%s %s%s", html_tr_td, text_Server, text_address,
html_e_td_td);
printTextInput(chp, 'f', conf.SNTPAddress, URL_LENGTH);
chprintf(chp, "%s%s %s%s", html_tr_td, text_DS, text_start, html_e_td_td);
chprintf(chp, "%sW%s", html_select, html_e_tag);
for (uint8_t i = 0; i < ARRAY_SIZE(weekNumber); i++) {
chprintf(chp, "%s%u", html_option, i);
if (conf.timeDstWeekNum == i) { chprintf(chp, "%s", html_selected); }
else { chprintf(chp, "%s", html_e_tag); }
chprintf(chp, "%s%s", weekNumber[i], html_e_option);
}
chprintf(chp, "%s", html_e_select);
chprintf(chp, "%sS%s", html_select, html_e_tag);
for (uint8_t i = 0; i < ARRAY_SIZE(weekDay); i++) {
chprintf(chp, "%s%u", html_option, i);
if (conf.timeDstDow == i) { chprintf(chp, "%s", html_selected); }
else { chprintf(chp, "%s", html_e_tag); }
chprintf(chp, "%s%s", weekDay[i], html_e_option);
}
chprintf(chp, "%s %s ", html_e_select, text_of);
chprintf(chp, "%sM%s", html_select, html_e_tag);
for (uint8_t i = 0; i < ARRAY_SIZE(monthName); i++) {
chprintf(chp, "%s%u", html_option, i);
if (conf.timeDstMonth == i) { chprintf(chp, "%s", html_selected); }
else { chprintf(chp, "%s", html_e_tag); }
chprintf(chp, "%s%s", monthName[i], html_e_option);
}
chprintf(chp, "%s %s ", html_e_select, text_at);
printIntInput(chp, 'h', conf.timeDstHour , 2, 0, 23);
chprintf(chp, " %s", text_oclock);
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_DS, text_offset, html_e_td_td);
printIntInput(chp, 'O', conf.timeDstOffset, 5, -1440, 1440);
chprintf(chp, " %s%s", durationSelect[1], html_e_td_e_tr_tr_td);
chprintf(chp, "%s %s%s", text_DS, text_end, html_e_td_td);
chprintf(chp, "%sw%s", html_select, html_e_tag);
for (uint8_t i = 0; i < ARRAY_SIZE(weekNumber); i++) {
chprintf(chp, "%s%u", html_option, i);
if (conf.timeStdWeekNum == i) { chprintf(chp, "%s", html_selected); }
else { chprintf(chp, "%s", html_e_tag); }
chprintf(chp, "%s%s", weekNumber[i], html_e_option);
}
chprintf(chp, "%s", html_e_select);
chprintf(chp, "%ss%s", html_select, html_e_tag);
for (uint8_t i = 0; i < ARRAY_SIZE(weekDay); i++) {
chprintf(chp, "%s%u", html_option, i);
if (conf.timeStdDow == i) { chprintf(chp, "%s", html_selected); }
else { chprintf(chp, "%s", html_e_tag); }
chprintf(chp, "%s%s", weekDay[i], html_e_option);
}
chprintf(chp, "%s %s ", html_e_select, text_of);
chprintf(chp, "%sm%s", html_select, html_e_tag);
for (uint8_t i = 0; i < ARRAY_SIZE(monthName); i++) {
chprintf(chp, "%s%u", html_option, i);
if (conf.timeStdMonth == i) { chprintf(chp, "%s", html_selected); }
else { chprintf(chp, "%s", html_e_tag); }
chprintf(chp, "%s%s", monthName[i], html_e_option);
}
chprintf(chp, "%s %s ", html_e_select, text_at);
printIntInput(chp, 'h', conf.timeStdHour , 2, 0, 23);
chprintf(chp, " %s", text_oclock);
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td,
text_Standard, text_offset, html_e_td_td);
printIntInput(chp, 'o', conf.timeStdOffset, 5, -1440, 1440);
chprintf(chp, " %s%s", durationSelect[1], html_e_td_e_tr_tr_td);
chprintf(chp, "%s %s%s", text_Time, text_format, html_e_td_td);
printTextInput(chp, 'g', conf.dateTimeFormat, NAME_LENGTH);
chprintf(chp, "%s%s", html_e_td_e_tr, html_e_table);
// JavaScript
chprintf(chp, "%s%s%s", html_script, JSCredential, html_e_script);
chprintf(chp, "%sPass.js'>%s", html_script_src, html_e_script);
// Buttons
chprintf(chp, "%s%s", html_ApplyValPass, html_Save);
break;
case PAGE_TCL:
// Information table - TCL heap
chprintf(chp, "%s%s %u %s", html_tr_th, text_Heap, UMM_MALLOC_CFG_HEAP_SIZE/1024, text_kB);
chprintf(chp, "%s%s", html_e_th_th, text_Used);
chprintf(chp, "%s%s", html_e_th_th, text_Free);
chprintf(chp, "%s%s", html_e_th_th, text_Total);
chprintf(chp, "%s%s%s", html_e_th_th, text_Metric, html_e_th_e_tr);
chprintf(chp, "%s%s%s", html_tr_td, text_Entries, html_e_td_td);
chprintf(chp, "%u%s", ummHeapInfo.usedEntries, html_e_td_td);
chprintf(chp, "%u%s", ummHeapInfo.freeEntries, html_e_td_td);
chprintf(chp, "%u%s", ummHeapInfo.totalEntries, html_e_td_td);
chprintf(chp, "%s %u%%%s", text_Fragmentation, umm_fragmentation_metric(), html_e_td_e_tr_tr_td);
chprintf(chp, "%s%s", text_Blocks, html_e_td_td);
chprintf(chp, "%u%s", ummHeapInfo.usedBlocks, html_e_td_td);
chprintf(chp, "%u%s", ummHeapInfo.freeBlocks, html_e_td_td);
chprintf(chp, "%u%s", ummHeapInfo.totalBlocks, html_e_td_td);
chprintf(chp, "%s %u%%", text_Used, umm_usage_metric());
chprintf(chp, "%s%s %u %s", html_tr_th, text_Storage, (UBS_BLOCK_SIZE * UBS_BLOCK_COUNT)/1024, text_kB);
chprintf(chp, "%s%s", html_e_th_th, text_Used);
chprintf(chp, "%s%s", html_e_th_th, text_Free);
chprintf(chp, "%s%s", html_e_th_th, text_Total);
chprintf(chp, "%s%s%s", html_e_th_th, text_Metric, html_e_th_e_tr);
chprintf(chp, "%s%s%s", html_tr_td, text_Blocks, html_e_td_td);
chprintf(chp, "%u%s", UBS_BLOCK_COUNT - uBSFreeBlocks, html_e_td_td);
chprintf(chp, "%u%s", uBSFreeBlocks, html_e_td_td);
chprintf(chp, "%u%s", UBS_BLOCK_COUNT, html_e_td_td);
chprintf(chp, "%s %u%%", text_Used, (uint8_t)((UBS_BLOCK_COUNT - uBSFreeBlocks) / (float)(UBS_BLOCK_COUNT / (float)100)));
chprintf(chp, "%s%s", html_e_td_e_tr, html_e_table);
chprintf(chp, "<i class='icon' style='font-size:20px;' title=\"");
tcl_list_cmd(&tcl, &chp, "\r\n", 0b00111100);
chprintf(chp, "\"></i>");
chprintf(chp, "<i class='icon' style='font-size:20px;' title=\"");
tcl_list_var(&tcl, &chp, "\r\n");
chprintf(chp, "\"></i>");
chprintf(chp, "%s%s", html_br, html_br);
// Script area
printTextArea(chp, 's', tclCmd, TCL_SCRIPT_LENGTH, 120, 20);
chprintf(chp, "%s%s", html_br, html_br);
// Select script
chprintf(chp, "%s%s%s%s", html_table, html_tr_td, text_Script, html_e_td_td);
chprintf(chp, "%sP%s", html_select_submit, html_e_tag);
logAddress = 1;
for (scriptp = scriptLL; scriptp != NULL; scriptp = scriptp->next) {
chprintf(chp, "%s%u", html_option, logAddress);
if (webScript == logAddress) { chprintf(chp, "%s", html_selected); }
else { chprintf(chp, "%s", html_e_tag); }
chprintf(chp, "%u. %s%s", logAddress, scriptp->name, html_e_option);
logAddress++;
}
chprintf(chp, "%s%u", html_option, DUMMY_NO_VALUE);
if (webScript == DUMMY_NO_VALUE) { chprintf(chp, "%s", html_selected); }
else { chprintf(chp, "%s", html_e_tag); }
chprintf(chp, "New script%s", html_e_option);
chprintf(chp, "%s%s", html_e_select, html_e_td_e_tr_tr_td);
chprintf(chp, "%s%s", text_Name, html_e_td_td);
printTextInput(chp, 'n', scriptName, NAME_LENGTH);
chprintf(chp, "%s%s", html_e_td_e_tr, html_e_table);
// Buttons
chprintf(chp, "%s%s%s%s", html_Run, html_Refresh, html_Save, html_Restart);
// Output
chprintf(chp, "%s<pre>Last output:\r\n%.*s</pre>", html_br, strlen(tclOutput), tclOutput);
//for (uint16_t j = 0; j < strlen(tclOutput); j++) { DBG_HTTP("-%x", tclOutput[j]); }
//DBG_HTTP("\r\n");
break;
case PAGE_TIMER:
chprintf(chp, "%s#", html_tr_th);
chprintf(chp, "%s%s", html_e_th_th, text_Name);
chprintf(chp, "%s%s", html_e_th_th, text_On);
chprintf(chp, "%s%s", html_e_th_th, text_Type);
chprintf(chp, "%s%s", html_e_th_th, text_Start);
chprintf(chp, "%s%s", html_e_th_th, text_Period);
chprintf(chp, "%s%s %s", html_e_th_th, text_Run, text_time);
chprintf(chp, "%s%s %s", html_e_th_th, text_Next, text_on);
chprintf(chp, "%s%s %s", html_e_th_th, text_Next, text_off);
chprintf(chp, "%s%s", html_e_th_th, text_Address);
chprintf(chp, "%s%s", html_e_th_th, text_Script);
chprintf(chp, "%s%s", html_e_th_th, text_On);
chprintf(chp, "%s%s", html_e_th_th, text_Off);
chprintf(chp, "%s%s%s\r\n", html_e_th_th, text_Status, html_e_th_e_tr);
// Information table
for (uint8_t i = 0; i < TIMER_SIZE; i++) {
chprintf(chp, "%s%u.%s", html_tr_td, i + 1, html_e_td_td);
chprintf(chp, "%s%s", conf.timer[i].name, html_e_td_td);
printOkNok(chp, GET_CONF_TIMER_ENABLED(conf.timer[i].setting));
chprintf(chp, "%s", html_e_td_td);
if (GET_CONF_TIMER_TYPE(conf.timer[i].setting)) {
chprintf(chp, "%s %s", text_Run, text_on);
for (uint8_t j = 0; j < ARRAY_SIZE(weekDayShort); j++) {
if ((conf.timer[i].setting >> (8 - j)) & 0b1) {
chprintf(chp, " %s", weekDayShort[j]);
}
}
} else {
chprintf(chp, "%s", text_Period);
}
chprintf(chp, "%s", html_e_td_td);
chprintf(chp, "%02u:%02u%s", conf.timer[i].startTime / SECONDS_PER_MINUTE,
conf.timer[i].startTime % SECONDS_PER_MINUTE, html_e_td_td);
if (!GET_CONF_TIMER_TYPE(conf.timer[i].setting)) {
chprintf(chp, "%u %s", conf.timer[i].periodTime,
durationSelect[GET_CONF_TIMER_PERIOD_TYPE(conf.timer[i].setting)]);
}
chprintf(chp, "%s%u %s", html_e_td_td, conf.timer[i].runTime,
durationSelect[GET_CONF_TIMER_RUN_TYPE(conf.timer[i].setting)]);
chprintf(chp, "%s", html_e_td_td);
tempTime = conf.timer[i].nextOn;
if (GET_CONF_TIMER_ENABLED(conf.timer[i].setting)) printFrmTimestamp(chp, &tempTime);
chprintf(chp, "%s", html_e_td_td);
tempTime = conf.timer[i].nextOff;
if (GET_CONF_TIMER_ENABLED(conf.timer[i].setting)) printFrmTimestamp(chp, &tempTime);
chprintf(chp, "%s", html_e_td_td);
printNodeAddress(chp, conf.timer[i].toAddress, 'I', conf.timer[i].toFunction,
conf.timer[i].toNumber, true);
chprintf(chp, "%s", html_e_td_td);
if (conf.timer[i].evalScript[0]) chprintf(chp, "%s", conf.timer[i].evalScript);
else chprintf(chp, "%s", NOT_SET);
chprintf(chp, "%s", html_e_td_td);
chprintf(chp, "%.2f%s", conf.timer[i].constantOn, html_e_td_td);
chprintf(chp, "%.2f%s", conf.timer[i].constantOff, html_e_td_td);
printOkNok(chp, GET_CONF_TIMER_TRIGGERED(conf.timer[i].setting));
chprintf(chp, "%s", html_e_td_e_tr);
}
chprintf(chp, "%s%s", html_e_table, html_table);
chprintf(chp, "%s%s%s", html_tr_td, text_Timer, html_e_td_td);
chprintf(chp, "%sP%s", html_select_submit, html_e_tag);
for (uint8_t i = 0; i < TIMER_SIZE; i++) {
chprintf(chp, "%s%u", html_option, i);
if (webTimer == i) { chprintf(chp, "%s", html_selected); }
else { chprintf(chp, "%s", html_e_tag); }
chprintf(chp, "%u. %s%s", i + 1, conf.timer[i].name, html_e_option);
}
chprintf(chp, "%s%s", html_e_select, html_e_td_e_tr_tr_td);
chprintf(chp, "%s%s", text_Name, html_e_td_td);
printTextInput(chp, 'n', conf.timer[webTimer].name, NAME_LENGTH);
chprintf(chp, "%s%s %s%s", html_e_td_e_tr_tr_td, text_Timer, text_is, html_e_td_td);
printOnOffButton(chp, "B", GET_CONF_TIMER_ENABLED(conf.timer[webTimer].setting));
chprintf(chp, "%s%s%s", html_e_td_e_tr_tr_td, text_Type, html_e_td_td);
printTwoButton(chp, "C", GET_CONF_TIMER_TYPE(conf.timer[webTimer].setting), 1, 0b10,
text_Period, text_Calendar);
chprintf(chp, "%s%s%s", html_e_td_e_tr_tr_td, weekDay[0], html_e_td_td);
printOnOffButton(chp, "J", GET_CONF_TIMER_MO(conf.timer[webTimer].setting));
chprintf(chp, "%s%s%s", html_e_td_e_tr_tr_td, weekDay[1], html_e_td_td);