«полуживой» Bluetooth на ESP32S3 N16R8

Добрый день, мучаюсь уже 2 дня с ESP32S3 N16R8 и поиском ей BLE устройств . То находит то не находит, но чаще не находит :grin:

Это у меня бракованная еспшка или именно с этой моделью есть какие-то нюансы?

#include <BLEDevice.h>

#include <BLEServer.h>

#include <BLEUtils.h>

#include <BLE2902.h>

#include <BLEScan.h>

#include <BLEAdvertisedDevice.h>




// ---------- Настройки GATT-сервера ----------

BLEServer* pServer = nullptr;

BLECharacteristic* pCharacteristic = nullptr;




#define SERVICE_UUID        "12345678-1234-1234-1234-1234567890ab"

#define CHARACTERISTIC_UUID "abcdefab-1234-1234-1234-abcdefabcdef"




// ---------- Настройки BLE-сканера ----------

int scanTime = 5; // время сканирования в секундах

BLEScan* pBLEScan;




class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {

    void onResult(BLEAdvertisedDevice advertisedDevice) {

      String output = "Device found: ";

      String name = advertisedDevice.getName().c_str();

      if(name.length() == 0) name = "<no name>";

      output += "[" + advertisedDevice.getAddress().toString() + "]";

      output += " Name: " + name;

      output += " RSSI: " + String(advertisedDevice.getRSSI());

      Serial.println(output);

    }

};




void setup() {

  Serial.begin(115200);

  Serial.setTimeout(5000);

  delay(1000);




  Serial.println("Initializing BLE server...");




  // ----------------- GATT-сервер -----------------

  BLEDevice::init("ESP32_S3_PERIPHERAL");

  pServer = BLEDevice::createServer();




  BLEService *pService = pServer->createService(SERVICE_UUID);

  pCharacteristic = pService->createCharacteristic(

                      CHARACTERISTIC_UUID,

                      BLECharacteristic::PROPERTY_READ |

                      BLECharacteristic::PROPERTY_WRITE

                    );

  pCharacteristic->setValue("ESP32S3 BLE OK");

  pService->start();




  BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();

  pAdvertising->addServiceUUID(pService->getUUID());

  pAdvertising->setScanResponse(true);

  pAdvertising->setMinInterval(0x20); // 20ms

  pAdvertising->setMaxInterval(0x40); // 40ms

  pAdvertising->start();




  Serial.println("BLE server advertising started");




  // ----------------- BLE-сканер -----------------

  Serial.println("Initializing BLE scan...");

  pBLEScan = BLEDevice::getScan();

  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());

  pBLEScan->setActiveScan(true);

  pBLEScan->setInterval(100);

  pBLEScan->setWindow(99);

}




void loop() {

  // 1) Сканиуем BLE-устройства

  Serial.println("Scanning for BLE devices...");

  BLEScanResults* foundDevices = pBLEScan->start(scanTime, false);

  Serial.print("Devices found: ");

  Serial.println(foundDevices->getCount());

  pBLEScan->clearResults();




  // 2) Обновление характеристик сервера при необходимости

  // pCharacteristic->setValue("новое значение");




  delay(3000); // пауза между сканированиями

}

ESP-ROM:esp32s3-20210327 Initializing BLE server…

BLE server advertising started Initializing BLE scan…

Scanning for BLE devices… Initializing BLE server…

BLE server advertising started Initializing BLE scan…

Scanning for BLE devices…

Devices found: 0 Scanning for BLE devices…

Device found: [48:77:5d:d8:e4:03] Name: RSSI: -90 Devices found: 1

Scanning for BLE devices…

Devices found: 0 Scanning for BLE devices…

Devices found: 0 Scanning for BLE devices…

Devices found: 0 Scanning for BLE devices…

Devices found: 0 Scanning for BLE devices…

Devices found: 0 Scanning for BLE devices…

Devices found: 0 Scanning for BLE devices…

Devices found: 0 Scanning for BLE devices…

d3:b9:6e:1a] Name: RSSI: -62 Device found: [86:67:7a:67:a2:52] Name: RSSI: -81

Devices found: 2 Scanning for BLE devices…

Devices found: 0 Scanning for BLE devices…

Devices found: 0 Scanning for BLE devices…

Проверьте питание, кабель. Попробуйте “запитать” от другой источника