1 | #include <WiFi.h>
|
2 | #include <Wire.h>
|
3 | #include <LiquidCrystal_I2C.h>
|
4 | #include "FS.h"
|
5 | #include "SPIFFS.h"
|
6 |
|
7 | LiquidCrystal_I2C lcd(0x3F, 16, 2); //Init Display
|
8 |
|
9 | const char* ssid = "ESP32AP";
|
10 | const char* password = "12345678";
|
11 |
|
12 | String header;
|
13 |
|
14 | WiFiServer server(80);
|
15 |
|
16 | void setup()
|
17 | {
|
18 |
|
19 | SPIFFS.begin();
|
20 | SPIFFS.format();
|
21 |
|
22 | Serial.begin(115200);
|
23 | pinMode(5, OUTPUT); // set the LED pin mode
|
24 | lcd.begin();
|
25 | lcd.backlight();
|
26 | lcd.clear();
|
27 | delay(10);
|
28 |
|
29 | // We start by connecting to a WiFi network
|
30 |
|
31 | Serial.println();
|
32 | Serial.println();
|
33 | Serial.print("Setting up ");
|
34 | Serial.println(ssid);
|
35 |
|
36 | WiFi.softAP(ssid, password);
|
37 |
|
38 | /*while (WiFi.status() != WL_CONNECTED) {
|
39 | delay(500);
|
40 | Serial.print(".");
|
41 | }*/
|
42 |
|
43 | Serial.println("");
|
44 | Serial.println("WiFi connected.");
|
45 | Serial.println("IP address: ");
|
46 | Serial.println(WiFi.softAPIP());
|
47 |
|
48 | lcd.print(WiFi.softAPIP());
|
49 | lcd.setCursor(0, 1);
|
50 | server.begin();
|
51 |
|
52 | }
|
53 |
|
54 | int value = 0;
|
55 | int i = 0;
|
56 |
|
57 |
|
58 | void loop() {
|
59 | WiFiClient client = server.available(); // listen for incoming clients
|
60 | lcd.setCursor(i, 1);
|
61 | lcd.print(".");
|
62 | i++;
|
63 | if (i > 9)
|
64 | {
|
65 | i = 0;
|
66 | lcd.setCursor(0, 1);
|
67 | lcd.print(" ");
|
68 |
|
69 | }
|
70 | // delay(100);
|
71 | if (client) {
|
72 | int indikator = 0; // if you get a client,
|
73 | Serial.println("New Client."); // print a message out the serial port
|
74 | String currentLine = ""; // make a String to hold incoming data from the client
|
75 |
|
76 | //variable um festzustellen ob erster schleifendurchlauf oder nicht
|
77 | while (client.connected()) { // loop while the client's connected
|
78 |
|
79 | if (client.available()) { // if there's bytes to read from the client,
|
80 |
|
81 | char c = client.read(); // read a byte, then
|
82 | //Serial.write(c);
|
83 |
|
84 | header += c; //Empfangene Daten zwischenspeichern
|
85 |
|
86 | }
|
87 | }
|
88 |
|
89 | client.stop(); // close the connection:
|
90 | //Serial.println("\nClient Disconnected.");
|
91 |
|
92 | int index = header.indexOf(":10"); //Anfang der Programmdaten suchen
|
93 | Serial.print("Index: ");
|
94 | Serial.println(index);
|
95 |
|
96 | String header2 = header.substring(index);
|
97 |
|
98 | //Datei schreiben
|
99 | File f1 = SPIFFS.open("/datei.hex", "w"); //Datei öffnen Modus: Schreiben
|
100 | if (!f1) {
|
101 | Serial.println("file open failed");
|
102 | }
|
103 |
|
104 | while (f1.available()) {
|
105 |
|
106 | f1.print(header2); //Dateiinhalte schreiben
|
107 | }
|
108 | f1.close();
|
109 |
|
110 | String debugLogData;
|
111 |
|
112 | //Datei lesen
|
113 | File f2 = SPIFFS.open("/datei.hex", "r"); //Datei öffnen Modus: Lesen
|
114 | if (!f2) {
|
115 | Serial.println("file open failed");
|
116 | }
|
117 |
|
118 | while (f2.available()) {
|
119 |
|
120 | debugLogData += char(f2.read()); //Dateiinhalte lesen
|
121 | }
|
122 | f2.close();
|
123 |
|
124 | Serial.println("_-_STRING HEADER_-_");
|
125 | Serial.print(debugLogData);
|
126 |
|
127 | header = ""; //Inhalt der Header Variable löschen
|
128 |
|
129 | }
|
130 | }
|