Go Down

Topic: 'WL_CONNECTED' was not declared in this scope  (Read 1 time) previous topic - next topic


Sep 09, 2018, 04:58 pm Last Edit: Sep 09, 2018, 08:00 pm by Jrsl78

I am trying to repeat a project from the book: "A Hands-On Course in Sensors using Arduino and Raspberry Pi." by Volker Ziemann.  The project is to use a NodeMCU 8266 to connect to a host computer.  I have downloaded the libraries for the NodeMCU (there were alot) and I believe they have been placed properly in the correct folder, but I'm not sure since for some reason I could not add it via the ZIP file method.  I had to do it manually.

The NodeMCU is connected to a temperature sensor and should take readings and post on an internal network webpage.

When I verify the code, I get the error "'WL_CONNECTED' was not declared in this scope".  From my research on the web, this could mean that the 'WL_CONNECTED' is not defined and so I have to make sure the library is included.  But, I've tried including other libraries like WiFi.h, and it won't fix the problem.  I've also made sure the WiFi libraries are in the the library folder in Arduino.  They seem to be in the right place...

I've also tried searching the forum for similar problems.

I've attached the code.  


Here is the copied error message from the IDE:

Arduino: 1.8.5 (Windows 7), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, 4M (1M SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

sketch_sep09e_webserver_to_read_temperature_for_forum:13: error: 'WL_CONNNECTED' was not declared in this scope

 while (WiFi.status() != WL_CONNNECTED){

exit status 1
'WL_CONNNECTED' was not declared in this scope


Your code,  for the convenience of users reading on mobile devices.

Please post ALL of the error messages you saw.

Code: [Select]
//Web server to read temperatre and set brightness
#include <ESP8266WiFi.h>
#include <WiFi.h>

const char* ssid = "hostcomputer";
const char* password = "password";
WiFiServer server(80);  //server listens on port 80

void setup() {
  Serial.begin(115200); delay(10);
  Serial.print("Connecting to ");Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNNECTED){
  Serial.print("\nWiFi connected and ");
  Serial.print("server started at");

void loop() {
  WiFiClient client = server.available();
  while (client) {
    String req = client.readStringUntil('\r');
    client.print("HTTP/1.1 200 OK\r\nContent-Type: text/html");
    client.print("\r\n\r\n<!DOCTYPE HTML)>\r\n<html>\r\n");
    if (req.indexOf("/temperature") != -1) { //read sensor
      float temp=100*3.3*analogRead(0)/1023;
      client.print("Temperature="); client.println(temp,2);
    }else if(req.indexOf("/led") !=-1) {  //brigthness of LED
      int i1=req.indexOf("?"); int i2=req.indexOf("HTTP");
      String payload=req.substring(i1+1, i2-1);
      if (i1>0) analogWrite(D4, 1023-payload.toInt());
    } else {
      Serial.println("invalid request");
    client.println("</html>"); delay(1);


Okay, I found it.  I spelled WL_CONNECTED with an extra 'N'.

Go Up