-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathESP32_32x32RGBMatrix.ino
1520 lines (1304 loc) · 43.6 KB
/
ESP32_32x32RGBMatrix.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
/*
* ESP32 Dev Module 80MHz
* WROOM32 it will indeed be 4MB (= 32Mbit).
*
*
* Serial input:
* setssid= SSID for WLAN
* setpass= Passwort for WLAN
* sethost= hostname for WLAN
* ESP=reboot reboot ESP
* ESP=getssid show SSID
* ESP=getpass show Password
* ESP=gethost show esp_hostname
* ESP=gettime show lokaltime
* ESP=getdate show lokaldate
* ESP=hatntp show true when set time/date from NTP
* ESP=getwifistat
*
*
https://github.com/bbx10/WebServer_tng
https://github.com/gmag11/NtpClient/blob/master/src/NTPClientLib.cpp
https://github.com/arduino-libraries/NTPClient/issues/36
https://tools.ietf.org/html/rfc958
https://github.com/esp8266/Arduino/blob/master/doc/filesystem.rst
http://esp-idf.readthedocs.io/en/latest/api-guides/wifi.html#system-event-sta-connected
https://github.com/VGottselig/ESP32-RGB-Matrix-Display
https://techtutorialsx.com/2017/05/09/esp32-running-code-on-a-specific-core/
https://techtutorialsx.com/2017/10/07/esp32-arduino-timer-interrupts/
http://www.iotsharing.com/2017/07/how-to-configure-esp32-multicore-arduino-esp32.html
http://esp-idf.readthedocs.io/en/latest/api-reference/system/freertos.html
https://techtutorialsx.com/2017/05/09/esp32-running-code-on-a-specific-core/
http://hit-karlsruhe.de/hit-info/info-ws17/Drehteller_Revisited/0403Softwaredoku.html
https://www.studocu.com/en-gb/document/deakin-university/modern-data-science/lecture-notes/kolban-esp32-esp32-documents-for-iot/1423897/view
Filter: setup.ini wird nicht ausgeliefert
*/
#include <WiFi.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <time.h>
//https://github.com/bbx10/WebServer_tng
#include "WebServer.h"
#include "FS.h"
#include "SPIFFS.h"
#include "myNTP.h"
myNTP oNtp;
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "Adafruit_GFX.h"
#include "ESP32RGBmatrixPanel.h"
/*#define COLUMNS 32
#define ROWS 32*/
WebServer server(80);
ESP32RGBmatrixPanel matrix;
//32x32*3 =3072byte/Frame = 3kb 10 Frames=30kb
#define BUFSIZ 255
int anifilepos=0;
int anifileframecounter=0;
String drawmodus="";
//ESP32RGBmatrixPanel matrix(23, 22, 03, 17, 16, 04, 00, 02, 15, 21, 19, 18, 5); //Flexible connection
//Default connection
//uint8 OE = 23;
//uint8 CLK = 22;
//uint8 LAT = 03;
//uint8 CH_A = 21;
//uint8 CH_B = 19;
//uint8 CH_C = 18;
//uint8 CH_D = 5;
//uint8 R1 = 17;
//uint8 G1 = 16;
//uint8 BL1 = 4;
//uint8 R2 = 0;
//uint8 G2 = 2;
//uint8 BL2 = 15;
const char* progversion = "32x32 RGB-Matrix V0.56";//ota fs ntp ti ini rgb
String ssid = "42"; //set per serial: setssid=
String password = "";//set per serial: setpass=
String esp_hostname = "rgbmatrix"; //nur zeichen und "-" keine "_"!
#define LED_PIN 2 //gpio05 D1
File fsUploadFile; //Hält den aktuellen Upload
String basichtml = "<html><head><title>esp32 "+String(progversion)+"</title>\r\n"
"<meta charset=\"utf-8\"/>"
"<link rel=\"shortcut icon\" href=\"favicon.ico\">"
"<link rel=\"STYLESHEET\" type=\"text/css\" href=\"style.css\">"
"<script type=\"text/javascript\" src=\"script.js\"></script>"
"</head><body>\r\n";
uint8_t MAC_array[6];
char MAC_char[18];
String macadresse="";
bool wifiaktiv=false;
#define dateiBUFSIZ 51200 //200kb
char dateipuffer[dateiBUFSIZ];
int dateiMax=0;
//dateipuffer[0]='\0';
unsigned long uhr_previousMillis=0;
unsigned long uhr_zeitchecker= 1000;//ms = 1sec
unsigned long tim_previousMillis=0;
unsigned long tim_zeitchecker= 15*1000;//15sec
bool istupdating=false;
TaskHandle_t xHandleRenderTask;
TaskHandle_t xHandleDrawTask;
TaskHandle_t xHandleCoreTask;
String playfile="";
bool DisplayOn=true;
bool timeriststopped=false;
int requeststopp=0;
//https://github.com/espressif/arduino-esp32/issues/855
//IRAM_ATTR tells the complier, that this code Must always be in the
//ESP32's IRAM, the limited 128k IRAM. use it sparingly.
hw_timer_t* displayUpdateTimer = NULL;
void IRAM_ATTR onDisplayUpdate() {
matrix.update();//16x16x10
}
void IRAM_ATTR playafileframe(int16_t framedelay){//40ms=25fps
if(dateiMax<1)return;
File aniFile;
int zeichen=0;
char clientline[BUFSIZ+1]; //inputzeile max.256 Zeichen
int buffpos=0;
bool framereading=true;
anifileframecounter-=framedelay;//verstrichene Zeit abziehen
if(anifileframecounter>0)return;//abzuwartende Zeit noch nicht vergangen, abrechen und warten
//Zeit abgelaufen, lese Frame
anifileframecounter=0;
if(anifilepos>dateiMax-1)anifilepos=0;
while (framereading){
zeichen=dateipuffer[anifilepos];
anifilepos++;
buffpos=0;
while(zeichen>31){ //Dateiende(-1)oder eine Zeileende ('\n'=13)
clientline[buffpos] =zeichen;//Array of Chars
buffpos++;
if (buffpos >= BUFSIZ-1){framereading=false;break;}//Buffer am überlaufen, abbrechen
zeichen=dateipuffer[anifilepos];
anifilepos++;
}
clientline[buffpos]=0; //null terminierunng
if(buffpos>1){//Zeile auswerten
//zeilenende, zeile auswerten & zeichnen
if (clientline[0]=='d'){
//Frame fertig, set new delaytime
anifileframecounter=get_int(clientline,1,4)-framedelay;//
if(anifileframecounter<0)anifileframecounter=0;
framereading=false;
//fertig break->while (iniFile.available())
}
//Zeichenbefehle
drawBefehl(clientline);
}
if(zeichen<0 || (anifilepos>dateiMax-1) ){ //dateiende
anifilepos=0;//Dateizeiger auf Anfang
framereading=false; //fertig break->while (iniFile.available())
}
}
}
#define renderframedelay 40 //ms 40=25fps
void IRAM_ATTR drawTask( void * pvParameters ){
//String taskMessage = ">>>Task running on core ";
// taskMessage = taskMessage + xPortGetCoreID();
int lavercounter = 0;
int stepp=16;
int steppDir=1;
while(true){
if(DisplayOn){
if(playfile!=""){
playafileframe(renderframedelay);
}
else
if(drawmodus=="drawpic"){
//nix tun
}
else
{
//testscreen of off
//text
matrix.setBrightness(10);//0..10
//matrix.setTextWrap(false);
//matrix.setTextSize(1);
matrix.black();//alles löschen
//blinkender richtungsloser Fleck
/*
lavercounter+=(stepp*steppDir);
if(lavercounter>=255){steppDir=-1;lavercounter=255;}
if(lavercounter<=0) {steppDir= 1;lavercounter=0;}
matrix.fillCircle(15, 16, 11, matrix.AdafruitColor(lavercounter,lavercounter,0) );//int16_t
*/
//testlines RGBW
byte i;
for(i=0;i<32;i++){
matrix.drawPixel(i, 28, i*8, 0, 0);
matrix.drawPixel(i, 29, 0,i*8, 0);
matrix.drawPixel(i, 30, 0,0,i*8);
matrix.drawPixel(i, 31, i*8,i*8,i*8);
}
byte ntp_stunde =oNtp.getstunde();
byte ntp_minute =oNtp.getminute();
//byte ntp_secunde =oNtp.getsecunde();
String s="";
if(ntp_stunde<10)s+="0";
s+=String(ntp_stunde)+":";
if(ntp_minute<10)s+="0";
s+=String(ntp_minute);
//Time
matrix.setCursor(1, 0);
matrix.setTextColor(matrix.AdafruitColor(0,255,0));
matrix.println(s);
//Datum
s="";
if(oNtp.getday()<10)s+="0";
s+=String(oNtp.getday())+".";
if(oNtp.getmonth()<10)s+="0";
s+=String(oNtp.getmonth())+".";
matrix.setCursor(1, 10);
matrix.setTextColor(matrix.AdafruitColor(255,255,0));
matrix.println(s);
delay(500-renderframedelay);
//Sekunden
/* matrix.setTextColor(matrix.AdafruitColor(255,255,255));
matrix.setCursor(10, 10);
s="";
if(ntp_secunde<10)s="0";
s+=String(ntp_secunde);
matrix.println(s);
*/
}
}else{//display off
if(drawmodus!="drawpic")
matrix.black();
}
//delay(40);//40ms=25fps
delay(renderframedelay);//25fps
}
}
bool beginWiFi(){
//get ssid/pass wenn definiert
String s;
s=getINI("ssid");
if(s.length()>0){
Serial.println("get SSID "+s);
ssid=s;
}
s=getINI("pass");
if(s.length()>0){
//Serial.println("get pass "+s);
Serial.println("get pass ***");
password=s;
}
s=getINI("host");
if(s.length()>0){
Serial.println("get hostname "+s);
esp_hostname=s;
}
if(ssid.length()==0 || password.length()==0){
Serial.print(":-/ please");
if(ssid.length()==0)
Serial.print("set SSID (setssid=) ");
if(password.length()==0)
Serial.print("set Pass (setpass=) ");
Serial.println(String(ssid.length())+" "+String(password.length()));
return false;
}
if(esp_hostname.length()>0){
char charBufHostname[255];
esp_hostname.toCharArray(charBufHostname,255);
WiFi.setHostname(charBufHostname);
}
char charBufSSID[255];
char charBufPASS[255];
ssid.toCharArray(charBufSSID,255);
password.toCharArray(charBufPASS,255);
WiFi.begin(charBufSSID,charBufPASS);
return true;
}
void setup() {
Serial.begin(115200);
Serial.print("Booting ");
Serial.println(progversion);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, true);
dateipuffer[0]=0;
//SPIFFS
SPIFFS.begin();
//WIFI
WiFi.mode(WIFI_STA);
WiFi.onEvent(WiFiEvent);
if(!beginWiFi()){Serial.println("no WIFI");return;}
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("Connection Failed! Rebooting...");
delay(6000);
ESP.restart();
}
wifiaktiv=true;
//get MAC
WiFi.macAddress(MAC_array);
for (int i = 0; i < sizeof(MAC_array); ++i) {
if(i>0) macadresse+=":";
macadresse+= String(MAC_array[i], HEX);
//sprintf(MAC_char, "%s%02x:", MAC_char, MAC_array[i]);
}
Serial.print("MAC: ");
Serial.println(macadresse);
//Online Update
ArduinoOTA
.onStart([]() {
istupdating=true;
playfile="";
stoppTimer(true);
vTaskDelete(xHandleDrawTask);
String type;
if (ArduinoOTA.getCommand() == U_FLASH)
type = "sketch";
else // U_SPIFFS
type = "filesystem";
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
Serial.println("Start updating " + type);
})
.onEnd([]() {
istupdating=false;
Serial.println("\nEnd");
})
.onProgress([](unsigned int progress, unsigned int total) {
digitalWrite(LED_PIN, true);
Serial.print(".");
if( (progress / (total / 100)) == int(progress / (total / 100)/10 )*10 ){
Serial.printf(" %u%%\r ", (progress / (total / 100)));
Serial.println("");
digitalWrite(LED_PIN, false);
}
})
.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});
if(esp_hostname.length()>0){
char charBufHostname[255];
esp_hostname.toCharArray(charBufHostname,255);
ArduinoOTA.setHostname(charBufHostname);
}
ArduinoOTA.begin();
//Webserver
server.on("/",handleRoot);
server.on("/index.htm",handleRoot);
server.on("/index.html",handleRoot);
server.on("/setup.ini",handleunauthorizedfiles);//niemals ausliefern, nur für Debugzwecke auskommentieren
server.on("/data.json", handleData);
server.on("/setup.htm",handleSetup);
server.on("/aktion",handleaktion);
server.on("/draw.ard", handleDraw );//Bild direkt anzeigen
//upload
server.on("/upload", HTTP_POST, []() {
server.send(200, "text/plain", "");
}, handleFileUpload);
server.onNotFound(handleNotFound);//Dateien vom Speicher oder 404
server.begin();
//NTP start
oNtp.begin();
digitalWrite(LED_PIN, false);
Serial.println("TaskCreate");
//RGBMatrix
// Adafruit_GFX
matrix.setBrightness(10);//0..10
matrix.setTextWrap(false);
matrix.setTextSize(1);
String Faktiv=getINI("aniaktiv");
if(Faktiv!="")
setplayfiledata(Faktiv);
//"PRO_CPU" and "APP_CPU".
//Serial.println("Starting to create task on core 1");
xTaskCreatePinnedToCore(
drawTask, // Function to implement the task
"drawTask", // Name of the task
10000, // Stack size in words
NULL, //Task input parameter
2 , // 1 Priority of the task
&xHandleDrawTask, // Task handle.
0); // tskNO_AFFINITY 0/1 Core where the task should run
xTaskCreatePinnedToCore(
coreTask, // Function to implement the task
"coreTask", // Name of the task
10000, // Stack size in words
NULL, //Task input parameter
1, // 1| portPRIVILEGE_BIT Priority of the task
&xHandleCoreTask, // Task handle.
0);
//us 1 second is 1.000.000us = 1000ms 1ms=1000us 1us=0,001ms 2us=0,002ms
// 1 tick take 1/(80MHZ/80) = 1us so we set divider 80 and count up
displayUpdateTimer = timerBegin(0, 80, true);//id,divider,countUp, true=edge type
// Attach onTimer function to our timer
timerAttachInterrupt(displayUpdateTimer, &onDisplayUpdate, true);//timer,function,
timerAlarmWrite(displayUpdateTimer, 2, true);//2 *timer,interruptAt,autoreload
//2=ms wenn 80 for the prescaler
timerAlarmEnable(displayUpdateTimer);
/**/
//Serial.println(portPRIVILEGE_BIT);=0
Serial.println("Ready");
}
void stoppTimer(bool matrixblank){
requeststopp++;
if(timeriststopped)return;
timeriststopped=true;
if(matrixblank){
matrix.black();
matrix.update();
matrix.update();
}
timerDetachInterrupt(displayUpdateTimer);
timerStop(displayUpdateTimer);
timerAlarmDisable(displayUpdateTimer);//
timerEnd(displayUpdateTimer);
displayUpdateTimer=NULL;
}
void startTimer(){
requeststopp--;
if(!timeriststopped)return;
if(requeststopp>0)return;
displayUpdateTimer = timerBegin(0, 80, true);//id,divider,countUp, true=edge type
timerAttachInterrupt(displayUpdateTimer, &onDisplayUpdate, true);//timer,function,
timerAlarmWrite(displayUpdateTimer, 2, true);//2 *timer,interruptAt,autoreload
//timerStart(displayUpdateTimer);
timerAlarmEnable(displayUpdateTimer);
timeriststopped=false;
}
void coreTask( void * pvParameters ){
//String taskMessage = ">>>Task running on core ";
//taskMessage = taskMessage + xPortGetCoreID();
//int ctcounter=0;
while(true){
handleSerial();
if(!istupdating){
if(wifiaktiv){
ArduinoOTA.handle();
server.handleClient();
oNtp.update();
handleTime();
}
}
delay(100);
}
vTaskDelete( NULL );
}
void loop() {// the main loop functions execute on core 1
// while (true){}
}
//------------------------------------------------------------------------------------------
void handleTime(){
unsigned long currentMillis = millis();
/*if(oNtp.hatTime() && currentMillis - tim_previousMillis > tim_zeitchecker){//Timer checken
tim_previousMillis = currentMillis;
if(last_minute!=oNtp.getminute()){//nur 1x pro min
checktimer();
last_minute=oNtp.getminute();
}
}
*/
}
//-----INI-----
String getINI(String name){//setup, serial.read
String re="";
File iniFile;
String zeile;
char zeichen;
int pos;
if(SPIFFS.exists("/setup.ini")){
iniFile = SPIFFS.open("/setup.ini", "r");
if(iniFile){
while (iniFile.available()){
zeichen=char(iniFile.read());
if(zeichen==char(10)){
pos=zeile.indexOf("=");
String sname =zeile.substring(0,pos);
String svalue=zeile.substring(pos+1);
pos=svalue.indexOf(";");
if(pos>0)svalue=svalue.substring(0,pos);
if(sname==name){
re=svalue;
}
zeile="";
}else{
zeile +=zeichen;
}
}
}
}
return re;
}
bool setINI(String name,String wert){
bool re=false;
bool ersetzt=false;
File iniFile;
String zeile;
String newfiledata="";
char zeichen;
int pos;
Serial.print("saveINI "+name+"="+wert+" ");
//save in setup.ini
if(SPIFFS.exists("/setup.ini")){
iniFile = SPIFFS.open("/setup.ini", "r");
if(iniFile){
//chek ob Wert vorhanden, wenn dann Zeile ersetzen
zeile="";
while (iniFile.available()){
zeichen=char(iniFile.read());
if(zeichen==char(10)){
pos=zeile.indexOf("=");
String sname =zeile.substring(0,pos);
if(sname==name){
if(wert.length()>0)
newfiledata+=name+"="+wert+";"+char(10);
else{
Serial.print("deleted ");
}
ersetzt=true;
}
else
newfiledata+=zeile+char(10);
zeile="";
}else{
zeile +=zeichen;
}
}
iniFile.close();
if(!ersetzt){//add wenn nicht existent und nicht leer
if(wert.length()>0)
newfiledata+=name+"="+wert+";"+char(10);
}
//save
iniFile = SPIFFS.open("/setup.ini", "w");
if(iniFile){
iniFile.print(newfiledata);
re=true;Serial.println("OK");
}
}
}
else{
iniFile = SPIFFS.open("/setup.ini", "w");
if(iniFile){
iniFile.println(name+"="+wert+";");
re=true;
Serial.println(" create OK");
}
}
iniFile.close();
if(re==false) Serial.println("ERR");
return re;
}
//------Serial----------
void handleSerial(){
int serialcountin=Serial.available();
if (serialcountin > 0) {//Get the number of bytes (characters) available for reading from the serial port
// read the incoming byte:
String instr="";
byte inp;
int pos;
for(int i=0;i<serialcountin;i++){
inp=Serial.read();//10=LF
if(inp>31)
instr+= (char)inp;
}
pos=instr.indexOf("=");//befehl=value
if(pos>-1){
String sname=instr.substring(0,pos);
String svalue=instr.substring(pos+1);
Serial.println("Serialinput Name:"+sname+" Wert:"+svalue);
if(sname=="setssid")
{ssid=svalue;
stoppTimer(false);
setINI("ssid",svalue);
startTimer();
}
else
if(sname=="setpass")
{
ssid=svalue;
stoppTimer(false);
setINI("pass",svalue);
startTimer();
}
else
if(sname=="sethost"){
esp_hostname=svalue;
stoppTimer(false);
setINI("host",svalue);
startTimer();
}
else
if(sname=="ESP" ){
Serial.print("ESP ");
if(svalue=="reboot"){
Serial.println("start reboot");
ESP.restart();
}
else
if(svalue=="getssid")
{
Serial.println(getINI("ssid"));
}
else
if(svalue=="getpass")
{
Serial.println(getINI("pass"));
}
else
if(svalue=="gethost")
{
Serial.println(getINI("host"));
}
else
if(svalue=="gettime")
{
byte ntp_stunde =oNtp.getstunde();
byte ntp_minute =oNtp.getminute();
byte ntp_secunde =oNtp.getsecunde();
if(ntp_stunde<10)Serial.print("0");
Serial.print(String(ntp_stunde)+":");
if(ntp_minute<10)Serial.print("0");
Serial.print(String(ntp_minute)+":");
if(ntp_secunde<10)Serial.print("0");
Serial.println(String(ntp_secunde));
}
else
if(svalue=="getdate")
{
if(oNtp.getday()<10)Serial.print("0");
Serial.print(String(oNtp.getday())+".");
if(oNtp.getmonth()<10)Serial.print("0");
Serial.println(String(oNtp.getmonth())+"."+String(oNtp.getyear()));
}
else
if(svalue=="getwifistat")
{
if(wifiaktiv)
Serial.println("true");
else
Serial.println("false");
}
else
if(svalue=="hatntp")
{
if(oNtp.hatTime())
Serial.println("true");
else
Serial.println("false");
}
else
{
Serial.println(svalue);
}
}else{
// saveINI(sname,svalue);
//Serial.println("read "+sname+'='+svalue);
}
}
else{
// say what you got:
Serial.print("I received: "+instr+" ");
Serial.print(serialcountin);
Serial.println(" byte");
}
//Serial.println(incomingByte, DEC);
}
}
void handleaktion(){//HTTP: /aktion?refresh=605
stoppTimer(true);
String message = "{\r\n";
String aktionen = "";
for (uint8_t i = 0; i < server.args(); i++) {
if (server.argName(i) == "settimekorr") {
oNtp.setTimeDiff(server.arg(i).toInt());
aktionen +="set_timekorr ";
message +="\"settimekorr\":\"true\",\r\n";
}
if (server.argName(i) == "sethost") {
esp_hostname= server.arg(i);
aktionen +="set_host ";
message +="\"sethost\":\""+esp_hostname+"\",\r\n";
setINI("host",esp_hostname);
}
if (server.argName(i) == "play") {
//load file to playfiledata
Serial.print("play ");
Serial.println(server.arg(i));
setplayfiledata(server.arg(i));
aktionen +="play ";
message +="\"play\":\""+server.arg(i)+"\",\r\n";
}
if (server.argName(i) == "stop") {
playfile="";
setINI("aniaktiv","");
aktionen +="stop ";
message +="\"stop\":\""+server.arg(i)+"\",\r\n";
Serial.println("stop");
}
if (server.argName(i) == "display") {
message +="\"display\":";
if (server.arg(i) == "on" ){
DisplayOn=true;
message +="true";
}
else{
DisplayOn=false;
message +="false";
}
message +=",\r\n";
}
/* if (server.argName(i) == "led") {
if (server.arg(i) == "on" ){
digitalWrite(LED_PIN, true);
aktionen +="LED_ON ";
}
if (server.arg(i) == "off"){
digitalWrite(LED_PIN, false);
aktionen +="LED_OFF ";
}
}*/
}
message +="\"aktionen\":\""+aktionen+"\"\r\n";
message +="}";
server.send(200, "text/html", message );
startTimer();
}
void handleRoot()
{
stoppTimer(true);
if(!handleFileRead("/index.htm")){
String html = basichtml;
html+="<h1>"+String(progversion)+"</h1>\r\n";
html+="<p>:-)</p>\r\n";
html+="<nav>";
html+="<a href=\"/setup.htm\">setup</a>\r\n";
html+="</nav>";
html+="</body>\r\n</html>\r\n";
server.setContentLength(html.length());
server.send(200,"text/html",html);
}
startTimer();
}
void handleunauthorizedfiles(){
stoppTimer(true);
String html = "Dateizugriff nicht erlaubt (Code 403: Forbidden).\r\n";
server.setContentLength(html.length());
server.send(403,"text/html",html);
startTimer();
}
void handleDraw(){
String html = "{}";
drawmodus="drawpic";
if(playfile!=""){
stoppTimer(true);
setINI("aniaktiv","");
playfile="";
startTimer();
}
char clientline[BUFSIZ+1]; //inputzeile max.256 Zeichen !
char cbuffer[BUFSIZ+1]; //inputzeile max.256 Zeichen !
int buffpos=0;
uint8_t ib=0;
//
for (uint8_t i = 0; i < server.args(); i++) {
if (server.argName(i) == "draw") {
//server.arg(i)// draw=f000
//stoppTimer(false);
//String s=server.arg(i); //test auf "," ->mehrere Befehle
server.arg(i).toCharArray(clientline, BUFSIZ+1); //in Array of Char konvertieren
if(server.arg(i).indexOf(',')>-1){
ib=0;
for(uint8_t t=0;t<BUFSIZ;t++){
if(clientline[t]==',' || clientline[t]==0 || clientline[t]=='&'){//trenner oder ende
cbuffer[ib]=0;
if(ib>0)drawBefehl(cbuffer);
ib=0;
}
else{
cbuffer[ib]=clientline[t];//umkopieren
ib++;
if(ib==BUFSIZ){
cbuffer[ib]=0;
drawBefehl(cbuffer);
ib=0;
}
}
}
}
else{
drawBefehl(clientline);
}
//matrix.update();
//startTimer();
/*
f000
l23052331024
p2231024
B swap.puffer
*/
}
if (server.argName(i) == "ti") {
//server.arg(i)// ti=1524083533262
}
}
server.setContentLength(html.length());
server.send(200,"text/html",html);
}
void handleSetup(){//setup, upload,...
stoppTimer(true);
String html = basichtml;
html+="<h1>Setup - "+String(progversion)+"</h1>\r\n";
html+="<nav>";
html+="<a href=\"/index.htm\">index</a>\r\n";
html+="</nav>";
String tmp="<table class=\"files\">\n";
String fileName;
File root = SPIFFS.open("/");
if(root.isDirectory()){
File file = root.openNextFile();
while(file){
if(!file.isDirectory()){//nur root
fileName=file.name();
Serial.print(fileName);
Serial.print(" ");
Serial.println(file.size());
if(fileName!="/setup.ini"){//setup.ini "hidden" File
tmp+="<tr>\r\n";
tmp+="\t<td><a target=\"_blank\" href =\"" + fileName + "\"" ;
if(isdownload(fileName)){
tmp+= " download=\"" + fileName+ "\"" ;
tmp+= " class=\"dl\"";
tmp+= " title=\"Download\"";
}else{
tmp+= " title=\"show\"";
}
tmp+= " >" + fileName.substring(1) + "</a>";
tmp+="</td>\n\t<td class=\"size\">" + formatBytes(file.size())+"</td>\n\t<td class=\"action\">";
tmp+="<a href =\"" + fileName + "?delete=" + fileName + "\" class=\"fl_del\"> löschen </a>";
tmp+="</td>\r\n</tr>\r\n";
}
}
file = root.openNextFile();
}
//static
tmp+="<tr>\n";
tmp+="\t<td><a target=\"_blank\" href =\"data.json\" title=\"show\">data.json</a>";
tmp+= "</td>\n\t<td class=\"size\"></td>\n\t<td class=\"action\">";
tmp+="\t</td>\n</tr>\n";
tmp += "<tr><td colspan=\"3\">";
tmp += formatBytes(SPIFFS.usedBytes()); //502
tmp += " von ";
tmp += formatBytes(SPIFFS.totalBytes()); //1374476byte=1.31MB
tmp += " (";
tmp += float(int(100.0/SPIFFS.totalBytes()*SPIFFS.usedBytes()*100.0)/100.0);
tmp += "%)";
Serial.print("SPIFFS usedBytes:");
Serial.print(SPIFFS.usedBytes());
Serial.print(" total:");