Sieht danach ausHast du die aktuelle Version des Codes verwendet?
Sieht danach ausHast du die aktuelle Version des Codes verwendet?
komplett so, unverändert?
Code:#include <ESP8266WiFi.h> const char* ssid = "********"; const char* password = "********"; WiFiServer server(80); void setup() { Serial.begin(115200); Serial.println(); Serial.printf("Connecting to %s ", ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(" connected"); server.begin(); Serial.printf("Web server started, open %s in a web browser\n", WiFi.localIP().toString().c_str()); } // prepare a web page to be send to a client (web browser) String prepareHtmlPage() { String htmlPage = String("HTTP/1.1 200 OK\r\n") + "Content-Type: text/html\r\n" + "Connection: close\r\n" + // the connection will be closed after completion of the response "Refresh: 5\r\n" + // refresh the page automatically every 5 sec "\r\n" + "<!DOCTYPE HTML>" + "<html>" + "Analog input: " + String(analogRead(A0)) + "</html>" + "\r\n"; return htmlPage; } void loop() { WiFiClient client = server.available(); // wait for a client (web browser) to connect if (client) { Serial.println("\n[Client connected]"); while (client.connected()) { // read line by line what the client (web browser) is requesting if (client.available()) { String line = client.readStringUntil('\r'); Serial.print(line); // wait for end of client's request, that is marked with an empty line if (line.length() == 1 && line[0] == '\n') { client.println(prepareHtmlPage()); break; } } } delay(1); // give the web browser time to receive the data // close the connection: client.stop(); Serial.println("[Client disonnected]"); } }
oh, ich hab was gefunden. muss noch mit 2.5.2 überprüfen.
ok, alles klar so weit:
Ab Version 2.4.1 muss zwingend im Response-Header, im Arduino-IDE-Quelltext "Content-Length" angegeben werden, damit der Browser weiß, auf wieviele Zeichen er vom Server wartet.
Gut möglich, dass das vorher automatisch irgendwo hinzugefügt worden ist, aber ab Version 2.4.1 nicht mehr.
Geändert von Moppi (22.10.2019 um 13:07 Uhr)
Update:
ich habe den Code jtzt auf einem neuen ESP8266 selber getestet, und tatsächlich tritt es auch bei mir so auf wie bei dir (Firefox):
2.2.0: läuft, website:2.5.2: sofortiger Abbruch,Analog input 2
Fehler: Verbindung unterbrochen
Die Verbindung zum Server wurde zurückgesetzt, während die Seite geladen wurde.
Die Website könnte vorübergehend nicht erreichbar sein, versuchen Sie es bitte später nochmals.
Wenn Sie auch keine andere Website aufrufen können, überprüfen Sie bitte die Netzwerk-/Internetverbindung.
Wenn Ihr Computer oder Netzwerk von einer Firewall oder einem Proxy geschützt wird, stellen Sie bitte sicher, dass Firefox auf das Internet zugreifen darf.
ich habe jetzt hier einen issue eröffnet: https://github.com/esp8266/Arduino/issues/6661
nimm mal den Quelltext:
Code:#include <ESP8266WiFi.h> //#include <ESP8266WebServer.h> //#include <FS.h> // muss vor <detail\RequestHandlersImpl.h> stehen //#include <detail\RequestHandlersImpl.h> String ssid = "..."; String password = "..."; //ESP8266WebServer webserver(80); // Webserver-Instanz f�r Port 80 erstellen WiFiServer server(80); void setup() { Serial.begin(115200); Serial.println(); Serial.println("Connecting to " + ssid); WiFi.mode(WIFI_STA); WiFi.begin(ssid.c_str(), password.c_str()); WiFi.config(IPAddress(xxx,xxx,xxx,xx), IPAddress(xxx,xxx,xxx,xxx), IPAddress(xxx,xxx,xxx,xxx), IPAddress(xxx,xxx,xxx,xxx)); //WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(" connected"); server.begin(); Serial.printf("Web server started, open %s in a web browser\n", WiFi.localIP().toString().c_str()); } // prepare a web page to be send to a client (web browser) String prepareHtmlPage() { String htmlPage = String("HTTP/1.1 200 OK\r\n") + "Content-Length: 44\r\n"+ "Content-Type: text/html\r\n" + "Connection: close\r\n" + // the connection will be closed after completion of the response "Refresh: 5\r\n" + // refresh the page automatically every 5 sec "\r\n" + "<!DOCTYPE html>" + "<html>" + "Analog input: " + String(analogRead(A0)) + "</html>" + "\r\n"; return htmlPage; } void loop() { WiFiClient client = server.available(); // wait for a client (web browser) to connect if (client) { Serial.println("\n[Client connected]"); while (client.connected()) { // read line by line what the client (web browser) is requesting if (client.available()) { String line = client.readStringUntil('\r'); Serial.print(line); // wait for end of client's request, that is marked with an empty line if (line.length() == 1 && line[0] == '\n') { client.println(prepareHtmlPage()); delay(100); // give the web browser time to receive the data // close the connection: client.stop(); Serial.println("[Client disonnected]"); break; } } } } }
ja, funktioniert jetzt mit 2.5.2 (habe WiFi.config() momentan auskommentiert)
was ist passiert?
weiter oben lesen: https://www.roboternetz.de/community...l=1#post655595
- - - Aktualisiert - - -
@hawe
habe Deinen ersten Quelltext, nach den neuen Erkenntnissen, nochmals modifiziert:
Code:bool authorized=false; void handleNotAuthorized() { String readString = ""; char strinput[MAXLEN], strupwd[TOKLEN], struname[TOKLEN] ; WiFiClient client = wifiserver.available(); //--------------------------------------- // debug // authorized=true; strcpy(strinput, ""); strcpy(strupwd, ""); strcpy(struname, ""); while ( client.connected() ) { if (authorized) return; if ( client.available() ) { char c = client.read(); //read char by request readString = ""; while ( (readString.length() < TOKLEN) && (c != '\n') ) { readString += c; c = client.read(); } readString.toCharArray(strinput, MAXLEN); // cstringarg(strinput, "uname", struname); // uname // cstringarg(strinput, "upwd", strupwd); // upwd if(strstr(website_upwd,strupwd)!=NULL & strstr(website_uname,struname)!=NULL) { authorized = true; readString = ""; return; // return; // <<< selbes Ergebnis, egal ob kommentiert oder auskommentiert } //if HTTP request has ended if (c == '\n') { client.flush(); //now output html data header String script=""; script += ("<!DOCTYPE html> \n"); script += ("<html> \n"); script += ("<head> \n"); // utf-8 für "°" Zeichen script += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> \n" ; script += "<title>" ; script += "</title> \n" ; script += "</head> \n" ; script += "<body> \n" ; script += ("<h2><p style=\"color:rgb(255,0,191);\"> log in to proceed: </p> </h2> \n"); script += ("<FORM ACTION='/' method=GET > \n"); script += ("<h2>user name: <INPUT TYPE=text NAME='uname' VALUE='' MAXLENGTH='50'> </h2> \n"); script += ("<h2>password : <INPUT TYPE=PASSWORD NAME='upwd' VALUE='' MAXLENGTH='50'> </h2> \n"); script += ("<h2><INPUT TYPE=SUBMIT></h2> \n"); script += ("</FORM> \n"); script += ("<BR> \n"); script += ("</body> \n"); script += ("</html> \n"); //---------------------------------- String script1 = ""; script1 += ("HTTP/1.1 200 OK \n"); script1 += ("Content-Type: text/html \n"); script1 += ("Content-Length: ") + script.length() + ("\n"); script1 += ("\n"); // do not forget this one //???? script = script1+script; client.print(script); delay(100); //stopping client client.stop(); //clearing string for next read //readString = ""; } } delay(1); } }
Lesezeichen