//-------------------------------------------------------------------------------------------- #if defined(HTTPCONF) || defined(ESP_HTTPCONF) //-------------------------------------------------------------------------------------------- #if defined(LAN) void Webconfig() { EthernetClient client = server.available(); if (client) { String receivedText = String(50); // an http request ends with a blank line boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); if (receivedText.length() < 50) { receivedText += c; } // if you've gotten to the end of the line (received a newline // character) and the line is blank, the http request has ended, // so you can send a reply if (c == '\n' && currentLineIsBlank) { // send a standard http response header client.println(F("HTTP/1.1 200 OK")); client.println(F("Content-Type: text/html")); client.println(F("Connection: close")); // the connection will be closed after completion of the response //client.println(F("Refresh: 5")); // refresh the page automatically every 5 sec client.println(); //don't forget this!!! //Website: client.println(F("")); client.println(F("")); client.println(F("Z21

Z21

")); //---------------------------------------------------------------------------------------------------- int firstPos = receivedText.indexOf("?"); if (firstPos > -1) { byte lastPos = receivedText.indexOf(" ", firstPos); String theText = receivedText.substring(firstPos+3, lastPos); // 10 is the length of "?A=" byte S88Pos = receivedText.indexOf("S="); #if defined(S88N) S88Module = receivedText.substring(S88Pos+2, receivedText.indexOf("HTTP")-1).toInt(); #endif byte Sip = theText.indexOf("A="); //Start IP, nur wenn DHCP aktiv ist Ausdruck vorhanden! if (Sip == 0xFF) { //DHCP off LAN_DHCP = false; Sip = 0; } else { LAN_DHCP = true; Sip += 2; } byte Aip = theText.indexOf("&B=", Sip); byte Bip = theText.indexOf("&C=", Aip); byte Cip = theText.indexOf("&D=", Bip); byte Dip = theText.substring(Cip+3, S88Pos).toInt(); Cip = theText.substring(Bip+3, Cip).toInt(); Bip = theText.substring(Aip+3, Bip).toInt(); Aip = theText.substring(Sip, Aip).toInt(); LAN_ip[0] = Aip; LAN_ip[1] = Bip; LAN_ip[2] = Cip; LAN_ip[3] = Dip; #if defined(DEBUG) #if defined(S88N) Debug.print("S88: "); Debug.println(S88Module); #endif if (LAN_DHCP) Debug.print("DHCP "); Debug.print("IP: "); Debug.println(LAN_ip); #if !defined(SOFT_RESET) Debug.println(F("-> Restart to accept!")); #endif #endif #if !defined(SOFT_RESET) client.print(F("

Reset Z21 to accept!

")); #endif FIXSTORAGE.FIXMODE(EELANDHCP, LAN_DHCP); FIXSTORAGE.FIXMODE(EELANip, Aip); FIXSTORAGE.FIXMODE(EELANip+1, Bip); FIXSTORAGE.FIXMODE(EELANip+2, Cip); FIXSTORAGE.FIXMODE(EELANip+3, Dip); #if defined(ESP_WIFI) FIXSTORAGE.commit(); #endif #if defined(S88N) if (FIXSTORAGE.read(EES88Moduls) != S88Module) { FIXSTORAGE.FIXMODE(EES88Moduls, S88Module); #if defined(ESP_WIFI) FIXSTORAGE.commit(); #endif #if defined(DEBUG) Debug.print("neu S88: "); Debug.println(S88Module); #endif SetupS88(); #if defined(WIFI) WLANSetup(); #endif } else { #endif #if defined(SOFT_RESET) soft_restart(); //Reboot MCU! #endif #if defined(S88N) } #endif } //---------------------------------------------------------------------------------------------------- client.print(F("
")); client.print(F("DHCP
")); client.print(F("IP:

8x S88 Module:

