• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

ESP8266WiFi

Q&A Forum › Category: ESP8266 › ESP8266WiFi
0 Vote Up Vote Down
Phaykeo Chanthalangsy asked 3 years ago

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

1 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi.
That code refers to what project? Can you share a link?
Or did you create the code yourself?
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.