ESP-32 WiFi function,after connected the esp32 sometime didnt work?
Posted: Mon Jun 24, 2019 5:03 am
I just using a simple wifi function to open the GPIO under the HTTP server. But after I send some command to esp-wroom-32D. The chip didn't work(cannot open anything until I switch off and turn it on again). My code show as below;
#include <WiFi.h>
String ClientRequest;
WiFiServer server(80);
WiFiClient client;
String myresultat;
String ReadIncomingRequest(){
while(client.available()) {
ClientRequest = (client.readStringUntil('\r'));
if ((ClientRequest.indexOf("HTTP/1.1")>0)&&(ClientRequest.indexOf("/favicon.ico")<0)){
myresultat = ClientRequest;
}
}
return myresultat;
}
void setup()
{
ClientRequest = "";
Serial.begin(9600);
pinMode(5, OUTPUT);
pinMode(33, OUTPUT);
pinMode(32, OUTPUT);
WiFi.disconnect();
delay(100);
Serial.println("START");
WiFi.begin("","");
while ((!(WiFi.status() == WL_CONNECTED))){
delay(10);
Serial.print("..");
}
Serial.println("Connected");
Serial.println("Your IP is");
Serial.println((WiFi.localIP()));
server.begin();
}
void loop()
{
client = server.available();
if (!client) { return; }
while(!client.available()){ delay(1); }
ClientRequest = (ReadIncomingRequest());
ClientRequest.remove(0, 5);
ClientRequest.remove(ClientRequest.length()-9,9);
if (ClientRequest == "1") {
digitalWrite(5,LOW);
digitalWrite(33,LOW);
digitalWrite(32,HIGH);
}
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("");
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("OK");
client.println("</html>");
client.stop();
delay(1);
client.flush();
}
#include <WiFi.h>
String ClientRequest;
WiFiServer server(80);
WiFiClient client;
String myresultat;
String ReadIncomingRequest(){
while(client.available()) {
ClientRequest = (client.readStringUntil('\r'));
if ((ClientRequest.indexOf("HTTP/1.1")>0)&&(ClientRequest.indexOf("/favicon.ico")<0)){
myresultat = ClientRequest;
}
}
return myresultat;
}
void setup()
{
ClientRequest = "";
Serial.begin(9600);
pinMode(5, OUTPUT);
pinMode(33, OUTPUT);
pinMode(32, OUTPUT);
WiFi.disconnect();
delay(100);
Serial.println("START");
WiFi.begin("","");
while ((!(WiFi.status() == WL_CONNECTED))){
delay(10);
Serial.print("..");
}
Serial.println("Connected");
Serial.println("Your IP is");
Serial.println((WiFi.localIP()));
server.begin();
}
void loop()
{
client = server.available();
if (!client) { return; }
while(!client.available()){ delay(1); }
ClientRequest = (ReadIncomingRequest());
ClientRequest.remove(0, 5);
ClientRequest.remove(ClientRequest.length()-9,9);
if (ClientRequest == "1") {
digitalWrite(5,LOW);
digitalWrite(33,LOW);
digitalWrite(32,HIGH);
}
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("");
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("OK");
client.println("</html>");
client.stop();
delay(1);
client.flush();
}