I am scratching my head about a problem with your temp, humidity and pressure server – the code compiles with an error “cannot declare variable ‘server’ to be of abstract type ‘WiFiServer’ I have completely uninstalled the Arduino IDE and have done a fresh install of the latest version, and have also tried it on our laptop, with the same result.
I have pasted the complete error report below:
Arduino: 1.8.8 (Windows 10), Board: "ESP32 Dev Module, Disabled, Default, 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, None" sketch_webserverlatest:30:12: error: cannot declare variable 'server' to be of abstract type 'WiFiServer' WiFiServer server(80); ^ In file included from C:\Program Files (x86)\Arduino\libraries\WiFi\src/WiFi.h:32:0, from C:\Users\George\Documents\ESP32\sketch_webserverlatest\sketch_webserverlatest.ino:7: C:\Program Files (x86)\Arduino\libraries\WiFi\src/WiFiServer.h:31:7: note: because the following virtual functions are pure within 'WiFiServer': class WiFiServer : public Server { ^ In file included from C:\Users\George\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.1\cores\esp32/Arduino.h:158:0, from sketch\sketch_webserverlatest.ino.cpp:1: C:\Users\George\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.1\cores\esp32/Server.h:28:18: note: virtual void Server::begin(uint16_t) virtual void begin(uint16_t port=0) =0; ^ C:\Users\George\Documents\ESP32\sketch_webserverlatest\sketch_webserverlatest.ino: In function 'void setup()': sketch_webserverlatest:50:28: error: invalid conversion from 'const char*' to 'char*' [-fpermissive] WiFi.begin(ssid, password); ^ In file included from C:\Users\George\Documents\ESP32\sketch_webserverlatest\sketch_webserverlatest.ino:7:0: C:\Program Files (x86)\Arduino\libraries\WiFi\src/WiFi.h:79:9: note: initializing argument 1 of 'int WiFiClass::begin(char*, const char*)' int begin(char* ssid, const char *passphrase); ^ exit status 1 cannot declare variable 'server' to be of abstract type 'WiFiServer' This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.
Thank you for taking the time to post your question in the forum. Can you please copy and paste the exact code that you’re uploading (remove your SSID and password)? I’ve never encountered that error before…
- Can you compile the WiFi Scan example?
- Can you double-check the following “5. Error compiling WiFiScan sketch”? https://rntlab.com/esp32-troubleshooting-guide/
Hi Rui,
Yes the WiFi scan example compiles fine (in fact the ESP32 is more sensitive than the WiFi on my phone!)
Indeed everything in the corse so far has been fine until the web server display sensor readings sketch, and I actually have a real world use for this to monitor the temp and humidity in our greenhouse..
I have pasted the code below directly from the Arduino IDE:
/*********
Rui Santos
Complete project details at http://randomnerdtutorials.com
*********/
// Load Wi-Fi library
#include <WiFi.h>
#include <Wire.h>
#include <Adafruit_BME280.h>
#include <Adafruit_Sensor.h>
//uncomment the following lines if you’re using SPI
/*#include <SPI.h>
#define BME_SCK 18
#define BME_MISO 19
#define BME_MOSI 23
#define BME_CS 5*/
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
// Replace with your network credentials
const char* ssid = “SSID”;
const char* password = “password”;
// Set web server port number to 80
WiFiServer server(80);
// Variable to store the HTTP request
String header;
void setup() {
Serial.begin(115200);
bool status;
// default settings
// (you can also pass in a Wire library object like &Wire2)
//status = bme.begin();
if (!bme.begin(0x76)) {
Serial.println(“Could not find a valid BME280 sensor, check wiring!”);
while (1);
}
// Connect to Wi-Fi network with SSID and password
Serial.print(“Connecting to “);
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(“.”);
}
// Print local IP address and start web server
Serial.println(“”);
Serial.println(“WiFi connected.”);
Serial.println(“IP address: “);
Serial.println(WiFi.localIP());
server.begin();
}
void loop(){
WiFiClient client = server.available(); // Listen for incoming clients
if (client) { // If a new client connects,
Serial.println(“New Client.”); // print a message out in the serial port
String currentLine = “”; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client’s connected
if (client.available()) { // if there’s bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
header += c;
if (c == ‘\n’) { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that’s the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what’s coming, then a blank line:
client.println(“HTTP/1.1 200 OK”);
client.println(“Content-type:text/html”);
client.println(“Connection: close”);
client.println();
// Display the HTML web page
client.println(“<!DOCTYPE html><html>”);
client.println(“<head><meta name=\”viewport\” content=\”width=device-width, initial-scale=1\”>”);
client.println(“<link rel=\”icon\” href=\”data:,\”>”);
// CSS to style the table
client.println(“<style>body { text-align: center; font-family: \”Trebuchet MS\”, Arial;}”);
client.println(“table { border-collapse: collapse; width:35%; margin-left:auto; margin-right:auto; }”);
client.println(“th { padding: 12px; background-color: #0043af; color: white; }”);
client.println(“tr { border: 1px solid #ddd; padding: 12px; }”);
client.println(“tr:hover { background-color: #bcbcbc; }”);
client.println(“td { border: none; padding: 12px; }”);
client.println(“.sensor { color:white; font-weight: bold; background-color: #bcbcbc; padding: 1px; }”);
// Web Page Heading
client.println(“</style></head><body><h1>ESP32 with BME280</h1>”);
client.println(“<table><tr><th>MEASUREMENT</th><th>VALUE</th></tr>”);
client.println(“<tr><td>Temp. Celsius</td><td><span class=\”sensor\”>”);
client.println(bme.readTemperature());
client.println(” *C</span></td></tr>”);
client.println(“<tr><td>Temp. Fahrenheit</td><td><span class=\”sensor\”>”);
client.println(1.8 * bme.readTemperature() + 32);
client.println(” *F</span></td></tr>”);
client.println(“<tr><td>Pressure</td><td><span class=\”sensor\”>”);
client.println(bme.readPressure() / 100.0F);
client.println(” hPa</span></td></tr>”);
client.println(“<tr><td>Approx. Altitude</td><td><span class=\”sensor\”>”);
client.println(bme.readAltitude(SEALEVELPRESSURE_HPA));
client.println(” m</span></td></tr>”);
client.println(“<tr><td>Humidity</td><td><span class=\”sensor\”>”);
client.println(bme.readHumidity());
client.println(” %</span></td></tr>”);
client.println(“</body></html>”);
// The HTTP response ends with another blank line
client.println();
// Break out of the while loop
break;
} else { // if you got a newline, then clear currentLine
currentLine = “”;
}
} else if (c != ‘\r’) { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
}
}
// Clear the header variable
header = “”;
// Close the connection
client.stop();
Serial.println(“Client disconnected.”);
Serial.println(“”);
}
}
I’ve tried to re-compile the code today on my computer and it’s working fine for me.
To be honest I don’t know how to solve that error, because I’ve never encountered it.
It seems like your Arduino IDE is not using the ESP32 Wi-Fi library to compile that sketch (and that’s why it’s failing).
I looks like you’re already using the latest version of the ESP32 add-on, but can you check it?
- Tools > Board > Boards Manager: ESP32 board add-on: core version 1.0.1
Can you also try to find the Arduino WiFi library in your Arduino IDE and remove it?
- It’s explained how to find that library here: “5. Error compiling WiFiScan sketch”? https://rntlab.com/esp32-troubleshooting-guide/