# Function not declared at this scope when #include \<ESP8266WiFi.h\>

**URL:** <https://forum.arduino.cc/t/function-not-declared-at-this-scope-when-include-esp8266wifi-h/359284>\
**Category:** Programming\
**Created:** [January 18, 2016, 5:20am UTC](https://forum.arduino.cc/t/function-not-declared-at-this-scope-when-include-esp8266wifi-h/359284 "2016-01-18T05:20:11Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![alangstein](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@alangstein](https://forum.arduino.cc/u/alangstein)\
**Post date:** [January 18, 2016, 5:20am UTC](https://forum.arduino.cc/t/function-not-declared-at-this-scope-when-include-esp8266wifi-h/359284/1 "2016-01-18T05:20:11Z")

</div>

I am creating an ESP8266 project to log the current status of my garage door (open or closed) to [data.sparkfun.com](http://data.sparkfun.com). When I try to compile the code I get an error "'postDoorStatus' was not declared in this scope" (postDoorStatus refers to a function which actually posts the door status to the [data.sparkfun.com](http://data.sparkfun.com) site). If I re-order the functions so that the postDoorStatus function is BEFORE the loop function then no problems. If I comment out the #include \<ESP8266WiFi.h\> then no problem.

I have removed almost all the code to demonstrate - even this minimal code reproduces the problem.

```cpp
#include <ESP8266WiFi.h>

//declare constants, global variables, and pin numbers

#define doorSensor 5    // GPIO 5 pin of ESP8266-12 will be the pin that sensor connects to
int lastDoorStatus = 0;  //global variable to track door status - initialize to 0 (open)

void setup() {
  
  pinMode (doorSensor, INPUT_PULLUP);
 
}

void loop() {

  int doorSensorValue = digitalRead(doorSensor); 
  postDoorStatus(doorSensorValue);
}

void postDoorStatus(int doorSensorValue) {

  //do nothing here for troubleshooting purposes

}

```

full error message:  
Arduino: 1.6.7 (Mac OS X), Board: "Generic ESP8266 Module, Serial, 80 MHz, 40MHz, DIO, 115200, 512K (64K SPIFFS), ck"

/Users/XXXX/Dropbox/Arduino/Sketchbooks/not\_in\_scope\_error\_troubleshoot/not\_in\_scope\_error\_troubleshoot.ino: In function 'void loop()':  
not\_in\_scope\_error\_troubleshoot:21: error: 'postDoorStatus' was not declared in this scope  
postDoorStatus(doorSensorValue);  
^  
exit status 1  
'postDoorStatus' was not declared in this scope

This report would have more information with  
"Show verbose output during compilation"  
enabled in File \> Preferences.

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [January 18, 2016, 6:56am UTC](https://forum.arduino.cc/t/function-not-declared-at-this-scope-when-include-esp8266wifi-h/359284/2 "2016-01-18T06:56:42Z")

</div>

In general, functions should be known to the compiler before you use them. For (to me) unknown reasons this however does not always seem to be the case (most Arduino code that I have seen / used does not seem to require it though).

You can add a prototype in the beginning of your code file

```cpp
#include <ESP8266WiFi.h>

//declare constants, global variables, and pin numbers

#define doorSensor 5    // GPIO 5 pin of ESP8266-12 will be the pin that sensor connects to
int lastDoorStatus = 0;  //global variable to track door status - initialize to 0 (open)

// prototypes here
void postDoorStatus(int doorSensorValue);

void setup() {
 
  pinMode (doorSensor, INPUT_PULLUP);
 
}
...
...

```

Alternatively you can create an include file in your project directory with all the prototypes of functions that you created and include that file in your source(s).

---

<div class="post-metadata">

**Author:** ![oqibidipo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/oqibidipo/32/221794_2.png) [@oqibidipo](https://forum.arduino.cc/u/oqibidipo)\
**Post date:** [January 18, 2016, 7:49am UTC](https://forum.arduino.cc/t/function-not-declared-at-this-scope-when-include-esp8266wifi-h/359284/3 "2016-01-18T07:49:14Z")

</div>

> <https://github.com/arduino/arduino-builder/issues/68>
>
> there's something about this header file that crashes the preprocessor, probably… indicates some more general purpose bug. reproduce by:
> \- add \`http://arduino.esp8266.com/stable/package\_esp8266com\_index.json\` to board manager prefs
> \- use board manager to install ESP8266 support
> \- try to compile this sketch
> 
> \`\`\`
> \#include "ESP8266WiFi.h"
> void setup() {}
> void loop() { hello(); }
> void hello(void) {}
> \`\`\`
> \- will fail due to not having auto-generated prototype for hello()
> \- now put \`#include "ESP8266WiFi.h"\` on last line, recompile
> \- works now because while it does crash on the #include, its after the prototypes are made (?)
> 
> Also mentioned @ https://github.com/esp8266/Arduino/issues/1066

> sterretje:  
> In general, functions should be known to the compiler before you use them. For (to me) unknown reasons this however does not always seem to be the case (most Arduino code that I have seen / used does not seem to require it though).

The IDE adds the prototypes automatically.  
In this case an external tool (ctags) fails when a certain header is included.

---

<div class="post-metadata">

**Author:** ![oqibidipo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/oqibidipo/32/221794_2.png) [@oqibidipo](https://forum.arduino.cc/u/oqibidipo)\
**Post date:** [January 21, 2016, 8:43pm UTC](https://forum.arduino.cc/t/function-not-declared-at-this-scope-when-include-esp8266wifi-h/359284/4 "2016-01-21T20:43:25Z")

</div>

The latest hourly build compiles this without errors.

---

<div class="post-metadata">

**Author:** ![nickgammon](https://avatars.discourse-cdn.com/v4/letter/n/45deac/32.png) [@nickgammon](https://forum.arduino.cc/u/nickgammon)\
**Post date:** [January 22, 2016, 2:31am UTC](https://forum.arduino.cc/t/function-not-declared-at-this-scope-when-include-esp8266wifi-h/359284/5 "2016-01-22T02:31:34Z")

</div>

> sterretje:  
> In general, functions should be known to the compiler before you use them. For (to me) unknown reasons this however does not always seem to be the case (most Arduino code that I have seen / used does not seem to require it though).

The IDE automatically generates prototypes for you, sometimes doing it wrongly.

[How to avoid the quirks of the IDE sketch file pre-preprocessing](http://www.gammon.com.au/forum/?id=12625)

---

<div class="post-metadata">

**Author:** ![68tjs](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/68tjs/32/927374_2.png) [@68tjs](https://forum.arduino.cc/u/68tjs)\
**Post date:** [January 22, 2016, 2:06pm UTC](https://forum.arduino.cc/t/function-not-declared-at-this-scope-when-include-esp8266wifi-h/359284/6 "2016-01-22T14:06:19Z")

</div>

With the IDE what's going on if we do declations functions before the setup ().

1. IDE maintains all those declarations and does not make his.
2. IDE overwrites all declarations and imposes his.

---

<div class="post-metadata">

**Author:** ![pert](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/pert/32/217111_2.png) [@pert](https://forum.arduino.cc/u/pert)\
**Post date:** [January 22, 2016, 7:54pm UTC](https://forum.arduino.cc/t/function-not-declared-at-this-scope-when-include-esp8266wifi-h/359284/7 "2016-01-22T19:54:16Z")

</div>

> 68tjs:  
> With the IDE what's going on if we do declations functions before the setup ().
> 
> 1. IDE maintains all those declarations and does not make his.
> 2. IDE overwrites all declarations and imposes his.

It does 1

---

<div class="post-metadata">

**Author:** ![68tjs](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/68tjs/32/927374_2.png) [@68tjs](https://forum.arduino.cc/u/68tjs)\
**Post date:** [January 23, 2016, 8:45am UTC](https://forum.arduino.cc/t/function-not-declared-at-this-scope-when-include-esp8266wifi-h/359284/8 "2016-01-23T08:45:11Z")

</div>

Thanks.

---

<div class="post-metadata">

**Author:** ![alangstein](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@alangstein](https://forum.arduino.cc/u/alangstein)\
**Post date:** [January 31, 2016, 11:59pm UTC](https://forum.arduino.cc/t/function-not-declared-at-this-scope-when-include-esp8266wifi-h/359284/9 "2016-01-31T23:59:17Z")

</div>

Sorry it took me a while to get back to this project. Thanks for all the helpful comments although I'm not sure I can say I actually understand the problem better now. Seems to be an idiosyncracy.

AGS

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 9:40pm UTC](https://forum.arduino.cc/t/function-not-declared-at-this-scope-when-include-esp8266wifi-h/359284/10 "2021-05-05T21:40:55Z")

</div>