")); break; } if (c == '\n') currentLineIsBlank = true; // you're starting a new line else if (c != '\r') currentLineIsBlank = false; // you've gotten a character on the current line } } client.stop(); // close the connection: } } #endif //-------------------------------------------------------------------------------------------- #if defined(ESP8266_MCU) || defined(ESP32_MCU) void Webconfig() { WiFiClient client = ESPWebserver.available(); if (!client) return; String HTTP_req; // stores the HTTP request if (client) { // got client? boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { // client data available to read char c = client.read(); // read 1 byte (character) from client HTTP_req += c; // save the HTTP request 1 char at a time // last line of client request is blank and ends with \n // respond to client only after last line received if (c == '\n' && currentLineIsBlank) { // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: keep-alive"); client.println(); //don't forget this!!! // AJAX request for switch state if (HTTP_req.indexOf("/ajax_switch") > -1) { #if defined(DEBUG) Debug.println("Reset WLAN conf!"); #endif // read switch state and send appropriate paragraph text ssid = HTTP_req.substring(HTTP_req.indexOf("&s=")+3,HTTP_req.indexOf("&p=")); pass = HTTP_req.substring(HTTP_req.indexOf("&p=")+3,HTTP_req.indexOf("&As=")); ssidAP = HTTP_req.substring(HTTP_req.indexOf("&As=")+4,HTTP_req.indexOf("&Ap=")); passAP = HTTP_req.substring(HTTP_req.indexOf("&Ap=")+4,HTTP_req.indexOf("&Ak=")); kanalAP = HTTP_req.substring(HTTP_req.indexOf("&Ak=")+4,HTTP_req.indexOf("&S8=")).toInt(); #if defined(S88N) S88Module = HTTP_req.substring(HTTP_req.indexOf("&S8=")+4,HTTP_req.indexOf("&nocache")).toInt(); #endif if ((kanalAP < 1) || (kanalAP > 13)) { kanalAP = SkanalAP; client.print("Ka. error! "); } if (passAP.length() < 8) { passAP = SpassAP; client.print("Code length error (min. 8)! "); } // write eeprom EEPROMwrite (ssid, EEssidLength, EEssidBegin); EEPROMwrite (pass, EEpassLength, EEpassBegin); EEPROMwrite (ssidAP, EEssidAPLength, EEssidAPBegin); EEPROMwrite (passAP, EEpassAPLength, EEpassAPBegin); FIXSTORAGE.FIXMODE(EEkanalAP, kanalAP); FIXSTORAGE.commit(); ESPSetup(); Udp.begin(z21Port); client.println("saved"); //OK! } else { // HTTP request for web page // send web page - contains JavaScript with AJAX calls client.println(""); client.println("Z21"); client.println(""); client.println(""); client.println(""); client.println("

Z21 Einstellungen


"); client.print("

WiFi Access-Point

"); client.print("
IP: "); client.print(WiFi.softAPIP()); client.print("
Connected Clients: "); client.print(WiFi.softAPgetStationNum()); client.print(" of 8
SSID:
code:
Ka.:
"); client.print("

WiFi Client

"); client.print("
IP: "); if (WiFi.status() == WL_CONNECTED) { client.print(WiFi.localIP()); client.print(" ("); client.print(WiFi.RSSI()); client.print("dBm)"); } else client.print("none"); client.print("
SSID:
code:
"); client.println("

S88 Module

"); client.print("
8x Anzahl:

"); client.println(""); client.println("

"); client.print("

Z21_ESP_Central_Station_v"); client.print(Z21mobileSwVer); client.print(bitRead(FIXSTORAGE.read(EEPROMRCN213), 2)); //RCN-213 #if defined (BOOSTER_INT_NDCC) if (FIXSTORAGE.read(EEPROMRailCom) == 0x01) client.print(".RAILCOM"); #endif client.println("
Build: "); client.println(comp_date); client.println("
Copyright (c) 2022 Philipp Gahtow
digitalmoba@arcor.de"); client.println("

"); client.print(""); } // display received HTTP request on serial port //Serial.print(HTTP_req); HTTP_req = ""; // finished with request, empty string break; } // every line of text received from the client ends with \r\n if (c == '\n') { // last character on line of received text // starting new line with next character read currentLineIsBlank = true; } else if (c != '\r') { // a text character was received from client currentLineIsBlank = false; } } // end if (client.available()) } // end while (client.connected()) delay(1); // give the web browser time to receive the data client.stop(); // close the connection } // end if (client) } #endif //-------------------------------------------------------------------------------------------- #endif //HTTPconf