Ciao a tutti,
in questi giorni, da novizio e autodidatta, sto testando i moduli ESP8266 e DHT11 montati su arduino per realizzare in futuro un termostato Wifi.
Di base sto provando alcuni esempi trovati nella rete ma continuo ad avere errori durante la compilazione. (Ho praticamente gli stessi errori in tutti gli esempi che provo)
Di seguito vi riporto il codice di un esempio trovato in rete e l’elenco degli errori.
Qualcuno può aiutarmi a capire?
#include <dht11.h>
#include <ESP8266wifi.h>
const char* ssid = "ssid"; // Your ssid
const char* password = "password"; // Your Password
int pin = 2;
WiFiServer server(80);
DHT11 dht11(pin);
double Fahrenheit(double celsius)
{
return ((double)(9 / 5) * celsius) + 32;
}
double Kelvin(double celsius)
{
return celsius + 273.15;
}
void setup()
{
Serial.begin(115200);
delay(10);
Serial.println();
// Connect to WiFi network
WiFi.mode(WIFI_STA);
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");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.println(WiFi.localIP());
}
void loop()
{
int err;
float temp, humi;
if ((err = dht11.read(humi, temp)) == 0)
{
Serial.print("temperature:");
Serial.print(temp);
Serial.print(" humidity:");
Serial.print(humi);
Serial.println();
}
else
{
Serial.println();
Serial.print("Error No :");
Serial.print(err);
Serial.println();
}
WiFiClient client = server.available();
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE html>");
client.println("<html xmlns='http://www.w3.org/1999/xhtml'>");
client.println("<head>\n<meta charset='UTF-8'>");
client.println("<title>ESP8266 Temperature & Humidity DHT11 Sensor</title>");
client.println("</head>\n<body>");
client.println("<H2>ESP8266 & DHT11 Sensor</H2>");
client.println("<H3>Humidity / Temperature</H3>");
client.println("<pre>");
client.print("Humidity (%) : ");
client.println((float)humi, 2);
client.print("Temperature (°C) : ");
client.println((float)temp, 2);
client.print("Temperature (°F) : ");
client.println(Fahrenheit(temp), 2);
client.print("Temperature (°K) : ");
client.println(Kelvin(temp), 2);
client.println("</pre>");
client.println("<H3>www.elec-cafe.com</H3>");
client.print("</body>\n</html>");
delay(DHT11_RETRY_DELAY); //delay for reread
}
Ecco l’elenco degli errori che ottengo
test_WiFi_6.ino:9:1: error: 'WiFiServer' does not name a type
test_WiFi_6.ino:10:1: error: 'DHT11' does not name a type
test_WiFi_6.ino: In function 'void setup()':
test_WiFi_6.ino:29:1: error: 'WiFi' was not declared in this scope
test_WiFi_6.ino:29:11: error: 'WIFI_STA' was not declared in this scope
test_WiFi_6.ino:37:25: error: 'WL_CONNECTED' was not declared in this scope
test_WiFi_6.ino:46:1: error: 'server' was not declared in this scope
test_WiFi_6.ino: In function 'void loop()':
test_WiFi_6.ino:57:17: error: expected primary-expression before '.' token
test_WiFi_6.ino:72:1: error: 'WiFiClient' was not declared in this scope
test_WiFi_6.ino:72:12: error: expected ';' before 'client'
test_WiFi_6.ino:73:1: error: 'client' was not declared in this scope
test_WiFi_6.ino:97:7: error: 'DHT11_RETRY_DELAY' was not declared in this scope
Errore durante la compilazione