salve, come da titolo volevo chiedervi se avete qualche notizia riguardo lo spegnimento della node mcu v2 amica dopo circa 2/3 ore che è collegata ad internet e dopo un po' di richieste ( lavora come server ) si spegne da sola, provo ad entrare dal router per vedere se è almeno attiva o collegata e da la la vedo spenta.
Avevo un altro probelma, ovvero che dopo un po' mi perdeva l'IP, ma quello lo ho risolto con un ciclo, se volete ora metto qui lo sketch.
Ho letto che c'è il topic relativo alla ESP8266 e però non mi pare di aver trovato le informazioni che cerco... ho cercato anche in internet ma ho trovato poco o nulla.. avete qualche consiglio?
Grazie mille
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include<dht11.h>
/***** Web Pages ************************************************************************/
String HeaderPage = "<!DOCTYPE html><html><head><style> header { background: linear-gradient(to right, #1e5799 0%,#7db9e8 100%); color: #fff; padding:10px; text-align: center; vertical-align: middle; } body{ padding:15px; color: #5e5e5e; font-family: Helvetica,Arial,sans-serif; font-variant: small-caps; font-size:1em; text-align: center; } footer { background: linear-gradient(to left, #1e5799 0%,#7db9e8 100%); color: #fff; padding:10px; text-align: right; vertical-align: bottom; } h2 { padding:10px; text-align: center; vertical-align: middle; font-size:2em; } </style></head><body><header>DOMOTICA FAI DA TE</header>";
String FooterPage = "<footer>powerd by NodeMCU V2 in ARDUINO IDE</br></footer></body></html>";
//String rootPageBody = "<h2>List of comands:</h2><ul><li>/LED=ON.....turn on led in D3</li><li>/LED=OFF...turn off led in D3</li><li>/HUMIDITY....give % of humidity</li><li>/TEMPERATURE.....give the temperature in C°</li><li>/.....return home page</li></ul>";
String rootPageBody = "<h2>List of comands:</h2><ul><li><a href=\"/LED=ON\"><button>ON</button></a>.....turn on led in D3</li><li><a href=\"/LED=OFF\"><button>OFF</button></a>...turn off led in D3</li><li><a href=\"/HUMIDITY\"><button>HUMIDITY</button></a>....give % of humidity</li><li><a href=\"/TEMPERATURE\"><button>TEMPERATURE</button></a>.....give the temperature in C°</li></ul>";
String rootWebPage;
/****************************************************************************************/
const char *wifi_ssid = "*****";
const char *wifi_password = "*******";
int pinLed = D3;
dht11 DHT11;
#define pinDht11 D5
long i;
int coloreDelBottone = 0;//se 1 led è acceso, se 0 led è spento
ESP8266WebServer server(80);
WiFiClient espClient;
void setup() {
Serial.begin(115200);
Serial.println("");
pinMode(pinLed,OUTPUT);
setup_wifi();
composeWebPage();
startWebServer();
}
void loop() {
while(WiFi.status() = WL_CONNECTED)
{
server.handleClient();
delay(1);
}
WiFi.disconnect(true);
delay(5);
setup_wifi();
composeWebPage();
startWebServer();
}
/***** Functions ***********************************************************************/
void Humidity()
{
String inizio = "<!DOCTYPE HTML> <html> <body> <h2>Umidita': ";
int valore = DHT11.read(pinDht11);
String dato =(String)DHT11.humidity;
String fine = " % </h2><br><br><br><br><a href=\"/\"><button style=\"background-color: #AFC7C7;\">HOMEPAGE</button></a></body></html>";
rootWebPage= inizio;
rootWebPage += dato;
rootWebPage +=fine;
server.send(200, "text/html", rootWebPage);
}
void Temperature()
{
String inizio = "<!DOCTYPE HTML> <html> <body> <h2>Temperatura: ";
int valore = DHT11.read(pinDht11);
String dato =(String)DHT11.temperature;
String fine = "</h2><br><br><br><br><a href=\"/\"><button style=\"background-color: #AFC7C7;\">HOMEPAGE</button></a></body></html>";
Serial.println(dato);
rootWebPage= inizio;
rootWebPage += dato;
rootWebPage +=fine;
Serial.println(rootWebPage);
server.send(200, "text/html", rootWebPage);
}
void OffWebPage()
{
rootWebPage ="<!DOCTYPE HTML> <html><h1>LED OFF</h1><br><br><br><br><a href=\"/\"><button style=\"background-color: #AFC7C7;\">HOMEPAGE</button></a></html>";
coloreDelBottone = 0;
}
void OnWebPage()
{
rootWebPage ="<!DOCTYPE HTML> <html><h1>LED ON</h1><br><br><br><br><a href=\"/\"><button style=\"background-color: #AFC7C7;\">HOMEPAGE</button></a></html>";
coloreDelBottone = 1;
}
void LedOn(){
digitalWrite(pinLed,HIGH);
OnWebPage();
server.send(200, "text/html", rootWebPage);
coloreDelBottone = 1;
}
void LedOff()
{
digitalWrite(pinLed,LOW);
OffWebPage();
server.send(500, "text/html", rootWebPage); //200
coloreDelBottone = 0;
}
void setup_wifi() {
delay(10);
Serial.println("********************");
Serial.println("INFO");
Serial.println("********************");
Serial.print("SSID: ");
Serial.println(wifi_ssid);
Serial.print("PASSWORD: ");
Serial.println(wifi_password);
Serial.println("===================");
Serial.print("Mi connetto");
Serial.println(wifi_ssid);
WiFi.begin(wifi_ssid, wifi_password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("Collegato correttamente");
Serial.println("********************");
Serial.print("IP: ");
Serial.println(WiFi.localIP());
Serial.println("********************");
}
void handleRoot() { composeWebPage();
server.send(200, "text/html", rootWebPage); }
void composeWebPage()
{
if(coloreDelBottone==0){
rootPageBody = "<h2>List of comands:</h2><ul><li><a href=\"/LED=ON\"><button style=\"background-color: #AFC7C7;\">ON</button></a>.....turn on led in D3</li><li><a href=\"/LED=OFF\"><button style=\"background-color: #FF0000;\">OFF</button></a>...turn off led in D3</li><li><a href=\"/HUMIDITY\"><button style=\"background-color: #AFC7C7;\">HUMIDITY</button></a>....give % of humidity</li><li><a href=\"/TEMPERATURE\"><button style=\"background-color: #AFC7C7;\">TEMPERATURE</button></a>.....give the temperature in C°</li></ul>";
}
else if( coloreDelBottone==1)
{
rootPageBody = "<h2>List of comands:</h2><ul><li><a href=\"/LED=ON\"><button style=\"background-color: #00FF00;\">ON</button></a>.....turn on led in D3</li><li><a href=\"/LED=OFF\"><button style=\"background-color: #AFC7C7;\">OFF</button></a>...turn off led in D3</li><li><a href=\"/HUMIDITY\"><button style=\"background-color: #AFC7C7;\">HUMIDITY</button></a>....give % of humidity</li><li><a href=\"/TEMPERATURE\"><button style=\"background-color: #AFC7C7;\">TEMPERATURE</button></a>.....give the temperature in C°</li></ul>";
}
rootWebPage = HeaderPage;
rootWebPage += rootPageBody;
rootWebPage += FooterPage;
}
void startWebServer() {
server.on("/", handleRoot);
server.on("/LED=ON",LedOn);
server.on("/LED=OFF",LedOff);
server.on("/TEMPERATURE",Temperature);
server.on("/HUMIDITY",Humidity);
server.begin();
Serial.println("Server pronto");
}