logo elektroda
logo elektroda
X
logo elektroda

[Solved] [Nano ESP32]Problem compiling on Platformio a file that compiles under Arduino

gmp 651 1
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 20955976
    gmp
    Level 19  
    I started playing around with an Arduino nano ESP32, and got the BLE scanner running in the Arduino environment. Unfortunately the same program cannot find some libraries. I tried adding them manually and also nothing.
    Of course I added manually:
    #include <Arduino.h> /added
    #include <ArduinoBLE.h> /added
    .
    I can't see the libraries below #include <BLEDevice.h>

    /*
       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 <Arduino.h>   //dodane 
    #include <ArduinoBLE.h> //dodane
    
    
    #include <BLEDevice.h>
    #include <BLEUtils.h>
    #include <BLEScan.h>
    #include <BLEAdvertisedDevice.h>
    
    
    #include <BLEDevice.h>
    #include <BLEUtils.h>
    #include <BLEScan.h>
    #include <BLEAdvertisedDevice.h>
    
    int scanTime = 5; //In seconds
    BLEScan* pBLEScan;
    
    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("");
      pBLEScan = BLEDevice::getScan(); //create new scan
      pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
      pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
      pBLEScan->setInterval(100);
      pBLEScan->setWindow(99);  // less or equal setInterval value
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
      Serial.print("Devices found: ");
      Serial.println(foundDevices.getCount());
      Serial.println("Scan done!");
      pBLEScan->clearResults();   // delete results fromBLEScan buffer to release memory
      delay(2000);
    }
    .
    Do you have a problem with Arduino? Ask question. Visit our forum Arduino.
  • ADVERTISEMENT
  • #2 20956460
    gmp
    Level 19  
    The problem solved 'by itself'. By the oldest known method. I reinstalled VSCode and platformio. Now, at compile time, the system adds the missing .h and .cpp files, I don't know where platformio copies them from, but it works. Strange that it didn't work before, even though I had all the updates installed. Maybe it has accumulated too much over the years.
ADVERTISEMENT