Hello,
I`m doing this course and encountered the below error.
I`m using PlatformIO but tried it also in Arduino IDE and here it works fine.
Can you please help me with what could be the issue?
Thanks and regards,
Elvio
——————– ERROR ——————–
Building in release mode
Compiling .pio\build\esp32doit-devkit-v1\src\main.cpp.o
src/main.cpp: In function ‘bool connectToServer(BLEAddress)’:
src/main.cpp:352:48: error: ‘temperatureNotifyCallback’ was not declared in this scope
temperatureCharacteristic->registerForNotify(temperatureNotifyCallback);
^
src/main.cpp:353:45: error: ‘humidityNotifyCallback’ was not declared in this scope
humidityCharacteristic->registerForNotify(humidityNotifyCallback);
^
src/main.cpp: At global scope:
src/main.cpp:370:13: warning: ‘void temperatureNotifyCallback(BLERemoteCharacteristic*, uint8_t*, size_t, bool)’ defined but not used [-Wunused-function]
static void temperatureNotifyCallback(BLERemoteCharacteristic* pBLERemoteCharacteristic,
^
src/main.cpp:378:13: warning: ‘void humidityNotifyCallback(BLERemoteCharacteristic*, uint8_t*, size_t, bool)’ defined but not used [-Wunused-function]
static void humidityNotifyCallback(BLERemoteCharacteristic* pBLERemoteCharacteristic,
^
*** [.pio\build\esp32doit-devkit-v1\src\main.cpp.o] Error 1
The “not declared in this scope” error generally means you have tried to use something that hasn’t been created yet. In this case it’s a couple of functions. What you need to do is move the functions above where they are used. So, move temperatureNotifyCallback function above temperatureCharacteristic->registerForNotify(temperatureNotifyCallback); Do the same for the humidityNotifyCallback function.
The Arduino IDE is a bit more forgiving and will let you get away with having the functions anywhere you like. PIO is stricter and will give that error which is correct.
Thanks very much, Steve, it worked immediately.
I really do appreciate your support.