-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathWebsites.ino
2896 lines (2827 loc) · 132 KB
/
Websites.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
// ############################## Statistik ##############################
void SiteStatistik() {
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
SerialPrintLine();
#endif
String sResponse = ""; // Response HTML
sResponse.reserve(4096); // ohne: Dauer: 74829 µS, 2585 Byte, Free Heap: 29.20 kB
int c = 0; // Counter für Anzeige Zeilen
insertHeaderCSS(sResponse); // Header und CCS einfügen
insertMenu_Index(sResponse); // Index Menu Tabelle Zeile 1 einfügen
insertMenu_Ueberschrift(sResponse); // Überschrift Tabelle Zeile 2 einfügen
// Tabelle Zeile 3 einfuegen
sResponse += F("<tr><td class=\"CXB\" colspan=\"5\">Maximalverbrauch</td></tr>");
// Tabelle Zeile 4, 5, 6 einfuegen (Maximalwerte)
unsigned long l = DS1307_read_long(DS1307_ADDR_MAXS0DAYTIME); // read timestamp Maximum Tag
if (l != 0xFFFFFFFF) { // Zeit bereits geschrieben
c += 1; // Counter erhöhen
sResponse += F("<tr><td class=\"rx\">pro Tag</td>"
"<td class=\"rx\" colspan=\"2\">");
sResponse += (DateToString(l));
sResponse += F("</td>"
"<td class=\"rx\">");
sResponse += longToStr(s0_count_max_day); // read max S0-Count day
sResponse += F(" m³</td>"
"<td class=\"lx\"> </td></tr>");
}
l = DS1307_read_long(DS1307_ADDR_MAXS0MONTHTIME); // read timestamp Maximum month
if (l != 0xFFFFFFFF) { // Zeit bereits geschrieben
c += 1; // Counter erhöhen
sResponse += F("<tr><td class=\"rx\">pro Monat</td>"
"<td class=\"rx\" colspan=\"2\">");
sResponse += (month(l));
sResponse += F("/");
sResponse += (year(l));
sResponse += F("</td>"
"<td class=\"rx\">");
sResponse += longToStr(s0_count_max_month); // read max S0-Count month
sResponse += F(" m³</td>"
"<td class=\"lx\"> </td></tr>");
}
l = DS1307_read_long(DS1307_ADDR_MAXS0YEARTIME); // read timestamp Maximum year
if (l != 0xFFFFFFFF) { // Zeit bereits geschrieben
c += 1; // Counter erhöhen
sResponse += F("<tr><td class=\"rx\">pro Jahr</td>"
"<td class=\"rx\" colspan=\"2\">");
sResponse += (year(l));
sResponse += F("</td>"
"<td class=\"rx\">");
sResponse += longToStr(s0_count_max_year); // read max S0-Count year
sResponse += F(" m³</td>"
"<td class=\"lx\"> </td></tr>");
}
if (c == 0) { // noch keine Daten geschrieben
sResponse += F("<tr><td class=\"c\" colspan=\"5\">"
"<br><br>Noch keine Daten vorhanden!<br><br><br>"
"</td></tr>");
}
// Tabelle Zeile 7 einfuegen
sResponse += F("<tr><td class=\"CXB\" colspan=\"5\">Jahreszeiten</td></tr>");
// Tabelle Zeile 8, 9, 10, 11 einfuegen (Jahreszeiten)
c = 0; // Reset Counter für Anzeige Zeilen
if (day() > 15) {
l = now() - 28944000; // - 11 Monate (335 Tage)
} else {
l = now() - 28857600; // - 11 Monate (334 Tage)
}
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.print(F("heute -11 Monate: "));
Serial.println(DateToString(l));
#endif
while (month(l) % 3 != 0) { // Prüfung Monat durch 3 teilbar
if (day(l) < 15) {
l = l + 2678400; // + 1 Monat (31 Tage)
} else {
l = l + 2419200; // + 1 Monat (28 Tage)
}
}
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.print(F("Beginn Jahreszeit: "));
Serial.println(DateToString(l));
#endif
String Line;
int daint = 0; // Integer Tag
int moint = 0; // Integer Monat
int yeint = 0; // Integer Year
String datum; // String Datum
int Space2;
int Space3;
long s0_count_int = 0;
long s0_count_avg_int = 0; // S0-Counter Durchschnitt
long s0_count_ges_int = 0; // S0-Counter gesamt
byte monat = month(l); // Monat Beginn
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.print(F("Monat Beginn: "));
Serial.println(monat);
#endif
int tage = 0;
String FileName = (F("/log/y_"));
FileName += (year(l));
FileName += (F(".log"));
nocheinmal: // Sprungmarke für 2. Durchlauf bei 2 Jahren
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.print(F("Datei: "));
Serial.println(FileName);
#endif
if (LittleFS.exists(FileName)) { // Returns true if a file with given path exists, false otherwise.
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.print(F("LittleFS Reading Data from: "));
Serial.println(FileName);
#endif
File LogFile = LittleFS.open(FileName, "r"); // Open text file for reading.
while (LogFile.available()) {
Line = LogFile.readStringUntil('\n'); // Lets read line by line from the file
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.println(Line);
#endif
daint = Line.substring(0, 2).toInt(); // Integer Tag
moint = Line.substring(3, 5).toInt(); // Integer Monat
yeint = Line.substring(6, 10).toInt(); // Integer Year
datum = Line.substring(0, 10); // String Datum
Space2 = Line.indexOf(' ', 19); // nach Uhrzeit folgt Count absolut
Space3 = Line.indexOf(' ', Space2 + 1 ); // nach absulut Count folgt Count
s0_count_int = Line.substring(Space3 + 1).toInt();
while (moint > (monat + 2)) {
monat += 3;
}
if (moint >= monat && moint <= monat + 2) {
s0_count_ges_int = s0_count_ges_int + s0_count_int;
tage = tage + daint;
}
if (moint == monat + 2) { // Jahreszeit
sResponse = WebsiteStatistikJahreszeiten(sResponse, monat, yeint);
//sResponse = WebsiteStatistikJahreszeiten(sResponse, monat, ye);
// sResponse = WebsiteStatistikJahreszeiten(sResponse, monat, s0_count_ges_int, tage, ye);
// Ende Zeitraum einfügen
sResponse += F(" - ");
sResponse += datum; // Datum einfügen
sResponse += F("</td>"
"<td class=\"rx\">");
sResponse += longToStr(s0_count_ges_int); // Gesamtverbrauch einfügen
sResponse += F(" m³</td>"
"<td class=\"rx\">");
s0_count_avg_int = s0_count_ges_int / tage;
sResponse += longToStr(s0_count_avg_int); // Durchschnitt Verbrauch pro Tag einfügen
sResponse += F(" m³/d </td></tr>");
s0_count_ges_int = 0; // Zähler zurück setzen
tage = 0; // Anzahl Tage zurück setzen
}
}
LogFile.close();
} else { // Datei Vorjahr existiert nicht
yeint = year(); // aktuelles Jahr
monat = 0;
FileName = (F("/log/y_"));
FileName += (year()); // aktuelles Jahr
FileName += (F(".log"));
if (LittleFS.exists(FileName)) { // Returns true if a file with given path exists, false otherwise.
goto nocheinmal; // 2. Durchlauf starten
} else { // Datei aktuelles Jahr existiert auch nicht
monat = month(); // aktuellen Monat übernehmen
yeint = year(); // aktuelles Jahr
//ye = year();
}
}
// wenn über 2 Jahre, 2. Durchlauf starten
if (yeint < year()) {
monat = 0;
FileName = (F("/log/y_"));
FileName += (year()); // aktuelles Jahr
FileName += (F(".log"));
goto nocheinmal;
}
// aktuelle Jahreszeit zuletzt
s0_count_ges_int = s0_count_ges_int + s0_count_month; // Counter aktuell addieren
tage = tage + day(); // Tage addieren
sResponse = WebsiteStatistikJahreszeiten(sResponse, month(), yeint);
// sResponse = WebsiteStatistikJahreszeiten(sResponse, month(), ye);
// sResponse = WebsiteStatistikJahreszeiten(sResponse, month(), s0_count_ges_int, tage, ye);
// Ende Zeitraum einfügen
sResponse += F(" - ");
sResponse += DateToString(now()); // Datum einfügen
sResponse += F("</td>"
"<td class=\"rx\">");
sResponse += longToStr(s0_count_ges_int); // Gesamtverbrauch einfügen
sResponse += F(" m³</td>"
"<td class=\"rx\">");
s0_count_avg_int = s0_count_ges_int / tage;
sResponse += longToStr(s0_count_avg_int); // Durchschnitt Verbrauch pro Tag einfügen
sResponse += F(" m³/d </td></tr>");
// Footer anhängen und senden
insertFooterSend(sResponse); // Footer anhängen und senden
}
// ############################## Einstellungen diverse anzeigen ##############################
void SiteSetup() {
String sResponse = ""; // Response HTML
sResponse.reserve(4096); // ohne: Dauer: 2947 µS, 2643 Byte2, Free Heap: 28.37 kB
String submit = server.arg("submit"); // welcher Button wurde betätigt
String logtext = "";
int countargs = server.args(); // Anzahl Argumente
if (countargs != 0) {
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
SerialPrintLine(); // Trennlinie seriell ausgeben
Serial.print(F("Button wurde betaetigt(submit): "));
Serial.println(submit);
Serial.print(F("Anzahl Argumente(countargs): "));
Serial.println(countargs);
#endif
if (submit == "saves0count") { // Button "Zählerstand speichern" betätigt
String qs0count = server.arg("s0count"); // S0-Count
// Prüfung auf Zahl einfügen
qs0count.replace(",", "."); // Komma durch Punkt ersetzen
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.print(F("S0-Count: "));
Serial.println(qs0count);
#endif
s0_count_abs = round(qs0count.toFloat() * 100.0); // "toFloat" funktioniert nicht richtig, deshalb runden
DS1307_write_long(DS1307_ADDR_S0COUNTABS, s0_count_abs); // save S0-Counter to DS1307 RAM
logtext = F("Set Counter to: ");
logtext += longToStr(s0_count_abs);
logtext += F(" m³");
}
if (submit == "resetMaxDay") { // Button "Rückstellen" betätigt
s0_count_max_day = 0; // Maximum pro Tag löschen
DS1307_write_long(DS1307_ADDR_MAXS0DAY, s0_count_max_day); // Maximum pro Tag speichern
DS1307_write_long(DS1307_ADDR_MAXS0DAYTIME, now()); // aktuelle Uhrzeit speichern
logtext = F("Reset max consumption per day");
}
if (submit == "resetMaxMonth") { // Button "Rückstellen" betätigt
s0_count_max_month = 0; // Maximum pro Monat löschen
DS1307_write_long(DS1307_ADDR_MAXS0MONTH, s0_count_max_month); // Maximum Monat speichern
DS1307_write_long(DS1307_ADDR_MAXS0MONTHTIME, now()); // aktuelle Uhrzeit speichern
logtext = F("Reset max consumption per month");
}
if (submit == "resetMaxYear") { // Button "Rückstellen" betätigt
s0_count_max_year = 0; // Maximum pro Jahr löschen
DS1307_write_long(DS1307_ADDR_MAXS0YEAR, s0_count_max_year); // Maximum Jahr speichern
DS1307_write_long(DS1307_ADDR_MAXS0YEARTIME, now()); // aktuelle Uhrzeit speichern
logtext += F("Reset max consumption per year");
}
if (submit == "sets0trip1") { // Button "Rückstellen" betätigt
EEPROM_write_long(EEPROM_ADDR_S0TRIP1, s0_count_abs); // S0-Count Trip begin set to S0-Count
EEPROM_write_long(EEPROM_ADDR_S0TRIP1TIME, now()); // S0-Count Trip time set
logtext = F("Reset Counter 1 to: ");
logtext += longToStr(s0_count_abs);
logtext += F(" m³");
}
if (submit == "sets0trip2") { // Button "Rückstellen" betätigt
EEPROM_write_long(EEPROM_ADDR_S0TRIP2, s0_count_abs); // S0-Count Trip begin set to S0-Count
EEPROM_write_long(EEPROM_ADDR_S0TRIP2TIME, now()); // S0-Count Trip time set
logtext = F("Reset Counter 2 to: ");
logtext += longToStr(s0_count_abs);
logtext += F(" m³");
}
if (submit == "setser") {
SerialOutput = !SerialOutput;// toggle boolean
EEPROM_write_byte(EEPROM_ADDR_SERIALOUTPUT, SerialOutput); // write byte at address
logtext = F("Serial Output: ");
if (SerialOutput == 1) { // serielle Ausgabe eingeschaltet
logtext += F("on");
} else { // serielle Ausgabe ausgeschaltet
logtext += F("off");
}
}
appendLogFile(logtext);
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.println(logtext);
#endif
}
// Beginn HTML
insertHeaderCSS(sResponse); // Header und CCS einfügen
sResponse += F("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/button.css\">");
insertMenu_Setup(sResponse); // Menu Tabelle Zeile 1 einfügen
insertMenu_Ueberschrift(sResponse); // Überschrift Tabelle Zeile 2 einfügen
// Zeile 3 einfügen
sResponse += F("<tr><td class=\"CXB\" colspan=\"5\">diverse Einstellungen</td></tr>");
// Tabelle Zeile 4 einfügen
sResponse += F("<tr>"
"<td colspan=\"2\" class=\"r\">Zählerstand:</td>"
"<td class=\"r\"><input type=number aria-label=\"Zählerstand\" min=0.00 max=99999.99 step=0.01 name=\"s0count\" maxlength=\"8\" value=\"");
sResponse += s0_count_abs / 100.0;
// sResponse += longToStr(s0_count_abs);
sResponse += F("\"></td>"
"<td>m³</td>"
"<td><button type=\"submit\" name=\"submit\" value=\"saves0count\">Speichern</button></td>"
"</tr>"
// Tabelle Zeile 5 einfügen
"<tr><td colspan=\"2\" class=\"r\">Maximalverbrauch pro Tag:</td>"
"<td class=\"r\">");
sResponse += longToStr(s0_count_max_day); // Maximum pro Tag
sResponse += F("</td>"
"<td>m³</td>"
"<td><button type=\"submit\" name=\"submit\" value=\"resetMaxDay\">Rückstellen</button></td>"
"</tr>"
// Tabelle Zeile 6 einfügen
"<tr><td colspan=\"2\" class=\"r\">Maximalverbrauch pro Monat:</td>"
"<td class=\"r\">");
sResponse += longToStr(s0_count_max_month); // Maximum pro Monat
sResponse += F("</td>"
"<td>m³</td>"
"<td><button type=\"submit\" name=\"submit\" value=\"resetMaxMonth\">Rückstellen</button></td>"
"</tr>"
// Tabelle Zeile 7 einfügen
"<tr><td colspan=\"2\" class=\"r\">Maximalverbrauch pro Jahr:</td>"
"<td class=\"r\">");
sResponse += longToStr(s0_count_max_year); // Maximum pro Jahr
sResponse += F("</td>"
"<td>m³</td>"
"<td><button type=\"submit\" name=\"submit\" value=\"resetMaxYear\">Rückstellen</button></td>"
"</tr>"
// Tabelle Zeile 8 einfügen
"<tr><td colspan=\"2\" class=\"r\">Verbrauch seit ");
unsigned long l = EEPROM_read_long(EEPROM_ADDR_S0TRIP1TIME); // read timestamp
sResponse += DateToString(l); // return Date String from Timestamp
sResponse += F(", ");
sResponse += TimeToStringHM(l); // return Time String from Timestamp
sResponse += F(" Uhr:</td>"
"<td class=\"r\">");
l = EEPROM_read_long(EEPROM_ADDR_S0TRIP1); // read S0-Count Trip begin
sResponse += longToStr(s0_count_abs - l);
sResponse += F("</td>"
"<td>m³</td>"
"<td><button type=\"submit\" name=\"submit\" value=\"sets0trip1\">Rückstellen</button></td>"
"</tr>"
// Tabelle Zeile 9 einfügen
"<tr><td colspan=\"2\" class=\"r\">Verbrauch seit ");
l = EEPROM_read_long(EEPROM_ADDR_S0TRIP2TIME); // read timestamp
sResponse += DateToString(l); // return Date String from Timestamp
sResponse += F(", ");
sResponse += TimeToStringHM(l); // return Time String from Timestamp
sResponse += F(" Uhr:</td>"
"<td class=\"r\">");
l = EEPROM_read_long(EEPROM_ADDR_S0TRIP2); // read S0-Count Trip begin
sResponse += longToStr(s0_count_abs - l);
sResponse += F("</td>"
"<td>m³</td>"
"<td><button type=\"submit\" name=\"submit\" value=\"sets0trip2\">Rückstellen</button></td>"
"</tr>"
// Tabelle Zeile 10 einfügen
"<tr><td colspan=\"2\" class=\"r\">serielle Ausgabe:</td>"
"<td class=\"r\">");
if (SerialOutput == 1) { // serielle Ausgabe eingeschaltet
sResponse += F("ein");
} else { // serielle Ausgabe ausgeschaltet
sResponse += F("aus");
}
sResponse += F("</td>"
"<td> </td>"
"<td><button type=\"submit\" name=\"submit\" value=\"setser\">");
if (SerialOutput == 1) { // serielle Ausgabe eingeschaltet
sResponse += F("ausschalten");
} else { // serielle Ausgabe ausgeschaltet
sResponse += F("einschalten");
}
sResponse += F("</button></td></tr>");
// Footer anhängen und senden
insertFooterSend(sResponse); // Footer anhängen und senden
}
// ############################## Einstellungen MQTT anzeigen ##############################
void SiteSetupMqtt() {
String sResponse = ""; // Response HTML
sResponse.reserve(4096); // ohne: Dauer: 2425 µS, 3162 Byte, Free Heap: 27.27 kB
String qbroker = server.arg("broker"); // Broker
String quser = server.arg("user"); // Username
String qpass = server.arg("pass"); // Passwort
String qport = server.arg("port"); // Port
String qabs = server.arg("abs"); // Zählerstand
String qmom = server.arg("mom"); // Momentanverbrauch
String qrssi = server.arg("rssi"); // WLAN-RSSI
String qrecon = server.arg("recon"); // WLAN-Reconnects
String qivall = server.arg("ivall"); // Intervall
String submit = server.arg("submit"); // welcher Button wurde betätigt
int countargs = server.args(); // Anzahl Argumente
if (countargs != 0) {
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
SerialPrintLine(); // Trennlinie seriell ausgeben
Serial.print(F("MQTT-Broker: "));
Serial.println(qbroker);
Serial.print(F("Username: "));
Serial.println(quser);
Serial.print(F("Passwort: "));
Serial.println(qpass);
Serial.print(F("Port: "));
Serial.println(qport);
Serial.print(F("Intervall: "));
Serial.println(qivall);
Serial.print(F("welcher Button wurde betaetigt(submit): "));
Serial.println(submit);
Serial.print(F("Anzahl Argumente(countargs): "));
Serial.println(countargs);
#endif
if (submit == "connect") { // Button "Verbinden" betätigt
if (qbroker.length() == 0) { // no MQTT Broker given
MqttConnect = false; // MQTT ausschalten
eMqttBroker = ""; // MQTT-Broker löschen
String logtext = F("MQTT disabled");
appendLogFile(logtext);
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.println(logtext);
#endif
if (client.connected()) { // MQTT Broker connected
client.disconnect(); // Disconnects the client
}
EEPROM_write_boolean(EEPROM_ADDR_MQTTCONNECT, MqttConnect); // write MQTT-Connect
EEPROM_write_string(EEPROM_ADDR_MQTTBROKER, eMqttBroker); // write String to EEPROM
} else {
MqttConnect = true; // MQTT einschalten
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.print(F("MQTT: Connect to broker: "));
Serial.print(qbroker);
Serial.print(F(" Port: "));
Serial.println(qport);
#endif
if (client.connected()) { // MQTT Broker connected
client.disconnect(); // Disconnects the client
}
client.setServer(qbroker.c_str(), qport.toInt()); // Sets the server details.
if (quser.length() == 0) { // no MQTT Username
client.connect(OwnStationHostname.c_str()); // Connects the client without authentification
} else {
client.connect(OwnStationHostname.c_str(), quser.c_str(), qpass.c_str()); // Connects with authentification
}
if (client.connected()) { // MQTT Broker connected
eMqttBroker = qbroker; // MQTT-Broker übernehmen
eMqttUsername = quser; // MQTT-Username übernehmen
eMqttPassword = qpass; // MQTT-Password übernehmen
eMqttPort = qport.toInt(); // MQTT-Port übernehmen
String logtext = F("MQTT Broker ");
logtext += (eMqttBroker);
logtext += F(" connected");
appendLogFile(logtext);
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.println(logtext);
#endif
client.publish(OwnStationHostname.c_str(), "Connected"); // publish "Connected"
EEPROM_write_string(EEPROM_ADDR_MQTTBROKER, eMqttBroker); // write String to EEPROM
EEPROM_write_string(EEPROM_ADDR_MQTTUSERNAME, eMqttUsername); // write String to EEPROM
EEPROM_write_string(EEPROM_ADDR_MQTTPASSWORD, eMqttPassword); // write String to EEPROM
EEPROM_write_int(EEPROM_ADDR_MQTTPORT, eMqttPort); // write MQTT Server Port to EEPROM
EEPROM_write_boolean(EEPROM_ADDR_MQTTCONNECT, MqttConnect); // write MQTT-Connect
appendLogFile(F("MQTT server settings saved"));
} else { // Connects the client Error
eMqttBroker = qbroker; // MQTT-Broker übernehmen
String logtext = F("MQTT connect to ");
logtext += (qbroker);
logtext += F(" failed");
appendLogFile(logtext);
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.println(logtext);
#endif
}
}
}
if (submit == "save") { // Button "Speichern" betätigt
if (qabs == "1") { // Zählerstand
eMqttPublish_s0_count_abs = true;
} else {
eMqttPublish_s0_count_abs = false;
}
EEPROM_write_boolean(EEPROM_ADDR_MQTTPUBLISHABS, eMqttPublish_s0_count_abs); // write boolean at address
if (qmom == "1") { // Momentanverbrauch
eMqttPublish_s0_count_mom = true;
} else {
eMqttPublish_s0_count_mom = false;
}
EEPROM_write_boolean(EEPROM_ADDR_MQTTPUBLISHMOM, eMqttPublish_s0_count_mom); // write boolean at address
if (qrssi == "1") { // WLAN-RSSI
eMqttPublish_rssi = true;
} else {
eMqttPublish_rssi = false;
}
EEPROM_write_boolean(EEPROM_ADDR_MQTTPUBLISHRSSI, eMqttPublish_rssi); // write boolean at address
if (qrecon == "1") { // WLAN-Reconnects
eMqttPublish_recon = true;
} else {
eMqttPublish_recon = false;
}
EEPROM_write_boolean(EEPROM_ADDR_MQTTPUBLISHRECON, eMqttPublish_recon); // write boolean at address
eMqttPublish_Intervall = qivall.toInt(); // Intervall
EEPROM_write_byte(EEPROM_ADDR_MQTTINTERVALL, eMqttPublish_Intervall); // write byte at address
appendLogFile(F("MQTT publish settings saved"));
}
}
// Beginn HTML
insertHeaderCSS(sResponse); // Header und CCS einfügen
sResponse += F("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/button.css\">");
insertMenu_Setup(sResponse); // Menu Tabelle Zeile 1 einfügen
insertMenu_Ueberschrift(sResponse); // Überschrift Tabelle Zeile 2 einfügen
// Zeile 3 einfügen
sResponse += F("<tr><td class=\"CXB\" colspan=\"5\">Einstellungen MQTT Server</td></tr>"
// Zeile 4 einfügen
"<tr><td class=\"r\">MQTT-Broker:</td>"
"<td class=\"l\"><input name=\"broker\" autocomplete=\"on\" aria-label=\"Broker\" type=\"text\" maxlength=\"64\" value=\"");
sResponse += eMqttBroker;
sResponse += F("\"></td>"
"<td colspan=\"3\" class=\"l\">(Name oder Adresse, leer um Dienst abzuschalten)</td></tr>"
// Zeile 5 einfügen
"<tr><td class=\"r\">Username:</td>"
"<td colspan=\"4\" class=\"l\"><input name=\"user\" autocomplete=\"username\" aria-label=\"Username\" type=\"text\" maxlength=\"64\" value=\"");
sResponse += eMqttUsername;
sResponse += F("\"></td></tr>"
// Zeile 6 einfügen
"<tr><td class=\"r\">Passwort:</td>"
"<td colspan=\"4\" class=\"l\"><input name=\"pass\" autocomplete=\"current-password\" aria-label=\"Passwort\" type=\"password\" maxlength=\"64\" value=\"");
sResponse += eMqttPassword;
sResponse += F("\"></td></tr>"
// Zeile 7 einfügen
"<tr><td class=\"r\">Port:</td>"
"<td colspan=\"3\" class=\"l\"><input type=\"number\" name=\"port\" aria-label=\"Port\" maxlength=\"5\" value=\"");
sResponse += eMqttPort;
sResponse += F("\"></td>"
"<td><button type=\"submit\" name=\"submit\" value=\"connect\">Verbinden</button></td>"
"</tr>");
// Zeile 8 einfügen
if (webtype == 0) { // Station
if (MqttConnect == false) { // MQTT ausgeschaltet
sResponse += F("<tr><td colspan=\"5\" class=\"c\">MQTT ausgeschaltet.</td></tr>");
} else { // MQTT eingeschaltet
if (client.connected()) { // MQTT Broker connected
//if (MqttConnect == true) {
sResponse += F("<tr><td colspan=\"5\" class=\"c\">MQTT Verbindung hergestellt.</td></tr>");
} else { // MQTT Broker not connected
sResponse += F("<tr><td colspan=\"5\" class=\"cred\">MQTT Verbindung nicht hergestellt! (Status: ");
sResponse += (client.state());
sResponse += F(")</td></tr>");
}
}
} else { // keine Netzwerkverbindung
sResponse += F("<tr><td colspan=\"5\" class=\"cred\">Keine Verbindung mit Netzwerk!</td></tr>");
}
// Zeile 9 einfügen
sResponse += F("<tr><td colspan=\"5\" class=\"CXB\">Publizierung durch Gaszähler</td></tr>"
// Zeile 10 einfügen
"<tr><td class=\"r\">Zählerstand:</td>"
"<td class=\"l\"><input name=\"abs\" aria-label=\"Zählerstand\" type=\"checkbox\" value=\"1\"");
sResponse += (eMqttPublish_s0_count_abs == 1 ? " checked" : "");
sResponse += F("></td><td colspan=\"3\" class=\"l\">");
if (eMqttPublish_s0_count_abs == true) {
sResponse += OwnStationHostname;
sResponse += F("/CountAbs");
} else {
sResponse += F(" ");
}
sResponse += F("</td></tr>"
// Zeile 11 einfügen
"<tr><td class=\"r\">Momentanverbrauch:</td>"
"<td class=\"l\"><input name=\"mom\" aria-label=\"Momentanverbrauch\" type=\"checkbox\" value=\"1\"");
sResponse += (eMqttPublish_s0_count_mom == 1 ? " checked" : "");
sResponse += F("></td><td colspan=\"3\" class=\"l\">");
if (eMqttPublish_s0_count_mom == true) {
sResponse += OwnStationHostname;
sResponse += F("/CountMom");
} else {
sResponse += F(" ");
}
sResponse += F("</td></tr>"
// Zeile 12 einfügen
"<tr><td class=\"r\">RSSI:</td>"
"<td class=\"l\"><input name=\"rssi\" aria-label=\"RSSI\" type=\"checkbox\" value=\"1\"");
sResponse += (eMqttPublish_rssi == 1 ? " checked" : "");
sResponse += F("></td><td colspan=\"3\" class=\"l\">");
if (eMqttPublish_rssi == true) {
sResponse += OwnStationHostname;
sResponse += F("/RSSI");
} else {
sResponse += F(" ");
}
sResponse += F("</td></tr>"
// Zeile 13 einfügen
"<tr><td class=\"r\">Neuverbindungen:</td>"
"<td class=\"l\"><input name=\"recon\" aria-label=\"Neuverbindungen\" type=\"checkbox\" value=\"1\"");
sResponse += (eMqttPublish_recon == 1 ? " checked" : "");
sResponse += F("></td><td colspan=\"3\" class=\"l\">");
if (eMqttPublish_recon == true) {
sResponse += OwnStationHostname;
sResponse += F("/WiFiReconnects");
} else {
sResponse += F(" ");
}
sResponse += F("</td></tr>"
// Zeile 14 einfügen
"<tr><td class=\"r\">Intervall:</td>"
"<td colspan=\"3\" class=\"l\">"
"<select name=\"ivall\" aria-label=\"Intervall\">");
byte intervall[10] = {1, 2, 3, 5, 6, 10, 15, 20, 30, 60};
for (int i = 0; i < 10; ++i) {
sResponse += F("<option");
if (intervall[i] == eMqttPublish_Intervall) {
sResponse += F(" selected=\"\"");
}
sResponse += F(">");
sResponse += intervall[i];
sResponse += F("</option>");
}
sResponse += F("</select> Minuten</td>"
"<td><button type=\"submit\" name=\"submit\" value=\"save\">Speichern</button></td>"
"</tr>");
// Footer anhängen und senden
insertFooterSend(sResponse); // Footer anhängen und senden
}
// ############################## Einstellungen WLAN anzeigen ##############################
void SiteSetupWifi() {
String sResponse = ""; // Response HTML
sResponse.reserve(8192); // ohne: Dauer: 1591774 µS, 3955 Byte, Free Heap: 27.71 kB
IPAddress ipadr; // IP address
char str[18]; // for sprintf IP-Address an MAC
int errorIpAddr = 0; // Error IP address
uint8_t* MAC_CON = WiFi.BSSID(); // Gets the MAC address of the router you are connected to
uint8_t* MAC; // Gets the MAC address of the router
uint8_t countargs = server.args(); // Anzahl Argumente
uint8_t setssid = server.arg("setssid").toInt(); // Auswahl SSID
String hssid = server.arg("hiddenssid"); // Auswahl versteckte SSID
String qpass = server.arg("pw"); // WLAN Passwort
String qdhcp = server.arg("dhcp"); // 1-DHCP ein, 0-DHCP aus
String qip = server.arg("ip"); // IP-Adresse statisch
String qdns = server.arg("dns"); // Domain Name Server statisch
String qsnm = server.arg("sn"); // Subnetzmaske statisch
String qsgw = server.arg("gw"); // Gateway statisch
String submit = server.arg("submit"); // welcher Button wurde betätigt
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
SerialPrintLine(); // Trennlinie seriell ausgeben
Serial.print(F("Anzahl Argumente(countargs): "));
Serial.println(countargs);
#endif
if (submit != "wps") { // bei WPS nicht scannen
//if (countargs == 0 || submit == "rescan") { // erster Aufruf ohne Argumente
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.println(F("Scanne Netzwerke..."));
#endif
WifiNetworks = WiFi.scanNetworks(); // Scanne Netzwerke
}
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.print(F("Anzahl gefundener Netzwerke(networks): "));
Serial.println(WifiNetworks);
String ssid;
int32_t rssi;
uint8_t encryptionType;
uint8_t *bssid;
int32_t channel;
bool hidden;
if (WifiNetworks <= 0) {
Serial.println(F("No networks found"));
} else if (WifiNetworks > 0) {
Serial.printf(PSTR("%d networks found:\n"), WifiNetworks);
// Print unsorted scan results
for (int8_t i = 0; i < WifiNetworks; i++) {
WiFi.getNetworkInfo(i, ssid, encryptionType, rssi, bssid, channel, hidden);
// get extra info
const bss_info *bssInfo = WiFi.getScanInfoByIndex(i);
String phyMode;
const char *wps = "";
if (bssInfo) {
phyMode.reserve(12);
phyMode = F("802.11");
String slash;
if (bssInfo->phy_11b) {
phyMode += 'b';
slash = '/';
}
if (bssInfo->phy_11g) {
phyMode += slash + 'g';
slash = '/';
}
if (bssInfo->phy_11n) {
phyMode += slash + 'n';
}
if (bssInfo->wps) {
wps = PSTR("WPS");
}
}
Serial.printf(PSTR(" %02d: [CH %02d] [%02X:%02X:%02X:%02X:%02X:%02X] %ddBm %c %c %-11s %3S %s\n"), i, channel, bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5], rssi, (encryptionType == ENC_TYPE_NONE) ? ' ' : '*', hidden ? 'H' : 'V', phyMode.c_str(), wps, ssid.c_str());
yield();
}
} else {
Serial.printf(PSTR("WiFi scan error: %d"), WifiNetworks);
}
if (countargs != 0) { // erster Aufruf ohne Argumente
Serial.print(F("Auswahl SSID(setssid): "));
Serial.println(setssid);
Serial.print(F("Auswahl versteckte SSID(hssid): "));
Serial.println(hssid);
Serial.print(F("WLAN Passwort(qpass): "));
Serial.println(qpass);
Serial.print(F("1-DHCP ein, 0-DHCP aus(qdhcp): "));
Serial.println(qdhcp);
Serial.print(F("IP-Adresse statisch(qip): "));
Serial.println(qip);
Serial.print(F("Domain Name Server statisch(qdns): "));
Serial.println(qdns);
Serial.print(F("Gateway statisch(qsgw): "));
Serial.println(qsgw);
Serial.print(F("Subnetzmaske statisch(qsnm): "));
Serial.println(qsnm);
Serial.print(F("welcher Button wurde betaetigt(submit): "));
Serial.println(submit);
}
#endif
// Beginn HTML
insertHeaderCSS(sResponse); // Header und CCS einfügen
sResponse += F("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/button.css\">");
insertMenu_Setup(sResponse); // Menu Tabelle Zeile 1 einfügen
insertMenu_Ueberschrift(sResponse); // Überschrift Tabelle Zeile 2 einfügen
// Zeile 3 einfügen
sResponse += (F("<tr><td class=\"CXB\" colspan=\"5\">Einstellungen WLAN</td></tr>"));
// Zeile 4 einfügen
if (WifiNetworks <= 0 && countargs == 0) { // kein Netzwerk gefunden!
sResponse += F("<tr><td colspan=\"5\" class=\"cred\">"
"<br><br>Kein Netzwerk gefunden!<br><br><br></td></tr>"
"<tr><td colspan=\"2\"></td>"
"<td><button type=\"submit\" name=\"submit\" value=\"rescan\">Scannen</button></td>"
"<td colspan=\"2\"></td></tr>"
"<tr><td colspan=\"5\"><br><br></td></tr>");
} else {
if (submit == "wps") {
//estart = 0; // Zähler zurück setzen
//EEPROM_write_byte(EEPROM_ADDR_START, estart); // write Start Count to EEPROM
sResponse += F("<tr><td colspan=\"5\" class=\"cred\">"
"<br><br>Starte WPS (Wi-Fi Protected Setup)."
"<br>Sollte es nicht gelingen, werden die alten Einstellungen weiter verwendet.<br><br></td></tr>"
"<script>setTimeout(function(){window.location.href='setuplan.htm'},60000);</script>");
// Footer anhängen und senden
insertFooterSend(sResponse); // Footer anhängen und senden
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.println(F("WPS-Button pressed"));
Serial.println(F("Wait 1 second for sending website"));
#endif
delay(1000); // wait for sending website
// starte WiFi Protected Setup (WPS)
if (!start_WPS_connect()) { // Wifi WPS Connection failed
String logText = F("Wifi WPS connection failed, restart");
appendLogFile(logText);
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.println(logText);
#endif
delay(1000);
ESP.restart();
}
}
if (submit == "save") {
if (qdhcp == "1") { // DHCP ein
edhcp = true;
} else { // DHCP aus
edhcp = false;
byte ipaddress[4];
if (str2ip((char*)qip.c_str(), ipaddress)) { // convert String to Array of 4 Bytes
eip = ipaddress; // statische IP übernehmen
EEPROM_write_ipaddress(EEPROM_ADDR_IP, eip); // write IPAddress to EEPROM
} else {
errorIpAddr = 1; // Error IP address
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.println(F("ERROR static IP-Address"));
#endif
}
if (str2ip((char*)qsgw.c_str(), ipaddress)) { // convert String to Array of 4 Bytes
esgw = ipaddress; // Standard-Gateway übernehmen
EEPROM_write_ipaddress(EEPROM_ADDR_GATEWAY, esgw); // write IPAddress to EEPROM
} else {
errorIpAddr = 2; // Error IP address
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.println(F("ERROR Standard-Gateway"));
#endif
}
if (str2ip((char*)qdns.c_str(), ipaddress)) { // convert String to Array of 4 Bytes
edns = ipaddress; // statischen Domain Name Server übernehmen
EEPROM_write_ipaddress(EEPROM_ADDR_DNS, edns); // write IPAddress to EEPROM
} else {
errorIpAddr = 3; // Error IP address
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.println(F("ERROR Domain Name Server"));
#endif
}
if (str2ip((char*)qsnm.c_str(), ipaddress)) { // convert String to Array of 4 Bytes
esnm = ipaddress; // Subnetmask übernehmen
EEPROM_write_ipaddress(EEPROM_ADDR_NETMASK, esnm); // write IPAddress to EEPROM
} else {
errorIpAddr = 4; // Error IP address
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.println(F("ERROR Subnetmask"));
#endif
}
}
if (errorIpAddr == 0) { // no Error IP address
EEPROM_write_boolean(EEPROM_ADDR_DHCP, edhcp); // write EEPROM DHCP on or off
}
}
// neue Tabelle innerhalb Zeile 4
sResponse += F("<tr><td colspan=\"5\" class=\"c\">"
// neue Tabelle
"<table class=\"table802\">"
// neue Tabelle Zeile 1 Überschrift
"<tr>"
"<th class=\"tdW6p\"> </th>"
"<th class=\"l\">Name (SSID)</th>"
"<th>MAC-Adresse</th>"
"<th>Kanal</th>"
"<th>RSSI</th>"
"<th>Verschlüsselung</th>"
"</tr>");
// neue Tabelle Netzwerke auflisten ab Zeile 2
for (int8_t i = 0; i < WifiNetworks; ++i) {
String wifiSSID = WiFi.SSID(i);
sResponse += F("<tr>"
// Spalte 1
"<td><input type=\"radio\" name=\"setssid\" aria-label=\"SSID\" value=\"");
sResponse += i; // Nr. in Array
sResponse += F("\"");
MAC = WiFi.BSSID(i); // Gets the MAC address of the router
if (memcmp(MAC, MAC_CON, 6) == 0) { // Compare two blocks of memory
sResponse += (wifiSSID == essid ? " checked" : "");
}
sResponse += F("></td>"
// Spalte 2
"<td class=\"l\">");
sResponse += wifiSSID; // Beschriftung
sResponse += F("</td>"
// Spalte 3
"<td>");
sprintf(str, "%02X:%02X:%02X:%02X:%02X:%02X", MAC[0], MAC[1], MAC[2], MAC[3], MAC[4], MAC[5]);
sResponse += str;
sResponse += F("</td>"
// Spalte 4
"<td class=\"c\">");
sResponse += WiFi.channel(i);
sResponse += F("</td>"
// Spalte 5
"<td class=\"c\">");
sResponse += WiFi.RSSI(i);
sResponse += F(" dB</td>"
// Spalte 6
"<td class=\"c\">");
switch (WiFi.encryptionType(i)) {
case 2:
sResponse += F("WPA (TKIP)");
break;
case 4:
sResponse += F("WPA2 (CCMP)");
break;
case 5:
sResponse += F("WEP");
break;
case 7:
sResponse += F("NONE");
break;
case 8:
sResponse += F("AUTO");
break;
default:
sResponse += F("unknown");
break;
}
sResponse += F("</td></tr>");
}
// neue Tabelle letzte Zeile Eingabefeld SSID
sResponse += F("<tr><td><input name=\"setssid\" aria-label=\"SSID\" type=\"radio\" value=\"255\"></td>"
"<td class=\"l\"><input class=\"iW80p\" name=\"hiddenssid\" autocomplete=\"on\" aria-label=\"SSID\" type=\"text\" maxlength=\"32\"></td>"
"<td colspan=\"4\"> </td></tr>"
// neue Tabelle Ende und Ende Zeile 4
"</table></td></tr>"
// Zeile 5 einfügen
"<tr><td><button type=\"submit\" name=\"submit\" value=\"wps\">WPS</button></td>"
"<td class=\"r\">Passwort:</td>"
"<td colspan=\"2\" class=\"l\"><input class=\"iW70p\" name=\"pw\" autocomplete=\"current-password\" aria-label=\"Passwort\" type=\"password\" maxlength=\"64\"></td>"
"<td><button type=\"submit\" name=\"submit\" value=\"connect\">Verbinden</button></td></tr>");
if (submit == "connect") {
// ################## new ##################
String qssid = "";
if (setssid == 255) { // verstecktes Netzwerk
qssid = hssid; // versteckte SSID übernehmen
} else {
qssid = WiFi.SSID(setssid);
}
if (qssid.length() > 0 && qssid.length() < 32 && qpass.length() > 0 && qpass.length() < 64) {
// ################## new ##################
sResponse += F("<tr><td colspan=\"5\" class=\"cred\">"
"Versuche Verbindung zum Netzwerk ");
sResponse += qssid;
sResponse += F(" herzustellen.<br>Sollte es nicht gelingen, werden die alten Einstellungen weiter verwendet.</td></tr>"
"<script>setTimeout(function(){window.location.href='setuplan.htm'},60000);</script>");
// Footer anhängen und senden
insertFooterSend(sResponse); // Footer anhängen und senden
delay(1000);
if (webtype == 1) { // Accesspoint
WiFi.softAPdisconnect(false); // Accesspoint nicht abschalten
WiFi.mode(WIFI_AP_STA); // Accesspoint und Station
} else {
WiFi.mode(WIFI_STA); // Station
}
WiFi.disconnect();
String logtext = F("Wifi try new connect to: ");
logtext += qssid;
appendLogFile(logtext);
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.println("");
Serial.println(logtext);
#endif
if (edhcp == false) { // DHCP aus
WiFi.config(eip, esgw, esnm, edns); // Style ESP8266
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.println(F("DHCP off, use static IP"));
#endif
} else { // DHCP ein
wifi_station_dhcpc_start();
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.println(F("DHCP on"));
#endif
}
if (setssid == 255) { // verstecktes Netzwerk
WiFi.begin(qssid.c_str(), qpass.c_str()); // Connect to hidden Network
} else {
MAC_CON = WiFi.BSSID(setssid); // Gets the MAC address of the router
uint8_t usedChannel = WiFi.channel(setssid);
#ifdef DEBUG_OUTPUT_SERIAL_WIFI
Serial.print(F("use AP MAC "));
sprintf(str, "%02X:%02X:%02X:%02X:%02X:%02X", MAC_CON[0], MAC_CON[1], MAC_CON[2], MAC_CON[3], MAC_CON[4], MAC_CON[5]);
Serial.print(str);
Serial.print(F(", "));
Serial.println(usedChannel);
#endif
WiFi.begin(qssid.c_str(), qpass.c_str(), usedChannel, MAC_CON); // Connect to new Network
}
if (testWifi()) {
essid = qssid; // SSID übernehmen
epass = qpass; // Wifi Passwort übernehmen
EEPROM_write_string(EEPROM_ADDR_SSID, essid); // write String to EEPROM
EEPROM_write_string(EEPROM_ADDR_PASS, epass); // write String to EEPROM
appendLogFile(F("Wifi settings saved"));
// zusätzliche Zeile einfügen bei Connect
sResponse += (F("<tr><td colspan=\"5\" class=\"c\">Verbunden mit Netzwerk: "));
sResponse += essid;
sResponse += (F("</td></tr>"));
} else {
connectWifiBestRssi(); // connect to AP with best RSSI
// WiFi.begin(essid.c_str(), epass.c_str()); // Connect to saved Network
if (testWifi()) {
// zusätzliche Zeile einfügen bei Connect
sResponse += (F("<tr><td colspan=\"5\" class=\"c\">Verbunden mit Netzwerk: "));
sResponse += essid;
sResponse += (F("</td></tr>"));
}
}
} else {
// zusätzliche Zeile einfügen bei Fehler Name (SSID) oder Passwort zu kurz
sResponse += (F("<tr><td colspan=\"5\" class=\"cred\">Name (SSID) oder Passwort zu kurz oder zu lang!</td></tr>"));
}
}
// Zeile 6 einfügen
sResponse += F("<tr><td class=\"CXB\" colspan=\"5\">Netzwerk</td></tr>"
// Zeile 7 einfügen
"<tr><td class=\"r\"><input type=\"radio\" name=\"dhcp\" aria-label=\"DHCP\" value=\"1\"");
if (edhcp == true) sResponse += (F(" checked")); // DHCP ein
sResponse += F("></td>"
"<td colspan = \"2\">IP-Adresse automatisch (DHCP)</td>"
"<td colspan=\"2\">");
if (edhcp == true) { // DHCP ein
ipadr = WiFi.localIP();
sprintf(str, "%d.%d.%d.%d", ipadr[0], ipadr[1], ipadr[2], ipadr[3]);
sResponse += str;
} else { // DHCP aus
sResponse += (F(" "));
}
sResponse += F("</td></tr>"
// Zeile 8 einfügen
"<tr><td class=\"r\"><input type=\"radio\" name=\"dhcp\" aria-label=\"DHCP\" value=\"0\"");
if (edhcp == false) sResponse += (F(" checked")); // DHCP aus
sResponse += F("></td>"
"<td colspan=\"2\">IP-Adresse statisch</td>"
"<td colspan=\"2\">"
"<input name=\"ip\" aria-label=\"IP\" type=\"text\" id=\"ip\" maxlength=\"15\" value=\"");
sprintf(str, "%d.%d.%d.%d", eip[0], eip[1], eip[2], eip[3]);
sResponse += str;
sResponse += F("\"></td></tr>"
// Zeile 9 einfügen
"<tr><td colspan=\"3\" class=\"r\">Domain Name Server:</td>"
"<td colspan=\"2\">"
"<input name=\"dns\" aria-label=\"DNS\" type=\"text\" id=\"dns\" maxlength=\"15\" value=\"");
if (edhcp == false) { // DHCP aus
ipadr = edns; // Domain Name Server übernehmen
} else { // DHCP ein
ipadr = WiFi.dnsIP();
}
sprintf(str, "%d.%d.%d.%d", ipadr[0], ipadr[1], ipadr[2], ipadr[3]);
sResponse += str;
sResponse += F("\"></td></tr>"
// Zeile 10 einfügen