Go Down

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

Jrsl78

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

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.  

Thanks.

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


AWOL

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){
    delay(500);
    Serial.print(".");
  }
  Serial.print("\nWiFi connected and ");
  server.begin();
  Serial.print("server started at");
  Serial.println(WiFi.localIP());
}

void loop() {
  WiFiClient client = server.available();
  while (client) {
    while(!client.available()){delay(1);}
    String req = client.readStringUntil('\r');
    client.flush();
    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");
      return;
    }
    client.println("</html>"); delay(1);
    client.stop();
    }
  }
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Jrsl78

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

Go Up