Compiler takes no library methods

I get error:
C:\Users\talkw\Documents\Arduino\server\SE_6_3\SE_6_3.ino:317:3: error: 'WiFi' does not name a type
317 | WiFi.mode(WIFI_AP_STA);

I included however at beginning of sketch , and the compiler doesnt complain:

#include <WiFi.h>

It seems the WiFi library is nog looked at ?! What can be the cause?

Jacob

Please provide more information

  • board
  • minimal code that shows the problem

Have you tested the WIFI examples for the board?

Post all your code in code tags, and the verbose error log also in code tags

your question, Board: ESP32 dev module

'compiler refuses to Take Methods from the wifi library'.

I see the cuase, it works; , however I have a strong remark on the ERROR REPORTING.

I got reported from compiler:
C:\Users\talkw\Documents\Arduino\server\SE_6_3\SE_6_3.ino:321:3: error: 'WiFi' does not name a type
321 | WiFi.mode(WIFI_AP_STA);
| ^~~~
C:\Users\talkw\Documents\Arduino\server\SE_6_3\SE_6_3.ino:324:4: error: 'WiFi' does not name a type
324 | WiFi.begin(ssid, password);
| ^~~~

BUT of course WiFI methods ARE defined in the library WiFi.h

It seems because Wifi.mode is called AFTER a bad piece of code of me, sorry !! :
Obviouisly the closing-comment should be one line lower.

Code:

`
/* if ((touchRead(27) < TOUCH_THRESHOLD)) {
digitalWrite(en_MHZ_n, LOW); //ENable 5V converter--> enable MHZ, Heatup
Serial.println("heating up Sensor FOR CALIBRATION");
tft.drawString("Cal CO2", 0, 90, 2);
w_loop(19);
mhz19.calibrateZero(); // calibrates MHZ to 400 ppm; (corr=50 always)
Serial.println("DONE CALIBRATION");
*/ //<---closing comment :of course wrong place - programming error of me - (move one line lower !!!)
}

// Set device as a Wi-Fi Station
WiFi.mode(WIFI_AP_STA); //<---XXX HERE COMPILER STARTS COMPLAINING however has nothing to do with Wifi methods or library !!!!!!
const char* ssid = "ESP32-Access-Point";
const char* password = "Hluppie";
WiFi.begin(ssid, password); // COMPILER complaint Wifi....
w_loop(1);
`

Question: in my opinion it would be good/is it possible to improve compiler error reporting on such ?

Jacob

Please post a full sketch that illustrates the error

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

You have to consider what the code looks like to the compiler.

#include <WiFi.h>

void setup() {
  //if (true) {  OOPS
  }  // <-- this now ends the function
     //     putting the next statement outside any function
  WiFi.begin("","");
}    // <-- also an error

void loop() {}

fails with

sketch_feb17a.ino:7:3: error: 'WiFi' does not name a type
    7 |   WiFi.begin("","");
      |   ^~~~
sketch_feb17a.ino:8:1: error: expected declaration before '}' token
    8 | }    // <-- also an error
      | ^

Outside a function, you are (mostly) limited to functions and global variables. Both start with a type. WiFi is an variable, not a type. If you hover over it in working code, the tooltip says

Would it be better if the compiler looked at the totality of your code and said, "From the indentation, it looks like you ended the comment in the wrong place." Sure. It doesn't though.