I created a simple code, as below. When I complied the code, there is a problem with WiFiClient client = server.available();. The error message said that “‘using ESP8266WebServer = class esp8266webserver::ESP8266WebServerTemplate<WiFiServer>’ has no member named ‘available’ “. What is wrong with the piece of code?. Is ESP8266WiFi library out of date?
/*
Control 1 channel relay to turn on/off lamp with 220 volt through ESP8266 web server
*/
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
/* **** STA Mode ***** */
/*Put your SSID & Password*/
const char* ssid = “Bcdnet”; // Enter SSID here
const char* password = “bcd710904”; //Enter Password here
ESP8266WebServer server(80);
uint8_t LAMPpin = 5; /* D1 */
bool LAMPstatus = LOW;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(100);
pinMode(LAMPpin, OUTPUT);
digitalWrite(LAMPpin,LOW);
Serial.println(“Connecting to “);
Serial.println(ssid);
//connect to your local wi-fi network
WiFi.begin(ssid, password);
//check wi-fi is connected to wi-fi network
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(“.”);
}
Serial.println(“”);
Serial.println(“WiFi connected..!”);
Serial.print(“Got Wifi IP: “); Serial.println(WiFi.localIP());
/* server.on(“/”, handle_OnConnect);
server.on(“/led1on”, handle_led1on);
server.on(“/led1off”, handle_led1off);
server.on(“/led2on”, handle_led2on);
server.on(“/led2off”, handle_led2off);
server.onNotFound(handle_NotFound);
*/
server.begin();
Serial.println(“HTTP server started”);
}
void loop() {
// put your main code here, to run repeatedly:
WiFiClient client = server.available();
if(!client){
return;
}
// Wait until the client sends some data
Serial.println(“New client”);
while(!client.available()){
delay(1);
}
// Read the first line of the request
String request = client.readStringUntil(‘\r’);
Serial.println(request);
Client.flush(); /* Refresh */
// Match the request
int value = LOW
if(request.indexOf(“/LAMPpin=ON”)!=-1){
digitalWrite(LAMPpin, HIGH);
value=HIGH;
}
if(request.indexOf(“/LAMPpin=OFF”)!=-1){
digitalWrite(LAMPpin, LOW);
value=LOW;
}
// Return the response
Client.println(“HTTP/1.1. 200 OK”);
Client.println(“Content-type: text/html”);
Client.println(“”); // It is important
Client.println(“<!DOCTYPE HTML>”);
Client.println(“<html>”);
Client.print(“Lamp is now:”);
if(value==HIGH){
Client.print(“On”);
} else {
Client.print(“Off”);
}
Client.println(“<br><br>”);
Client.println(“<a href=\”/LAMPpin=ON\”\”><button>On</button></a>”);
Client.println(“<a href=\”/LAMPpin=OFF\”\”><button>Off</button></a><br/>”);
Client.println(“</html>”);
delay(1);
Serial.println(“Client disconnected”);
Serial.println(“”);
}
Thanks for any help