forked from dawibe/Tonuino_Tag_Writer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tonuino_Tag_Writer_ESP32.ino
1571 lines (1390 loc) · 77.9 KB
/
Tonuino_Tag_Writer_ESP32.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ╔══╗───╔╦╦══╦═╦╦═╗╔══╗────╔╗╔╗──╔╗ ╗╔
// ╚╗╔╩╦═╦╣║╠║║╣║║║║║╚╗╦╩╗╔═╗║║║╠╦╗╚╝╔╬╬╦═╦╦╗
// ─║║╬║║║║║╠║║╣║║║║║─║╣╬╚╣╬║║║║║╔╬║║╣║║║╩╣╔╝
// ─╚╩═╩╩═╩═╩══╩╩═╩═╝─╚╩══╬╗║╚══╩╝╚══╩╩╩╩═╩╝
// ───────────────────────╚═╝
//
// Tonuino Tag Writer (TTW)
// Daniel Wilhelm
// Hans Schneider (debugging and improvements)
//
// Hardware: ESP32 Dev Module
//
// Arduino IDE 1.8.19
//
// ESP32 2.0.1
//
// WIFIManager (https://github.com/tzapu/WiFiManager)
//
// ArduinoJSON 5.13.5 (6 not yet supported!)
//
// Arduino Config
// 4M (190KB SPIFFS with OTA); 240MHz;
// 882513 Bytes (67%) of memory used, max. memory is 1310720 bytes
// 39148 bytes (11%) of dynamic memory used by global variables, 288532 bytes remaining for local variables, max. is 327680 bytes
//
// ToDo
// - NTP timezone selection
// - Clear config also clear WiFi
//
// Bugs
// - byteToHexStringRange: last byte ist etwas irreführend
// - card must be represented after each read/write
//
// 0.1.0 First stable working version
// 0.1.2 Bug: show right input options after read card
// 0.1.3 Ability to switch to German language in configuration 2022-02-29
//
// NodeMCU connection to external devices
// ESP32 <-> RC522:
// 3.3V <-> 3.3V
// GND <-> GND
// D2 <-> RST
// D18 <-> SCK
// D19 <-> MISO
// D21 <-> SDA
// D23 <-> MOSI
// D22 <-> IRQ // Currently not used
// **************************************************************************
// Includes
// **************************************************************************
#include <FS.h>
#include "SPIFFS.h"
#include <ESPmDNS.h>
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager WiFi Configuration Magic
#include <ArduinoJson.h> // Config file handling
#include <TimeLib.h> // https://github.com/PaulStoffregen/Time
#include <SPI.h>
#include <MFRC522.h>
//#include <HTTPUpdateServer.h>
#include <ESP32httpUpdate.h>
WebServer httpServer(80);
//HTTPUpdateServer httpUpdater;
WiFiUDP Udp; // Needed for NTP
unsigned int NtpLocalPort = 123; // local port to listen for UDP packets (NTP)
// **************************************************************************
// Defines
// **************************************************************************
#define DEBUG // Define for Debug output on serial interface
#define CLEAR_BTN 4 // GPIO4 LOW during PowerUp will clear the json config file
#define RST_PIN 2 // GPIO2 MFRC522
#define SS_PIN 21 // GPIO21 MFRC522
#define IRQ_PIN 22 // GPIO22 MFRC522
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
const String FIRMWARE_NAME = "TTW";
const String VERSION = "v0.1.3";
// Number of known default keys (hard-coded)
// NOTE: Synchronize the NR_KNOWN_KEYS define with the defaultKeys[] array
#define NR_KNOWN_KEYS 8
// Known keys, see: https://code.google.com/p/mfcuk/wiki/MifareClassicDefaultKeys
byte knownKeys[NR_KNOWN_KEYS][MFRC522::MF_KEY_SIZE] = {
{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, // FF FF FF FF FF FF = factory default
{0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5}, // A0 A1 A2 A3 A4 A5
{0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5}, // B0 B1 B2 B3 B4 B5
{0x4d, 0x3a, 0x99, 0xc3, 0x51, 0xdd}, // 4D 3A 99 C3 51 DD
{0x1a, 0x98, 0x2c, 0x7e, 0x45, 0x9a}, // 1A 98 2C 7E 45 9A
{0xd3, 0xf7, 0xd3, 0xf7, 0xd3, 0xf7}, // D3 F7 D3 F7 D3 F7
{0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}, // AA BB CC DD EE FF
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 00 00 00 00 00 00
};
byte dataBlock[] = {
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
String strDataBlock = "00000000000000000000000000000000";
// **************************************************************************
// **************************************************************************
// DO NOT CHANGE ANYTHING BELOW THIS LINE
// **************************************************************************
// **************************************************************************
// **************************************************************************
// Debug
// **************************************************************************
#ifdef DEBUG
#define DEBUG_PRINT(x) Serial.print (x)
#define DEBUG_PRINTLN(x) Serial.println (x)
#else
#define DEBUG_PRINT(x)
#define DEBUG_PRINTLN(x)
#endif
// **************************************************************************
// Variables
// **************************************************************************
// config.json
char host_name[20] = "";
char ntpserver[30] = "";
// NTP
bool ntp_enabled = true; // Set to false to disable querying for the time
char poolServerName[30] = "europe.pool.ntp.org"; // default NTP Server when not configured in config.json
char boottime[20] = ""; // Boot Time
const int timeZone = 1; // Central European Time
const int NTP_PACKET_SIZE = 48; // NTP time is in the first 48 bytes of message
byte packetBuffer[NTP_PACKET_SIZE]; // Buffer to hold incoming & outgoing packets
// Webserver
String javaScript;
String htmlHeader;
String htmlFooter;
// Other
bool shouldSaveConfig = false; // Flag for saving data
bool de_enabled = false; // Set language to English
// **************************************************************************
// JSON Configuration Management
// **************************************************************************
bool loadConfig() {
if (SPIFFS.exists("/config.json")) {
File configFile = SPIFFS.open("/config.json", "r");
if (configFile) {
DEBUG_PRINTLN("[0161] opened config file");
size_t size = configFile.size();
if (size > 1024) {
DEBUG_PRINTLN("[0164] Config file size is too large");
return false;
}
std::unique_ptr<char[]> buf(new char[size]); // Allocate a buffer to store contents of the file.
configFile.readBytes(buf.get(), size); // Input Buffer (needed by ArduinoJson)
DynamicJsonBuffer jsonBuffer;
JsonObject& json = jsonBuffer.parseObject(buf.get());
#ifdef DEBUG
json.printTo(Serial);
#endif
if (json.success()) {
DEBUG_PRINTLN("[0175] \nparsed json");
if (json.containsKey("hostname")) strncpy(host_name, json["hostname"], 20);
if (json.containsKey("ntpserver")) strncpy(ntpserver, json["ntpserver"], 30);
if (json.containsKey("ntpenabled")) ntp_enabled = json["ntpenabled"];
if (json.containsKey("deenabled")) de_enabled = json["deenabled"];
}
else {
DEBUG_PRINTLN("[0182] Failed to parse config file");
return false;
}
}
else {
DEBUG_PRINTLN("[0187] Failed to open config file");
return false;
}
}
return true;
}
// **************************************************************************
// Callback notifying us of the need to save config
// **************************************************************************
void saveConfigCallback()
{
DEBUG_PRINTLN("[0200] Should save config");
shouldSaveConfig = true;
}
// **************************************************************************
// Gets called when WiFiManager enters configuration mode
// **************************************************************************
void configModeCallback (WiFiManager *myWiFiManager)
{
DEBUG_PRINTLN("[0210] Entered config mode");
DEBUG_PRINTLN(WiFi.softAPIP());
DEBUG_PRINTLN(myWiFiManager->getConfigPortalSSID()); // if you used auto generated SSID, print it
}
// **************************************************************************
// IP Address to String
// **************************************************************************
String ipToString(IPAddress ip)
{
String s = "";
for (int i = 0; i < 4; i++)
s += i ? "." + String(ip[i]) : String(ip[i]);
return s;
}
// **************************************************************************
// NTP Time Syncronization
// **************************************************************************
time_t getNtpTime()
{
IPAddress ntpServerIP; // NTP server's ip address
while (Udp.parsePacket() > 0) ; // Discard any previously received packets
DEBUG_PRINTLN("[0236] NTP: Transmit NTP Request");
WiFi.hostByName(ntpserver, ntpServerIP); // Lookup IP from Hostname
DEBUG_PRINT("[0238] NTP: ");
DEBUG_PRINT(ntpserver);
DEBUG_PRINT(" [0240] IP: ");
DEBUG_PRINTLN(ntpServerIP);
sendNTPpacket(ntpServerIP);
uint32_t beginWait = millis();
while (millis() - beginWait < 1500) {
int size = Udp.parsePacket();
if (size >= NTP_PACKET_SIZE) {
DEBUG_PRINTLN("[0247] NTP: Receive NTP Response");
Udp.read(packetBuffer, NTP_PACKET_SIZE); // read packet into the buffer
unsigned long secsSince1900;
// convert four bytes starting at location 40 to a long integer
secsSince1900 = (unsigned long)packetBuffer[40] << 24;
secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
secsSince1900 |= (unsigned long)packetBuffer[43];
return secsSince1900 - 2208988800UL + (timeZone * 60 * 60); // NTP Time - 70 Years + TimeZone Hours
}
}
DEBUG_PRINTLN("[0258] NTP: No NTP Response :-(");
return 0; // return 0 if unable to get the time
}
// send an NTP request to the time server at the given address
void sendNTPpacket(IPAddress &address)
{
memset(packetBuffer, 0, NTP_PACKET_SIZE); // set all bytes in the buffer to 0
packetBuffer[0] = 0b11100011; // LI (Clock is unsynchronized), Version (4), Mode (Client)
packetBuffer[1] = 0; // Stratum, or type of clock (Unspecified or invalid)
packetBuffer[2] = 6; // Polling Interval (log2 seconds)
packetBuffer[3] = 0xEC; // Peer Clock Precision (log2 seconds)
// 8 bytes of zero for Root Delay & Root Dispersion
packetBuffer[12] = 49; //
packetBuffer[13] = 0x4E; //
packetBuffer[14] = 49; //
packetBuffer[15] = 52; //
Udp.beginPacket(address, 123); // NTP requests are to port 123
Udp.write(packetBuffer, NTP_PACKET_SIZE);
Udp.endPacket();
}
// **************************************************************************
// HTML Header Template
// **************************************************************************
void buildHeader()
{
htmlHeader="<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//DE' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>\n";
htmlHeader+="<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='de'>\n";
htmlHeader+=" <head>\n";
htmlHeader+=" <meta name='viewport' content='width=device-width, initial-scale=.75' />\n";
htmlHeader+=" <link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' />\n";
htmlHeader+=" <style>@media (max-width: 991px) {.nav-pills>li {float: none; margin-left: 0; margin-top: 5px; text-align: center;}}</style>\n";
htmlHeader+=" <title>" + FIRMWARE_NAME + " - " + VERSION + "</title>\n";
htmlHeader+=" </head>\n";
htmlHeader+=" <body>\n";
htmlHeader+=" <div class='container'>\n";
htmlHeader+=" <h1>" + FIRMWARE_NAME + " - " + VERSION + "</h1>\n";
htmlHeader+=" <div class='row'>\n";
htmlHeader+=" <div class='col-md-12'>\n";
htmlHeader+=" <ul class='nav nav-pills'>\n";
htmlHeader+=" <li class='active'>\n";
htmlHeader+=" <a href='/'>Hostname <span class='badge'>" + String(host_name) + "</span></a></li>\n";
htmlHeader+=" <li class='active'>\n";
htmlHeader+=" <a href='http://" + ipToString(WiFi.localIP()) + ":80'>Local IP<span class='badge'>" + ipToString(WiFi.localIP()) + "</span></a></li>\n";
htmlHeader+=" <li class='active'>\n";
htmlHeader+=" <a href='/'>MAC <span class='badge'>" + String(WiFi.macAddress()) + "</span></a></li>\n";
htmlHeader+=" <li class='active'>\n";
if (de_enabled) {
htmlHeader+=" <a href='/config'>Konfiguration</a></li>\n";
}
else {
htmlHeader+=" <a href='/config'>Configuration</a></li>\n";
}
htmlHeader+=" <li class='active'>\n";
htmlHeader+=" <a href='/tonuino'>Tonuino</a></li>\n";
htmlHeader+=" <li class='active'>\n";
htmlHeader+=" <a href='/ota'>FW-Update</a></li>\n";
htmlHeader+=" <li class='active'>\n";
htmlHeader+=" <a href='/'><span class='glyphicon glyphicon-signal'></span> "+ String(WiFi.RSSI()) + " dBm</a></li>\n";
htmlHeader+=" </ul>\n";
htmlHeader+=" </div>\n";
htmlHeader+=" </div><hr />\n";
}
// **************************************************************************
// HTML Footer Template
// **************************************************************************
void buildFooter()
{
if (de_enabled) {
htmlFooter=" <div class='row'><div class='col-md-12'><em>Tonuino Tag Writer (TTW), Aktuelle Zeit: "+ String(hour()) + ":" + String(minute()) + ":" + String(second()) +"</em></div></div>\n";
}
else {
htmlFooter=" <div class='row'><div class='col-md-12'><em>Tonuino Tag Writer (TTW), Current time: "+ String(hour()) + ":" + String(minute()) + ":" + String(second()) +"</em></div></div>\n";
}
htmlFooter+=" </div>\n";
htmlFooter+=" </body>\n";
htmlFooter+="</html>\n";
}
// **************************************************************************
// HTML JavaScript Template
// **************************************************************************
void buildJavaScript()
{
javaScript="<script type='text/javascript'>\n";
javaScript+=" function einblenden(){\n";
javaScript+=" var selectcard = document.getElementById('select_card').selectedIndex;\n";
javaScript+=" var selectadmincard = document.getElementById('select_admincard').selectedIndex;\n";
javaScript+=" document.getElementById('input_titleA1').style.display = 'none';\n";
javaScript+=" document.getElementById('input_titleB1').style.display = 'none';\n";
javaScript+=" document.getElementById('input_titleA2').style.display = 'none';\n";
javaScript+=" document.getElementById('input_titleB2').style.display = 'none';\n";
javaScript+=" document.getElementById('input_title1').style.display = 'none';\n";
javaScript+=" document.getElementById('input_title2').style.display = 'none';\n";
javaScript+=" if(selectcard == 0) {\n";
javaScript+=" document.getElementById('hoerspiel').style.display = 'inline';\n";
javaScript+=" }\n";
javaScript+=" else {\n";
javaScript+=" document.getElementById('hoerspiel').style.display = 'none';\n";
javaScript+=" }\n";
javaScript+=" if(selectcard == 1) {\n";
javaScript+=" document.getElementById('album').style.display = 'inline';\n";
javaScript+=" }\n";
javaScript+=" else {\n";
javaScript+=" document.getElementById('album').style.display = 'none';\n";
javaScript+=" }\n";
javaScript+=" if(selectcard == 2) {\n";
javaScript+=" document.getElementById('party').style.display = 'inline';\n";
javaScript+=" }\n";
javaScript+=" else {\n";
javaScript+=" document.getElementById('party').style.display = 'none';\n";
javaScript+=" }\n";
javaScript+=" if(selectcard == 3) {\n";
javaScript+=" document.getElementById('einzel').style.display = 'inline';\n";
javaScript+=" document.getElementById('input_title1').style.display = 'inline';\n";
javaScript+=" document.getElementById('input_title2').style.display = 'inline';\n";
javaScript+=" }\n";
javaScript+=" else {\n";
javaScript+=" document.getElementById('einzel').style.display = 'none';\n";
javaScript+=" }\n";
javaScript+=" if(selectcard == 4) {\n";
javaScript+=" document.getElementById('hoerbuch').style.display = 'inline';\n";
javaScript+=" }\n";
javaScript+=" else {\n";
javaScript+=" document.getElementById('hoerbuch').style.display = 'none';\n";
javaScript+=" }\n";
javaScript+=" if(selectcard == 5) {\n";
javaScript+=" document.getElementById('hoerspielvonbis').style.display = 'inline';\n";
javaScript+=" document.getElementById('input_titleA1').style.display = 'inline';\n";
javaScript+=" document.getElementById('input_titleB1').style.display = 'inline';\n";
javaScript+=" document.getElementById('input_titleA2').style.display = 'inline';\n";
javaScript+=" document.getElementById('input_titleB2').style.display = 'inline';\n";
javaScript+=" }\n";
javaScript+=" else {\n";
javaScript+=" document.getElementById('hoerspielvonbis').style.display = 'none';\n";
javaScript+=" }\n";
javaScript+=" if(selectcard == 6) {\n";
javaScript+=" document.getElementById('albumvonbis').style.display = 'inline';\n";
javaScript+=" document.getElementById('input_titleA1').style.display = 'inline';\n";
javaScript+=" document.getElementById('input_titleB1').style.display = 'inline';\n";
javaScript+=" document.getElementById('input_titleA2').style.display = 'inline';\n";
javaScript+=" document.getElementById('input_titleB2').style.display = 'inline';\n";
javaScript+=" }\n";
javaScript+=" else {\n";
javaScript+=" document.getElementById('albumvonbis').style.display = 'none';\n";
javaScript+=" }\n";
javaScript+=" if(selectcard == 7) {\n";
javaScript+=" document.getElementById('partyvonbis').style.display = 'inline';\n";
javaScript+=" document.getElementById('input_titleA1').style.display = 'inline';\n";
javaScript+=" document.getElementById('input_titleB1').style.display = 'inline';\n";
javaScript+=" document.getElementById('input_titleA2').style.display = 'inline';\n";
javaScript+=" document.getElementById('input_titleB2').style.display = 'inline';\n";
javaScript+=" }\n";
javaScript+=" else {\n";
javaScript+=" document.getElementById('partyvonbis').style.display = 'none';\n";
javaScript+=" }\n";
javaScript+=" if(selectcard == 8) {\n";
javaScript+=" document.getElementById('Sonder').style.display = 'inline';\n";
javaScript+=" document.getElementById('select_admincard').style.display = 'inline';\n";
javaScript+=" }\n";
javaScript+=" else {\n";
javaScript+=" document.getElementById('Sonder').style.display = 'none';\n";
javaScript+=" document.getElementById('select_admincard').style.display = 'none';\n";
javaScript+=" }\n";
javaScript+=" if(selectcard == 8 && selectadmincard == 1) {\n";
javaScript+=" document.getElementById('input_time1').style.display = 'inline';\n";
javaScript+=" document.getElementById('input_time2').style.display = 'inline';\n";
javaScript+=" }\n";
javaScript+=" else {\n";
javaScript+=" document.getElementById('input_time1').style.display = 'none';\n";
javaScript+=" document.getElementById('input_time2').style.display = 'none';\n";
javaScript+=" }\n";
javaScript+=" }\n";
javaScript+="</script>\n";
}
// **************************************************************************
// HTML Page for ESP Reboot
// **************************************************************************
void Handle_Reboot()
{
if (de_enabled) {
httpServer.sendHeader("Verbindung", "geschlossen");
httpServer.send(200, "text/html", F("<body>Neustart OK, bitte öffne die <a href='/'>Startseite</a>.</body>"));
}
else {
httpServer.sendHeader("Connection", "close");
httpServer.send(200, "text/html", F("<body>Reboot OK, please open the <a href='/'>main page</a>.</body>"));
}
delay(500);
ESP.restart();
}
// **************************************************************************
// HTML Page for ESP Clear Json config-file
// **************************************************************************
void Handle_ClearConfig()
{
if (de_enabled) {
httpServer.sendHeader("Verbindung", "geschlossen");
httpServer.send(200, "text/html", F("<body>Config-Datei gelöscht, ESP Neustart, bitte öffne die <a href='/'>Startseite</a>.</body>"));
}
else {
httpServer.sendHeader("Connection", "close");
httpServer.send(200, "text/html", F("<body>Config file deleted, ESP reboot, please open the <a href='/'>main page</a>.</body>"));
}
SPIFFS.remove("/config.json");
delay(500);
ESP.restart();
}
// **************************************************************************
// HTML Page for ESP configuration
// **************************************************************************
void Handle_config()
{
if (httpServer.method() == HTTP_GET) {
DEBUG_PRINTLN("[0483] WEB: Connection established - /config");
sendConfigPage("", "", 0, 200);
}
else {
DEBUG_PRINTLN("[0487] WEB: Connection established - /config (save)");
}
if (de_enabled) {
sendConfigPage("Settings erfolgreich gesichert! Bitte neu starten!", "Erfolg!", 1, 200);
}
else {
sendConfigPage("Settings saved! Please reboot!", "Success!", 1, 200);
}
}
void sendConfigPage(String message, String header, int type, int httpcode)
{
char host_name_conf[20] = "";
char ntpserver_conf[30] = "";
bool ntpenabled_conf;
bool deenabled_conf;
if (type == 1){ // Type 1 -> save data
String message = "[0505] WEB: Number of args received: ";
message += String(httpServer.args()) + "\n";
for (int i = 0; i < httpServer.args(); i++) {
message += "[0508] Arg " + (String)i + " –> ";
message += httpServer.argName(i) + ":" ;
message += httpServer.arg(i) + "\n";
}
strncpy(host_name_conf, httpServer.arg("host_name_conf").c_str(), 20);
strncpy(ntpserver_conf, httpServer.arg("ntpserver_conf").c_str(), 30);
if (httpServer.hasArg("ntpenabled")) {ntpenabled_conf = true;} else {ntpenabled_conf = false;}
if (httpServer.hasArg("deenabled")) {deenabled_conf = true;} else {deenabled_conf = false;}
DEBUG_PRINT("[0518]");
DEBUG_PRINTLN(message);
// validate values before saving
bool validconf;
if (httpServer.args() != 0) {
validconf = true;
}
else {
validconf = false;
}
if (validconf)
{
DEBUG_PRINTLN("[0531] SPI: save config.json...");
DynamicJsonBuffer jsonBuffer;
JsonObject& json = jsonBuffer.createObject();
json["hostname"] = String(host_name_conf);
json["ntpserver"] = String(ntpserver_conf);
json["ntpenabled"] = String(ntpenabled_conf);
json["deenabled"] = String(deenabled_conf);
File configFile = SPIFFS.open("/config.json", "w");
if (!configFile) {
DEBUG_PRINTLN("[0541] SPI: failed to open config file for writing");
}
#ifdef DEBUG
json.printTo(Serial);
#endif
DEBUG_PRINTLN("[0546]");
json.printTo(configFile);
configFile.close();
// end save
}
} else { // Type 0 -> load data
if (SPIFFS.begin())
{
DEBUG_PRINTLN("[0554] SPI: mounted file system");
if (SPIFFS.exists("/config.json"))
{
// file exists, reading and loading
DEBUG_PRINTLN("[0558] SPI: reading config file");
File configFile = SPIFFS.open("/config.json", "r");
if (configFile) {
DEBUG_PRINTLN("[0561] SPI: opened config file");
size_t size = configFile.size();
// Allocate a buffer to store contents of the file.
std::unique_ptr<char[]> buf(new char[size]);
configFile.readBytes(buf.get(), size);
DynamicJsonBuffer jsonBuffer;
JsonObject& json = jsonBuffer.parseObject(buf.get());
DEBUG_PRINT("[0569] JSO: ");
#ifdef DEBUG
json.printTo(Serial);
#endif
if (json.success()) {
DEBUG_PRINTLN("\n[0574] JSO: parsed json");
if (json.containsKey("hostname")) strncpy(host_name_conf, json["hostname"], 20);
if (json.containsKey("ntpserver")) strncpy(ntpserver_conf, json["ntpserver"], 30);
if (json.containsKey("ntpenabled")) ntpenabled_conf = json["ntpenabled"];
if (json.containsKey("deenabled")) deenabled_conf = json["deenabled"];
} else {
DEBUG_PRINTLN("[0580] JSO: failed to load json config");
}
}
}
} else {
DEBUG_PRINTLN("[0585] SPI: failed to mount FS");
}
}
String htmlDataconf; // Hold the HTML Code
buildHeader();
buildFooter();
htmlDataconf=htmlHeader;
if (type == 1)
htmlDataconf+=" <div class='row'><div class='col-md-12'><div class='alert alert-success'><strong>" + header + "</strong> " + message + "</div></div></div>\n";
if (type == 2)
htmlDataconf+=" <div class='row'><div class='col-md-12'><div class='alert alert-warning'><strong>" + header + "</strong> " + message + "</div></div></div>\n";
if (type == 3)
htmlDataconf+=" <div class='row'><div class='col-md-12'><div class='alert alert-danger'><strong>" + header + "</strong> " + message + "</div></div></div>\n";
htmlDataconf+=" <div class='row'>\n";
htmlDataconf+="<form method='post' action='/config'>";
htmlDataconf+=" <div class='col-md-12'>\n";
if (de_enabled) {
htmlDataconf+=" <h3>Konfiguration</h3>\n";
}
else {
htmlDataconf+=" <h3>Configuration</h3>\n";
}
htmlDataconf+=" <table class='table table-striped' style='table-layout: fixed;'>\n";
if (de_enabled) {
htmlDataconf+=" <thead><tr><th>Option</th><th>Aktueller Wert</th><th>Neuer Wert</th></tr></thead>\n";
}
else {
htmlDataconf+=" <thead><tr><th>Option</th><th>Current value</th><th>New value</th></tr></thead>\n";
}
htmlDataconf+=" <tbody>\n";
htmlDataconf+=" <tr class='text-uppercase'><td>Hostname</td><td><code>" + ((host_name_conf[0] == 0 ) ? String("(" + String(host_name) + ")") : String(host_name_conf)) + "</code></td><td><input type='text' id='host_name_conf' name='host_name_conf' value='" + String(host_name_conf) + "'></td></tr>\n";
htmlDataconf+=" <tr class='text-uppercase'><td>NTP Server</td><td><code>" + ((ntpserver_conf[0] == 0 ) ? String("(" + String(poolServerName) + ")") : String(ntpserver_conf)) + "</code></td><td><input type='text' id='ntpserver_conf' name='ntpserver_conf' value='" + String(ntpserver_conf) + "'></td></tr>\n";
if (de_enabled) {
htmlDataconf+=" <tr class='text-uppercase'><td>NTP ein?</td><td><code>" + (ntpenabled_conf ? String("Ja") : String("Nein")) + "</code></td><td><input type='checkbox' id='ntpena' name='ntpenabled' " + (ntpenabled_conf ? String("checked") : String("")) + "></td></tr>";
htmlDataconf+=" <tr class='text-uppercase'><td>Sprache Deutsch ein?</td><td><code>" + (deenabled_conf ? String("Ja") : String("Nein")) + "</code></td><td><input type='checkbox' id='deenab' name='deenabled' " + (deenabled_conf ? String("checked") : String("")) + "></td></tr>";
// htmlDataconf+=" <tr><td colspan='5' class='text-center'><em><a href='/reboot' class='btn btn-sm btn-danger'>Neustart</a> <a href='/update' class='btn btn-sm btn-warning'>Update</a> <button type='submit' class='btn btn-sm btn-success'>Sichern</button> <a href='/' class='btn btn-sm btn-primary'>Abbruch</a></em></td></tr>";
htmlDataconf+=" <tr><td colspan='5' class='text-center'><em><a href='/reboot' class='btn btn-sm btn-danger'>Neustart</a> <button type='submit' class='btn btn-sm btn-success'>Sichern</button> <a href='/' class='btn btn-sm btn-primary'>Abbruch</a></em></td></tr>";
}
else {
htmlDataconf+=" <tr class='text-uppercase'><td>NTP on?</td><td><code>" + (ntpenabled_conf ? String("Yes") : String("No")) + "</code></td><td><input type='checkbox' id='ntpena' name='ntpenabled' " + (ntpenabled_conf ? String("checked") : String("")) + "></td></tr>";
htmlDataconf+=" <tr class='text-uppercase'><td>German language on?</td><td><code>" + (deenabled_conf ? String("YES") : String("No")) + "</code></td><td><input type='checkbox' id='deenab' name='deenabled' " + (deenabled_conf ? String("checked") : String("")) + "></td></tr>";
// htmlDataconf+=" <tr><td colspan='5' class='text-center'><em><a href='/reboot' class='btn btn-sm btn-danger'>Roboot</a> <a href='/update' class='btn btn-sm btn-warning'>Update</a> <button type='submit' class='btn btn-sm btn-success'>Save</button> <a href='/' class='btn btn-sm btn-primary'>Cancel</a></em></td></tr>";
htmlDataconf+=" <tr><td colspan='5' class='text-center'><em><a href='/reboot' class='btn btn-sm btn-danger'>Roboot</a> <button type='submit' class='btn btn-sm btn-success'>Save</button> <a href='/' class='btn btn-sm btn-primary'>Cancel</a></em></td></tr>";
}
htmlDataconf+=" </tbody></table>\n";
htmlDataconf+=" </div></div>\n";
htmlDataconf+=htmlFooter;
httpServer.send(httpcode, "text/html; charset=UTF-8", htmlDataconf);
httpServer.client().stop();
}
// **************************************************************************
// Convert a Decimal String to a Hex String
// **************************************************************************
String dectohex(String dec) {
String hex;
hex = String(dec.toInt(), HEX);
return hex;
}
// **************************************************************************
// Convert a Hex String to a Decimal String
// **************************************************************************
String hextodec(String hex) {
String dec;
dec = String(strtol(hex.c_str(), NULL, 16));
return dec;
}
// **************************************************************************
// HTML create/change Tonuino ChipCard Page
// **************************************************************************
void Handle_tonuino(){
if (httpServer.method() == HTTP_GET) {
DEBUG_PRINTLN("[0665] WEB: Connection established - /tonuino");
// Look for new cards
bool card = 0;
if (mfrc522.PICC_IsNewCardPresent())
{
card = 1;
}
// Select one of the cards
if (mfrc522.PICC_ReadCardSerial())
{
card = 1;
}
if (card == 0) {
DEBUG_PRINTLN("[0681] RFID: No card presented!");
if (de_enabled) {
sendControlPage("Keine Karte aufgelegt! Werte unten stammen nicht von einer Karte!", "Warnung!", 2, 200);
}
else {
sendControlPage("No Card presented! Values do not come from a card!", "Warning!", 2, 200);
}
}
else {
readblock(1,0);
// Halt PICC
mfrc522.PICC_HaltA();
// Stop encryption on PCD
mfrc522.PCD_StopCrypto1();
if (de_enabled) {
sendControlPage("Werte (" + byteToHexString(dataBlock,sizeof(dataBlock)) + ") gelesen von Karte! UID: " + getchipcarduid(), "Erfolg!", 1, 200);
}
else {
sendControlPage("Values (" + byteToHexString(dataBlock,sizeof(dataBlock)) + ") read from a Card! UID: " + getchipcarduid(), "Success!", 1, 200);
}
}
}
else {
DEBUG_PRINTLN("[0704] WEB: Connection established - /tonuino (write card)");
// generate the Tonuino MiFare sector 1 block 0
strDataBlock = httpServer.arg(0);
if (httpServer.arg(1).length() == 1) strDataBlock += "0"; // "1" -> "01"
strDataBlock += httpServer.arg(1); // Version
if (httpServer.arg(3) == "8") { // Modifier Karte
strDataBlock += "00";
}
else {
if (dectohex(httpServer.arg(2)).length() == 1) strDataBlock += "0";
strDataBlock += dectohex(httpServer.arg(2));
}
if (httpServer.arg(3) == "0") { // Hörspiel
strDataBlock += "01";
}
if (httpServer.arg(3) == "1") { // Album
strDataBlock += "02";
}
if (httpServer.arg(3) == "2") { // Party
strDataBlock += "03";
}
if (httpServer.arg(3) == "3") { // Einzel
strDataBlock += "04";
if (dectohex(httpServer.arg(4)).length() == 1) strDataBlock += "0";
strDataBlock += dectohex(httpServer.arg(4));
}
if (httpServer.arg(3) == "4") { // Hörbuch
strDataBlock += "05";
}
if (httpServer.arg(3) == "5") { // Hörspiel von bis
strDataBlock += "07";
if (dectohex(httpServer.arg(6)).length() == 1) strDataBlock += "0";
strDataBlock += dectohex(httpServer.arg(6));
if (dectohex(httpServer.arg(8)).length() == 1) strDataBlock += "0";
strDataBlock += dectohex(httpServer.arg(8));
}
if (httpServer.arg(3) == "6") { // Album von bis
strDataBlock += "08";
if (dectohex(httpServer.arg(6)).length() == 1) strDataBlock += "0";
strDataBlock += dectohex(httpServer.arg(6));
if (dectohex(httpServer.arg(8)).length() == 1) strDataBlock += "0";
strDataBlock += dectohex(httpServer.arg(8));
}
if (httpServer.arg(3) == "7") { // Party von bis
strDataBlock += "09";
if (dectohex(httpServer.arg(6)).length() == 1) strDataBlock += "0";
strDataBlock += dectohex(httpServer.arg(6));
if (dectohex(httpServer.arg(8)).length() == 1) strDataBlock += "0";
strDataBlock += dectohex(httpServer.arg(8));
}
if (httpServer.arg(3) == "8" && httpServer.arg(5) == "0") { // Modifier Karte - Admin Menü
strDataBlock += "00";
}
if (httpServer.arg(3) == "8" && httpServer.arg(5) == "1") { // Modifier Karte - Einschlaf Modus
strDataBlock += "01";
if (dectohex(httpServer.arg(7)).length() == 1) strDataBlock += "0";
strDataBlock += dectohex(httpServer.arg(7));
}
if (httpServer.arg(3) == "8" && httpServer.arg(5) == "2") { // Modifier Karte - Pausetanz Modus
strDataBlock += "02";
}
if (httpServer.arg(3) == "8" && httpServer.arg(5) == "3") { // Modifier Karte - Sperre Modus
strDataBlock += "03";
}
if (httpServer.arg(3) == "8" && httpServer.arg(5) == "4") { // Modifier Karte - Kleinkind Modus
strDataBlock += "04";
}
if (httpServer.arg(3) == "8" && httpServer.arg(5) == "5") { // Modifier Karte - Kindergarten Modus
strDataBlock += "05";
}
if (httpServer.arg(3) == "8" && httpServer.arg(5) == "6") { // Modifier Karte - Titel wiederholen Modus
strDataBlock += "06";
}
if (httpServer.arg(3) == "8" && httpServer.arg(5) == "7") { // Modifier Karte - Audio Feedback
strDataBlock += "07";
}
strDataBlock += "00";
// convert the hex char array to hex byte array
hexCharacterStringToBytes(dataBlock, strDataBlock.c_str());
// Look for new cards
bool card = 0;
if (mfrc522.PICC_IsNewCardPresent())
{
card = 1;
}
// Select one of the cards
if (mfrc522.PICC_ReadCardSerial())
{
card = 1;
}
if (card == 0) {
DEBUG_PRINTLN("[0815] RFID: No card presented!");
if (de_enabled) {
sendControlPage("Keine Karte aufgelegt!", "Fehler!", 3, 200);
}
else {
sendControlPage("No card presented!", "Error!", 3, 200);
}
}
else {
// Write the block to the card
writeblock(1, 0);
// Halt PICC
mfrc522.PICC_HaltA();
// Stop encryption on PCD
mfrc522.PCD_StopCrypto1();
if (de_enabled) {
sendControlPage("Neue Werte (" + byteToHexString(dataBlock,sizeof(dataBlock)) + ") auf die Karte geschrieben!", "Erfolg!", 1, 200);
}
else {
sendControlPage("New values (" + byteToHexString(dataBlock,sizeof(dataBlock)) + ") written to card!", "Success!", 1, 200);
}
}
}
}
void sendControlPage(String message, String header, int type, int httpcode)
{
if (type == 1) { // Type 1
// String message = "WEB: Neue Werte gesetzt über die control page: ";
String message = "[0845] WEB: Set new values using control page: ";
message += String(httpServer.args()) + "\n";
for (int i = 0; i < httpServer.args(); i++) {
message += "Arg " + (String)i + " -> ";
message += httpServer.argName(i) + ":" ;
message += httpServer.arg(i) + "\n";
}
DEBUG_PRINTLN(message);
}
String htmlDataconf; // Hold the HTML Code
buildHeader();
buildFooter();
buildJavaScript();
htmlDataconf=htmlHeader;
htmlDataconf+=javaScript;
if (type == 1)
htmlDataconf+=" <div class='row'><div class='col-md-12'><div class='alert alert-success'><strong>" + header + "</strong> " + message + "</div></div></div>\n";
if (type == 2)
htmlDataconf+=" <div class='row'><div class='col-md-12'><div class='alert alert-warning'><strong>" + header + "</strong> " + message + "</div></div></div>\n";
if (type == 3)
htmlDataconf+=" <div class='row'><div class='col-md-12'><div class='alert alert-danger'><strong>" + header + "</strong> " + message + "</div></div></div>\n";
htmlDataconf+=" <div class='row'>\n";
htmlDataconf+=" <form method='post' action='/tonuino'>\n";
htmlDataconf+=" <div class='col-md-12'>\n";
if (de_enabled) {
htmlDataconf+=" <h3>Erzeuge / Ändere Tonuino Karte</h3>\n";
htmlDataconf+=" <table class='table table-striped' style='table-layout: fixed;'>\n";
htmlDataconf+=" <thead><tr><th>Option</th><th colspan='3'>Werte</th><th>Kommentare</th></tr></thead>\n";
htmlDataconf+=" <tbody>\n";
htmlDataconf+=" <tr><td>Magic Number</td><td><input type='text' id='magicnumber_set' name='magicnumber_set' size='7' maxlength='8' value='" + byteToHexStringRange(dataBlock,0,4) + "'></td><td></td><td></td><td>Nummer muss mit dem Tonuino übereinstimmen, default ist 1337B347</td></tr>\n";
htmlDataconf+=" <tr><td>Version</td><td>";
htmlDataconf+=" <select name='version_set' size='1'>\n";
htmlDataconf+=" <option " + ((byteToHexStringRange(dataBlock,4,5) == "01" ) ? String("selected") : String("")) + ">1</option>\n";
htmlDataconf+=" <option " + ((byteToHexStringRange(dataBlock,4,5) == "02" ) ? String("selected") : String("")) + ">2</option>\n";
htmlDataconf+=" </select>\n";
htmlDataconf+=" </td><td></td><td></td><td>V1 ist für Tonuino 2.0.x<br>V2 ist für Tonuino 2.1.x</td></tr>\n";
htmlDataconf+=" <tr><td>Ordner Nummer</td><td><input type='text' id='folder_set' name='folder_set' size='2' maxlength='2' value='" + ((byteToHexStringRange(dataBlock,5,6) == "00") ? String("01") : hextodec(byteToHexStringRange(dataBlock,5,6))) + "'> (1-99)</td><td></td><td></td><td></td></tr>\n";
htmlDataconf+=" <tr><td>Kartentyp</td><td>\n";
htmlDataconf+=" <select id='select_card' onchange='einblenden()' name='cardtype' size='1'>\n";
htmlDataconf+=" <option value='0' " + ((byteToHexStringRange(dataBlock,6,7) == "01" ) ? String("selected") : String("")) + ">Hörspiel</option>\n";
htmlDataconf+=" <option value='1' " + ((byteToHexStringRange(dataBlock,6,7) == "02" ) ? String("selected") : String("")) + ">Album</option>\n";
htmlDataconf+=" <option value='2' " + ((byteToHexStringRange(dataBlock,6,7) == "03" ) ? String("selected") : String("")) + ">Party</option>\n";
htmlDataconf+=" <option value='3' " + ((byteToHexStringRange(dataBlock,6,7) == "04" ) ? String("selected") : String("")) + ">Einzel</option>\n";
htmlDataconf+=" <option value='4' " + ((byteToHexStringRange(dataBlock,6,7) == "05" ) ? String("selected") : String("")) + ">Hörbuch</option>\n";
htmlDataconf+=" <option value='5' " + ((byteToHexStringRange(dataBlock,6,7) == "07" ) ? String("selected") : String("")) + ">Hörspiel von-bis</option>\n";
htmlDataconf+=" <option value='6' " + ((byteToHexStringRange(dataBlock,6,7) == "08" ) ? String("selected") : String("")) + ">Album von-bis</option>\n";
htmlDataconf+=" <option value='7' " + ((byteToHexStringRange(dataBlock,6,7) == "09" ) ? String("selected") : String("")) + ">Party von-bis</option>\n";
htmlDataconf+=" <option value='8' " + ((byteToHexStringRange(dataBlock,5,6) == "00" ) ? String("selected") : String("")) + ">Sonderkarte</option>\n";
htmlDataconf+=" </select>\n";
htmlDataconf+=" </td><td>\n";
htmlDataconf+=" <input type='text' id='input_title1' name='title' value='" + hextodec(byteToHexStringRange(dataBlock,7,8)) + "' size='2' maxlength='3' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "04" ) ? String("inline") : String("none")) + ";'> <div id='input_title2' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "04" ) ? String("inline") : String("none")) + ";'>(1-255)</div>\n";
htmlDataconf+=" <select id='select_admincard' name='admincardtype' style='display: " + ((byteToHexStringRange(dataBlock,5,6) == "00" ) ? String("inline") : String("none")) + ";' onchange='einblenden()'>\n";
htmlDataconf+=" <option value='0' " + ((byteToHexStringRange(dataBlock,5,7) == "0000") ? String("selected") : String("")) + ">Admin Menü</option>\n";
htmlDataconf+=" <option value='1' " + ((byteToHexStringRange(dataBlock,5,7) == "0001") ? String("selected") : String("")) + ">Einschlaf Modus</option>\n";
htmlDataconf+=" <option value='2' " + ((byteToHexStringRange(dataBlock,5,7) == "0002") ? String("selected") : String("")) + ">Pausetanz Modus</option>\n";
htmlDataconf+=" <option value='3' " + ((byteToHexStringRange(dataBlock,5,7) == "0003") ? String("selected") : String("")) + ">Sperre</option>\n";
htmlDataconf+=" <option value='4' " + ((byteToHexStringRange(dataBlock,5,7) == "0004") ? String("selected") : String("")) + ">Kleinkind Modus</option>\n";
htmlDataconf+=" <option value='5' " + ((byteToHexStringRange(dataBlock,5,7) == "0005") ? String("selected") : String("")) + ">Kindergarten Modus</option>\n";
htmlDataconf+=" <option value='6' " + ((byteToHexStringRange(dataBlock,5,7) == "0006") ? String("selected") : String("")) + ">Titel wiederholen</option>\n";
htmlDataconf+=" <option value='7' " + ((byteToHexStringRange(dataBlock,5,7) == "0007") ? String("selected") : String("")) + ">Audio-Feedback</option>\n";
htmlDataconf+=" </select>\n";
htmlDataconf+=" <input type='text' id='input_titleA1' name='titlefrom' value='" + hextodec(byteToHexStringRange(dataBlock,7,8)) + "' size='2' maxlength='3' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "07" ) || (byteToHexStringRange(dataBlock,6,7) == "08" ) || (byteToHexStringRange(dataBlock,6,7) == "09" ) ? String("inline") : String("none")) + ";'> <div id='input_titleA2' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "07" ) || (byteToHexStringRange(dataBlock,6,7) == "08" ) || (byteToHexStringRange(dataBlock,6,7) == "09" ) ? String("inline") : String("none")) + ";'>(1-255)</div>\n";
htmlDataconf+=" </td><td>\n";
htmlDataconf+=" <input type='text' id='input_time1' name='sleeptime' value='" + hextodec(byteToHexStringRange(dataBlock,7,8)) + "' size='1' maxlength='2' style='display: " + ((byteToHexStringRange(dataBlock,5,7) == "0001" ) ? String("inline") : String("none")) + ";'> <div id='input_time2' style='display: " + ((byteToHexStringRange(dataBlock,5,7) == "0001" ) ? String("inline") : String("none")) + ";'>(1-99 min)</div>\n";
htmlDataconf+=" <input type='text' id='input_titleB1' name='titletill' value='" + hextodec(byteToHexStringRange(dataBlock,8,9)) + "' size='1' maxlength='3' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "07" ) || (byteToHexStringRange(dataBlock,6,7) == "08" ) || (byteToHexStringRange(dataBlock,6,7) == "09" ) ? String("inline") : String("none")) + ";'> <div id='input_titleB2' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "07" ) || (byteToHexStringRange(dataBlock,6,7) == "08" ) || (byteToHexStringRange(dataBlock,6,7) == "09" ) ? String("inline") : String("none")) + ";'>(1-255)</div>\n";
htmlDataconf+=" </td><td>\n";
htmlDataconf+=" <div id='hoerspiel' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "01" ) && (byteToHexStringRange(dataBlock,5,6) != "00" ) ? String("inline") : String("none")) + ";'>\n";
htmlDataconf+=" Ein zufälliger Titel aus dem gewählten Ordner wird abgespielt.\n";
htmlDataconf+=" </div>\n";
htmlDataconf+=" <div id='album' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "02" ) && (byteToHexStringRange(dataBlock,5,6) != "00" ) ? String("inline") : String("none")) + ";'>\n";
htmlDataconf+=" Spielt alle Titel des Ordners in numerischer Reihenfolge.\n";
htmlDataconf+=" </div>\n";
htmlDataconf+=" <div id='party' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "03" ) && (byteToHexStringRange(dataBlock,5,6) != "00" ) ? String("inline") : String("none")) + ";'>\n";
htmlDataconf+=" Spielt zufällige Titel des Ordners in Endlosschleife.\n";
htmlDataconf+=" </div>\n";
htmlDataconf+=" <div id='einzel' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "04" ) && (byteToHexStringRange(dataBlock,5,6) != "00" ) ? String("inline") : String("none")) + ";'>\n";
htmlDataconf+=" Spielt Datei xxx.mp3 ab.\n";
htmlDataconf+=" </div>\n";
htmlDataconf+=" <div id='hoerbuch' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "05" ) && (byteToHexStringRange(dataBlock,5,6) != "00" ) ? String("inline") : String("none")) + ";'>\n";
htmlDataconf+=" Spielt alle Titel des Ordners in numerischer Reihenfolge und speichert den Fortschritt, so dass beim nächsten Verwenden der Karte beim aktuellen Titel begonnen wird.\n";
htmlDataconf+=" </div>\n";
htmlDataconf+=" <div id='hoerspielvonbis' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "07" ) && (byteToHexStringRange(dataBlock,5,6) != "00" ) ? String("inline") : String("none")) + ";'>\n";
htmlDataconf+=" Ein zufälliger Titel im gewählten Ordner zwischen von und bis wird abgespielt.\n";
htmlDataconf+=" </div>\n";
htmlDataconf+=" <div id='albumvonbis' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "08" ) && (byteToHexStringRange(dataBlock,5,6) != "00" ) ? String("inline") : String("none")) + ";'>\n";
htmlDataconf+=" Spielt alle Titel des Ordners zwischen von und bis in numerischer Reihenfolge.\n";
htmlDataconf+=" </div>\n";
htmlDataconf+=" <div id='partyvonbis' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "09" ) && (byteToHexStringRange(dataBlock,5,6) != "00" ) ? String("inline") : String("none")) + ";'>\n";
htmlDataconf+=" Spielt zufällige Titel des Ordners zwischen von und bis in Endlosschleife.\n";
htmlDataconf+=" </div>\n";
htmlDataconf+=" <div id='Sonder' style='display: " + ((byteToHexStringRange(dataBlock,5,6) == "00" ) ? String("inline") : String("none")) + ";'>\n";
htmlDataconf+=" Dies ist eine Sonderkarte\n";
htmlDataconf+=" </div>\n";
htmlDataconf+=" </td></tr>\n";
htmlDataconf+=" <tr><td colspan='5' class='text-center'><em> <button type='submit' class='btn btn-sm btn-success'>Schreibe Karte</button> <a href='/tonuino' class='btn btn-sm btn-warning'>Lese Karte</a> <a href='/' class='btn btn-sm btn-primary'>Abbruch</a></em></td></tr>\n";
}
else {
htmlDataconf+=" <h3>Generate / Change Tonuino card</h3>\n";
htmlDataconf+=" <table class='table table-striped' style='table-layout: fixed;'>\n";
htmlDataconf+=" <thead><tr><th>Option</th><th colspan='3'>Values</th><th>Comments</th></tr></thead>\n";
htmlDataconf+=" <tbody>\n";
htmlDataconf+=" <tr><td>Magic Number</td><td><input type='text' id='magicnumber_set' name='magicnumber_set' size='7' maxlength='8' value='" + byteToHexStringRange(dataBlock,0,4) + "'></td><td></td><td></td><td>Number must match the Tonuino, default is 1337B347</td></tr>\n";
htmlDataconf+=" <tr><td>Version</td><td>";
htmlDataconf+=" <select name='version_set' size='1'>\n";
htmlDataconf+=" <option " + ((byteToHexStringRange(dataBlock,4,5) == "01" ) ? String("selected") : String("")) + ">1</option>\n";
htmlDataconf+=" <option " + ((byteToHexStringRange(dataBlock,4,5) == "02" ) ? String("selected") : String("")) + ">2</option>\n";
htmlDataconf+=" </select>\n";
htmlDataconf+=" </td><td></td><td></td><td>V1 is for Tonuino 2.0.x<br>V2 is for Tonuino 2.1.x</td></tr>\n";
htmlDataconf+=" <tr><td>Ordner Nummer</td><td><input type='text' id='folder_set' name='folder_set' size='2' maxlength='2' value='" + ((byteToHexStringRange(dataBlock,5,6) == "00") ? String("01") : hextodec(byteToHexStringRange(dataBlock,5,6))) + "'> (1-99)</td><td></td><td></td><td></td></tr>\n";
htmlDataconf+=" <tr><td>Kartentyp</td><td>\n";
htmlDataconf+=" <select id='select_card' onchange='einblenden()' name='cardtype' size='1'>\n";
htmlDataconf+=" <option value='0' " + ((byteToHexStringRange(dataBlock,6,7) == "01" ) ? String("selected") : String("")) + ">Radioplay</option>\n";
htmlDataconf+=" <option value='1' " + ((byteToHexStringRange(dataBlock,6,7) == "02" ) ? String("selected") : String("")) + ">Album</option>\n";
htmlDataconf+=" <option value='2' " + ((byteToHexStringRange(dataBlock,6,7) == "03" ) ? String("selected") : String("")) + ">Party</option>\n";
htmlDataconf+=" <option value='3' " + ((byteToHexStringRange(dataBlock,6,7) == "04" ) ? String("selected") : String("")) + ">Single</option>\n";
htmlDataconf+=" <option value='4' " + ((byteToHexStringRange(dataBlock,6,7) == "05" ) ? String("selected") : String("")) + ">Audio book</option>\n";
htmlDataconf+=" <option value='5' " + ((byteToHexStringRange(dataBlock,6,7) == "07" ) ? String("selected") : String("")) + ">Radioplay from-to</option>\n";
htmlDataconf+=" <option value='6' " + ((byteToHexStringRange(dataBlock,6,7) == "08" ) ? String("selected") : String("")) + ">Album from-to</option>\n";
htmlDataconf+=" <option value='7' " + ((byteToHexStringRange(dataBlock,6,7) == "09" ) ? String("selected") : String("")) + ">Party from-to</option>\n";
htmlDataconf+=" <option value='8' " + ((byteToHexStringRange(dataBlock,5,6) == "00" ) ? String("selected") : String("")) + ">Special card</option>\n";
htmlDataconf+=" </select>\n";
htmlDataconf+=" </td><td>\n";
htmlDataconf+=" <input type='text' id='input_title1' name='title' value='" + hextodec(byteToHexStringRange(dataBlock,7,8)) + "' size='2' maxlength='3' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "04" ) ? String("inline") : String("none")) + ";'> <div id='input_title2' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "04" ) ? String("inline") : String("none")) + ";'>(1-255)</div>\n";
htmlDataconf+=" <select id='select_admincard' name='admincardtype' style='display: " + ((byteToHexStringRange(dataBlock,5,6) == "00" ) ? String("inline") : String("none")) + ";' onchange='einblenden()'>\n";
htmlDataconf+=" <option value='0' " + ((byteToHexStringRange(dataBlock,5,7) == "0000") ? String("selected") : String("")) + ">Admin Menü</option>\n";
htmlDataconf+=" <option value='1' " + ((byteToHexStringRange(dataBlock,5,7) == "0001") ? String("selected") : String("")) + ">Sleep mode</option>\n";
htmlDataconf+=" <option value='2' " + ((byteToHexStringRange(dataBlock,5,7) == "0002") ? String("selected") : String("")) + ">Stop dance</option>\n";
htmlDataconf+=" <option value='3' " + ((byteToHexStringRange(dataBlock,5,7) == "0003") ? String("selected") : String("")) + ">Lock</option>\n";
htmlDataconf+=" <option value='4' " + ((byteToHexStringRange(dataBlock,5,7) == "0004") ? String("selected") : String("")) + ">Toddler mode</option>\n";
htmlDataconf+=" <option value='5' " + ((byteToHexStringRange(dataBlock,5,7) == "0005") ? String("selected") : String("")) + ">Kindergarten mode</option>\n";
htmlDataconf+=" <option value='6' " + ((byteToHexStringRange(dataBlock,5,7) == "0006") ? String("selected") : String("")) + ">Repeat title</option>\n";
htmlDataconf+=" <option value='7' " + ((byteToHexStringRange(dataBlock,5,7) == "0007") ? String("selected") : String("")) + ">Audio-Feedback</option>\n";
htmlDataconf+=" </select>\n";
htmlDataconf+=" <input type='text' id='input_titleA1' name='titlefrom' value='" + hextodec(byteToHexStringRange(dataBlock,7,8)) + "' size='2' maxlength='3' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "07" ) || (byteToHexStringRange(dataBlock,6,7) == "08" ) || (byteToHexStringRange(dataBlock,6,7) == "09" ) ? String("inline") : String("none")) + ";'> <div id='input_titleA2' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "07" ) || (byteToHexStringRange(dataBlock,6,7) == "08" ) || (byteToHexStringRange(dataBlock,6,7) == "09" ) ? String("inline") : String("none")) + ";'>(1-255)</div>\n";
htmlDataconf+=" </td><td>\n";
htmlDataconf+=" <input type='text' id='input_time1' name='sleeptime' value='" + hextodec(byteToHexStringRange(dataBlock,7,8)) + "' size='1' maxlength='2' style='display: " + ((byteToHexStringRange(dataBlock,5,7) == "0001" ) ? String("inline") : String("none")) + ";'> <div id='input_time2' style='display: " + ((byteToHexStringRange(dataBlock,5,7) == "0001" ) ? String("inline") : String("none")) + ";'>(1-99 min)</div>\n";
htmlDataconf+=" <input type='text' id='input_titleB1' name='titletill' value='" + hextodec(byteToHexStringRange(dataBlock,8,9)) + "' size='1' maxlength='3' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "07" ) || (byteToHexStringRange(dataBlock,6,7) == "08" ) || (byteToHexStringRange(dataBlock,6,7) == "09" ) ? String("inline") : String("none")) + ";'> <div id='input_titleB2' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "07" ) || (byteToHexStringRange(dataBlock,6,7) == "08" ) || (byteToHexStringRange(dataBlock,6,7) == "09" ) ? String("inline") : String("none")) + ";'>(1-255)</div>\n";
htmlDataconf+=" </td><td>\n";
htmlDataconf+=" <div id='hoerspiel' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "01" ) && (byteToHexStringRange(dataBlock,5,6) != "00" ) ? String("inline") : String("none")) + ";'>\n";
htmlDataconf+=" A random track from the selected folder is played.\n";
htmlDataconf+=" </div>\n";
htmlDataconf+=" <div id='album' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "02" ) && (byteToHexStringRange(dataBlock,5,6) != "00" ) ? String("inline") : String("none")) + ";'>\n";
htmlDataconf+=" Plays all tracks in the folder in numerical order.\n";
htmlDataconf+=" </div>\n";
htmlDataconf+=" <div id='party' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "03" ) && (byteToHexStringRange(dataBlock,5,6) != "00" ) ? String("inline") : String("none")) + ";'>\n";
htmlDataconf+=" Plays random tracks in the folder in an endless loop.\n";
htmlDataconf+=" </div>\n";
htmlDataconf+=" <div id='einzel' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "04" ) && (byteToHexStringRange(dataBlock,5,6) != "00" ) ? String("inline") : String("none")) + ";'>\n";
htmlDataconf+=" Plays file xxx.mp3.\n";
htmlDataconf+=" </div>\n";
htmlDataconf+=" <div id='hoerbuch' style='display: " + ((byteToHexStringRange(dataBlock,6,7) == "05" ) && (byteToHexStringRange(dataBlock,5,6) != "00" ) ? String("inline") : String("none")) + ";'>\n";