nkolban / esp32-snippets

Sample ESP32 snippets and code fragments
https://leanpub.com/kolban-ESP32
Apache License 2.0
2.35k stars 710 forks source link

ESP IDF compile errors - error: 'Serial' was not declared in this scope #350

Open BladeRunner68 opened 6 years ago

BladeRunner68 commented 6 years ago

Beginner Warning!! Having moved from PlatformIO to using the esp IDF toolchain I am getting the errors below when I try and compile some sample code for C++. Am I missing something really obvious here with my initial attempts?

MINGW32 ~/esp/stblescan $ make CXX build/main/stblescan.o C:/msys32/home/simon/esp/stblescan/main/stblescan.cpp: In member function 'virtual void MyAdvertisedDeviceCallbacks::onResult(BLEAdvertisedDevice)': C:/msys32/home/simon/esp/stblescan/main/stblescan.cpp:17:7: error: 'Serial' was not declared in this scope Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str()); ^ C:/msys32/home/simon/esp/stblescan/main/stblescan.cpp: In function 'void setup()': C:/msys32/home/simon/esp/stblescan/main/stblescan.cpp:23:3: error: 'Serial' was not declared in this scope Serial.begin(115200); ^ C:/msys32/home/simon/esp/stblescan/main/stblescan.cpp: In function 'void loop()': C:/msys32/home/simon/esp/stblescan/main/stblescan.cpp:38:13: error: 'delay' was not declared in this scope delay(2000); ^ make[1]: [/home/simon/esp/esp-idf/make/component_wrapper.mk:274: stblescan.o] Error 1 make: [C:/msys32/home/simon/esp/esp-idf/make/project.mk:450: component-main-build] Error 2

Here is the example code for stblescan.cpp:

/ Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp Ported to Arduino ESP32 by Evandro Copercini /

include "BLEDevice.h"

include "BLEUtils.h"

include "BLEScan.h"

include "BLEAdvertisedDevice.h"

int scanTime = 30; //In seconds

class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { void onResult(BLEAdvertisedDevice advertisedDevice) {

  Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str());

}

};

void setup() { Serial.begin(115200); Serial.println("Scanning...");

BLEDevice::init(""); BLEScan* pBLEScan = BLEDevice::getScan(); //create new scan pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster BLEScanResults foundDevices = pBLEScan->start(scanTime); Serial.print("Devices found: "); Serial.println(foundDevices.getCount()); Serial.println("Scan done!"); }

void loop() { // put your main code here, to run repeatedly: delay(2000); }

chegewara commented 6 years ago

You are trying to compile arduino-ide code with esp-idf. Try those tests: https://github.com/nkolban/esp32-snippets/tree/master/cpp_utils/tests/BLETests