'buttonTimer' was not declared in this scope

Hello, I have this error. I will give you a chunk of code, where the error is located, if you need the whole code, let me know.

if (do_chip_reboot){
    led_state = LED_OFF;
  buttonTimer Serial.println("Button pressed, the chip will reboot in " + String(buttonTimer) + "s");
    delay(buttonTimer*1000);
    ESP.restart();
    do_chip_reboot = false;
  }

And here are all my error codes

Arduino: 1.8.15 (Mac OS X), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"

/Users/Daniel/TEST_FOR_MAIL/TEST_FOR_MAIL.ino: In function 'void loop()':
TEST_FOR_MAIL:64:3: error: 'buttonTimer' was not declared in this scope
64 | buttonTimer Serial.println("Button pressed, the chip will reboot in " + String(buttonTimer) + "s");
| ^~~~~~~~~~~
/Users/Daniel/TEST_FOR_MAIL/TEST_FOR_MAIL.ino: At global scope:
TEST_FOR_MAIL:71:3: error: expected unqualified-id before 'if'
71 | if ((millis() - time_of_last_letter) > time_between_two_letters_are_detected1000 && isNewObjectDetected()) {
| ^~
TEST_FOR_MAIL:76:8: error: expected constructor, destructor, or type conversion before '(' token
76 | delay(time_between_two_measurements);
| ^
TEST_FOR_MAIL:78:3: error: expected unqualified-id before 'if'
78 | if (nbr_of_new_letters > 0) {
| ^~
TEST_FOR_MAIL:90:5: error: expected unqualified-id before 'else'
90 | } else {
| ^~~~
TEST_FOR_MAIL:98:3: error: expected unqualified-id before 'if'
98 | if (nbr_of_new_letters > 0 && (millis() - time_of_last_letter) > time_before_weebhook_is_triggered * 1000 ) {
| ^~
TEST_FOR_MAIL:132:3: error: 'Serial' does not name a type
132 | Serial.println();
| ^~~~~~
TEST_FOR_MAIL:133:1: error: expected declaration before '}' token
133 | }
| ^
/Users/Daniel/TEST_FOR_MAIL/TEST_FOR_MAIL.ino: In function 'bool sendIFTTTRequest()':
TEST_FOR_MAIL:150:18: error: 'host' was not declared in this scope
150 | Serial.println(host);
| ^~~~
TEST_FOR_MAIL:152:43: error: 'httpsPort' was not declared in this scope
152 | int connect_code = client.connect(host, httpsPort);
| ^~~~~~~~~
TEST_FOR_MAIL:156:5: error: 'closeConnection' was not declared in this scope
156 | closeConnection(client);
| ^~~~~~~~~~~~~~~
TEST_FOR_MAIL:161:18: error: 'url' was not declared in this scope
161 | Serial.println(url);
| ^~~
TEST_FOR_MAIL:178:3: error: 'closeConnection' was not declared in this scope
178 | closeConnection(client);
| ^~~~~~~~~~~~~~~
/Users/Daniel/TEST_FOR_MAIL/TEST_FOR_MAIL.ino: In function 'bool connectWifi()':
TEST_FOR_MAIL:195:7: error: 'WPA2_Entreprise_enabled' was not declared in this scope
195 | if (WPA2_Entreprise_enabled) {
| ^~~~~~~~~~~~~~~~~~~~~~~
TEST_FOR_MAIL:202:5: error: 'ssid' was not declared in this scope
202 | ssid.toCharArray(char_ssid, 32);
| ^~~~
TEST_FOR_MAIL:203:5: error: 'password' was not declared in this scope
203 | password.toCharArray(char_password, 64);
| ^~~~~~~~
TEST_FOR_MAIL:213:5: error: 'username' was not declared in this scope
213 | username.toCharArray(char_username, 32);
| ^~~~~~~~
TEST_FOR_MAIL:236:16: error: 'ssid' was not declared in this scope
236 | WiFi.begin(ssid, password);
| ^~~~
TEST_FOR_MAIL:236:22: error: 'password' was not declared in this scope
236 | WiFi.begin(ssid, password);
| ^~~~~~~~
/Users/Daniel/TEST_FOR_MAIL/TEST_FOR_MAIL.ino: At global scope:
TEST_FOR_MAIL:251:6: error: redefinition of 'void loop()'
251 | void loop() {
| ^~~~
/Users/Daniel/TEST_FOR_MAIL/TEST_FOR_MAIL.ino:59:6: note: 'void loop()' previously defined here
59 | void loop() {
| ^~~~
/Users/Daniel/TEST_FOR_MAIL/TEST_FOR_MAIL.ino: In function 'void loop()':
TEST_FOR_MAIL:252:28: error: a function-definition is not allowed here before '{' token
252 | bool isNewObjectDetected() {
| ^
TEST_FOR_MAIL:267:7: error: 'distance' was not declared in this scope; did you mean 'std::distance'?
267 | if (distance > moyenne_distance * 1.01 || distance < moyenne_distance * 0.99) {
| ^~~~~~~~
| std::distance
In file included from /Users/Daniel/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include/c++/10.3.0/bits/stl_algobase.h:66,
from /Users/Daniel/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include/c++/10.3.0/bits/specfun.h:45,
from /Users/Daniel/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include/c++/10.3.0/cmath:1927,
from /Users/Daniel/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include/c++/10.3.0/math.h:36,
from /Users/Daniel/Library/Arduino15/packages/esp8266/hardware/esp8266/3.0.2/cores/esp8266/Arduino.h:34,
from sketch/TEST_FOR_MAIL.ino.cpp:1:
/Users/Daniel/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include/c++/10.3.0/bits/stl_iterator_base_funcs.h:138:5: note: 'std::distance' declared here
138 | distance(_InputIterator __first, _InputIterator __last)
| ^~~~~~~~
TEST_FOR_MAIL:267:18: error: 'moyenne_distance' was not declared in this scope
267 | if (distance > moyenne_distance * 1.01 || distance < moyenne_distance * 0.99) {
| ^~~~~~~~~~~~~~~~
TEST_FOR_MAIL:269:5: error: 'last_10_distances' was not declared in this scope
269 | last_10_distances[1] = distance;
| ^~~~~~~~~~~~~~~~~
TEST_FOR_MAIL:274:30: error: 'distance' was not declared in this scope; did you mean 'std::distance'?
274 | while (nbr_mesure < 100 && distance > moyenne_distance * 1.01 || distance < moyenne_distance * 0.99) {
| ^~~~~~~~
| std::distance
In file included from /Users/Daniel/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include/c++/10.3.0/bits/stl_algobase.h:66,
from /Users/Daniel/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include/c++/10.3.0/bits/specfun.h:45,
from /Users/Daniel/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include/c++/10.3.0/cmath:1927,
from /Users/Daniel/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include/c++/10.3.0/math.h:36,
from /Users/Daniel/Library/Arduino15/packages/esp8266/hardware/esp8266/3.0.2/cores/esp8266/Arduino.h:34,
from sketch/TEST_FOR_MAIL.ino.cpp:1:
/Users/Daniel/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include/c++/10.3.0/bits/stl_iterator_base_funcs.h:138:5: note: 'std::distance' declared here
138 | distance(_InputIterator __first, _InputIterator __last)
| ^~~~~~~~
TEST_FOR_MAIL:274:41: error: 'moyenne_distance' was not declared in this scope
274 | while (nbr_mesure < 100 && distance > moyenne_distance * 1.01 || distance < moyenne_distance * 0.99) {
| ^~~~~~~~~~~~~~~~
TEST_FOR_MAIL:277:27: error: 'last_10_distances' was not declared in this scope
277 | moyenne_distance += last_10_distances[i];
| ^~~~~~~~~~~~~~~~~
TEST_FOR_MAIL:280:5: error: 'last_10_distances' was not declared in this scope
280 | last_10_distances[nbr_mesure % 10] = distance;
| ^~~~~~~~~~~~~~~~~
TEST_FOR_MAIL:282:23: error: 'min_time_before_next_ultrasonic' was not declared in this scope
282 | delayMicroseconds(min_time_before_next_ultrasonic);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TEST_FOR_MAIL:288:16: error: 'moyenne_distance' was not declared in this scope
288 | Serial.print(moyenne_distance);
| ^~~~~~~~~~~~~~~~
TEST_FOR_MAIL:47:26: error: expected primary-expression before '=' token
47 | #define distance_bottom = mesureDistance();
| ^
/Users/Daniel/TEST_FOR_MAIL/TEST_FOR_MAIL.ino:293:3: note: in expansion of macro 'distance_bottom'
293 | distance_bottom = distance_bottom
0.99 + moyenne_distance * 0.01;
| ^~~~~~~~~~~~~~~
TEST_FOR_MAIL:47:28: error: 'mesureDistance' was not declared in this scope
47 | #define distance_bottom = mesureDistance();
| ^~~~~~~~~~~~~~
/Users/Daniel/TEST_FOR_MAIL/TEST_FOR_MAIL.ino:293:3: note: in expansion of macro 'distance_bottom'
293 | distance_bottom = distance_bottom*0.99 + moyenne_distance * 0.01;
| ^~~~~~~~~~~~~~~
TEST_FOR_MAIL:293:19: error: expected primary-expression before '=' token
293 | distance_bottom = distance_bottom0.99 + moyenne_distance * 0.01;
| ^
TEST_FOR_MAIL:47:26: error: expected primary-expression before '=' token
47 | #define distance_bottom = mesureDistance();
| ^
/Users/Daniel/TEST_FOR_MAIL/TEST_FOR_MAIL.ino:293:21: note: in expansion of macro 'distance_bottom'
293 | distance_bottom = distance_bottom
0.99 + moyenne_distance * 0.01;
| ^~~~~~~~~~~~~~~
TEST_FOR_MAIL:293:36: error: invalid type argument of unary '' (have 'double')
293 | distance_bottom = distance_bottom
0.99 + moyenne_distance * 0.01;
| ^~~~~
TEST_FOR_MAIL:47:26: error: expected primary-expression before '=' token
47 | #define distance_bottom = mesureDistance();
| ^
/Users/Daniel/TEST_FOR_MAIL/TEST_FOR_MAIL.ino:296:50: note: in expansion of macro 'distance_bottom'
296 | if (nbr_mesure == 100 || moyenne_distance > (distance_bottom + distance_change_to_detect) || moyenne_distance < (distance_bottom - distance_change_to_detect)) {
| ^~~~~~~~~~~~~~~
TEST_FOR_MAIL:47:44: error: expected ')' before ';' token
47 | #define distance_bottom = mesureDistance();
| ^
/Users/Daniel/TEST_FOR_MAIL/TEST_FOR_MAIL.ino:296:50: note: in expansion of macro 'distance_bottom'
296 | if (nbr_mesure == 100 || moyenne_distance > (distance_bottom + distance_change_to_detect) || moyenne_distance < (distance_bottom - distance_change_to_detect)) {
| ^~~~~~~~~~~~~~~
/Users/Daniel/TEST_FOR_MAIL/TEST_FOR_MAIL.ino:296:49: note: to match this '('
296 | if (nbr_mesure == 100 || moyenne_distance > (distance_bottom + distance_change_to_detect) || moyenne_distance < (distance_bottom - distance_change_to_detect)) {
| ^
TEST_FOR_MAIL:47:44: error: expected ')' before ';' token
47 | #define distance_bottom = mesureDistance();
| ^
/Users/Daniel/TEST_FOR_MAIL/TEST_FOR_MAIL.ino:296:50: note: in expansion of macro 'distance_bottom'
296 | if (nbr_mesure == 100 || moyenne_distance > (distance_bottom + distance_change_to_detect) || moyenne_distance < (distance_bottom - distance_change_to_detect)) {
| ^~~~~~~~~~~~~~~
/Users/Daniel/TEST_FOR_MAIL/TEST_FOR_MAIL.ino:296:8: note: to match this '('
296 | if (nbr_mesure == 100 || moyenne_distance > (distance_bottom + distance_change_to_detect) || moyenne_distance < (distance_bottom - distance_change_to_detect)) {
| ^
TEST_FOR_MAIL:296:68: error: 'distance_change_to_detect' was not declared in this scope
296 | if (nbr_mesure == 100 || moyenne_distance > (distance_bottom + distance_change_to_detect) || moyenne_distance < (distance_bottom - distance_change_to_detect)) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~
TEST_FOR_MAIL:47:26: error: expected primary-expression before '=' token
47 | #define distance_bottom = mesureDistance();
| ^
/Users/Daniel/TEST_FOR_MAIL/TEST_FOR_MAIL.ino:310:28: note: in expansion of macro 'distance_bottom'
310 | if (moyenne_distance > distance_bottom - 0.5){
| ^~~~~~~~~~~~~~~
TEST_FOR_MAIL:317:10: error: return-statement with a value, in function returning 'void' [-fpermissive]
317 | return false;
| ^~~~~
/Users/Daniel/TEST_FOR_MAIL/TEST_FOR_MAIL.ino: At global scope:
TEST_FOR_MAIL:54:23: error: variable or field 'timer1_attachInterrupt' declared void
54 | #define ledInterrupt timer1_attachInterrupt(ledInterrupt);
| ^~~~~~~~~~~~~~~~~~~~~~
/Users/Daniel/TEST_FOR_MAIL/TEST_FOR_MAIL.ino:346:22: note: in expansion of macro 'ledInterrupt'
346 | ICACHE_RAM_ATTR void ledInterrupt(){
| ^~~~~~~~~~~~
TEST_FOR_MAIL:54:46: error: 'ledInterrupt' was not declared in this scope
54 | #define ledInterrupt timer1_attachInterrupt(ledInterrupt);
| ^~~~~~~~~~~~
/Users/Daniel/TEST_FOR_MAIL/TEST_FOR_MAIL.ino:346:22: note: in expansion of macro 'ledInterrupt'
346 | ICACHE_RAM_ATTR void ledInterrupt(){
| ^~~~~~~~~~~~
TEST_FOR_MAIL:346:35: error: expected unqualified-id before ')' token
346 | ICACHE_RAM_ATTR void ledInterrupt(){
| ^
TEST_FOR_MAIL:51:21: error: variable or field 'attachInterrupt' declared void
51 | #define rebootChip attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), rebootChip, RISING);
| ^~~~~~~~~~~~~~~
/Users/Daniel/TEST_FOR_MAIL/TEST_FOR_MAIL.ino:420:22: note: in expansion of macro 'rebootChip'
420 | ICACHE_RAM_ATTR void rebootChip(){
| ^~~~~~~~~~
TEST_FOR_MAIL:51:72: error: 'rebootChip' was not declared in this scope
51 | #define rebootChip attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), rebootChip, RISING);
| ^~~~~~~~~~
/Users/Daniel/TEST_FOR_MAIL/TEST_FOR_MAIL.ino:420:22: note: in expansion of macro 'rebootChip'
420 | ICACHE_RAM_ATTR void rebootChip(){
| ^~~~~~~~~~
TEST_FOR_MAIL:420:33: error: expected unqualified-id before ')' token
420 | ICACHE_RAM_ATTR void rebootChip(){
| ^
exit status 1
'buttonTimer' was not declared in this scope

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

here is where I got my code from:

What on earth is this line supposed to mean? It doesn't follow C++ syntax.

Hi, If you look at the orginal source code on the github site you can see the section of code, You have a syntax error on the line:

buttonTimer Serial.println("Button pressed, the chip will reboot in " + String(buttonTimer) + "s");

buttonTimer is a variable and Serial.println() is a command. buttonTimer should not be on this line of code.

Look at the orignal source:

led_state = LED_OFF;
Serial.println("Button pressed, the chip will reboot in " + String(button_timer) + "s");
delay(button_timer*1000);
ESP.restart();
do_chip_reboot = false;

Remove the buttonTimer variable and re-compile again.

Good luck with your project

Hello, Thanks for the quick reply.Thank you for the way you wrote. It was clear and I could understand it well. Even if I do remove what you said to remove, I still get the same error. Any ideas?

Hi, In example.h there is a line that declares const int button_timer = 60 ;
Make sure your .cpp file has an include statement for example.h

The reason you are getting the compile error is that the .cpp file cannot find a declaration for botton_timer

Thanks

Hello, thank you for your advice, but how would I do that? To find the special file?

(The cpp file)

On the github site, included in the link in your post, there are several files, I am assuming you copied and pasted the code from the .cpp file to your code. Download the rest of the files from github. Put those files in your Arduino folder where your project is and then place an include statement in your .cpp file at the top #include "example.h"

Thanks