The use of the ESP8266 in the world of IoT

User avatar
By Davide_Facci
#82475 Ciao a tutti,
Ho la mia scheda che si blocca in maniera casuale con lo sketch che vi allego, cercando sul web c'e' scritto che utilizzando delle stringhe puo' succedere che la scheda si blocchi ma non so come convertirle in char.
Vi ringrazio in anticipo se qualcuno mi puo' aiutare.
Grazie

Google translate:
Hi everyone,
I have my card that crashes randomly with the sketch that I am attaching, looking on the web there is written that using strings it can happen that the card hangs but I don't know how to convert them to char.
I thank you in advance if anyone can help me.
Thank you

#include <ESP8266WiFi.h>

const char* ssid = "Home&Life SuperWiFi-996D";
const char* password = "CDEDACYKDFGAF3BC";
int ledPin = 13; // GPIO13 or for NodeMCU you can directly write D7
int ResultSomma;
int StatoPinD4;
WiFiServer server(80);

void setup() {
Serial.begin(115200);

ESP.wdtDisable();

pinMode(ledPin, OUTPUT);
pinMode(D4, OUTPUT);
digitalWrite(ledPin, LOW);
delay(10);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
server.begin();
Serial.println("Server started");
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP()); //Gets the WiFi shield's IP address and Print the IP address of serial monitor
Serial.println("/");
Serial.printf("\n\nrinfo->reason=%d\n\n", ESP.getResetInfoPtr()->reason);
//ESP.wdtDisable();
//while (1){ESP.wdtFeed();};

ESP.wdtEnable(WDTO_500MS);

}
void LampeggioD4() {
digitalWrite(D4, HIGH);
StatoPinD4 = digitalRead(D4);
Serial.println(StatoPinD4);
delay(2000);
digitalWrite(D4, LOW);
StatoPinD4 = digitalRead(D4);
Serial.println(StatoPinD4);
delay(2000);

}

void Somma() {
ResultSomma=1+ResultSomma;
//delay (1000);
Serial.println(ResultSomma);
if (ResultSomma==3)
{
ResultSomma=0;
}
}

void loop() {

//Somma();
LampeggioD4();

// Check if a client has connected
WiFiClient client = server.available();
if (!client)
{
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available())
{
delay(500);
}
yield();
// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
// Match the request
int value = LOW;
if (request.indexOf("/LED=ON") != -1)
{
digitalWrite(ledPin, HIGH);
value = HIGH;
}
if (request.indexOf("/LED=OFF") != -1)
{
digitalWrite(ledPin, LOW);
value = LOW;
}
client.flush();

client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // do not forget this one
//client.println("<!DOCTYPE HTML>");
//client.println("<html>");
//client.print("Led pin is now: ");
if(value == HIGH)
{
client.print("INSERITO");
}
else
{
client.print("DISINSERITO");
}
/*
client.println("<br><br>");
client.println("<a href=\"/LED=ON\"\"><button>Turn On </button></a>");
client.println("<a href=\"/LED=OFF\"\"><button>Turn Off </button></a><br />");
client.println("</html>");
*/
delay(1);
Serial.println("Client disonnected");
//Serial.println("");
ESP.wdtFeed();
}