Как расширить возможное количество сервисов BLE на ESP32 - PullRequest
0 голосов
/ 25 января 2020

Я пытаюсь предоставить около 18 различных сервисов на одном BLE-устройстве. Устройство, которое я выбрал, - ESP32. Если я попробую следующий код в Arduino-IDE, код остановится (больше не будет операторов в последовательном мониторе) после запуска 7 сервисов.

Ограничено ли количество возможных BLE-сервисов на ESP32 или может Я что-то изменил в коде, чтобы расширить число?

Заранее спасибо

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

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>

// See the following for generating UUIDs:
// https://www.uuidgenerator.net/

#define SERVICE1_UUID        "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define SERVICE2_UUID        "5fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define SERVICE3_UUID        "6fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define SERVICE4_UUID        "7fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define SERVICE5_UUID        "8fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define SERVICE6_UUID        "9fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define SERVICE7_UUID        "4fafc301-1fb5-459e-8fcc-c5c9c331914b"
#define SERVICE8_UUID        "4fafc401-1fb5-459e-8fcc-c5c9c331914b"
#define SERVICE9_UUID        "4fafc501-1fb5-459e-8fcc-c5c9c331914b"
#define SERVICE10_UUID       "4fafc601-1fb5-459e-8fcc-c5c9c331914b"

void setup() {
  Serial.begin(115200);
  Serial.println("Starting BLE work!");

  BLEDevice::init("Long name works now");
  BLEServer *pServer = BLEDevice::createServer();

  Serial.println("Service1");
  BLEService *pService1 = pServer->createService(SERVICE1_UUID);
  BLECharacteristic *pCharacteristic1 = pService1->createCharacteristic(SERVICE1_UUID, BLECharacteristic::PROPERTY_READ);
  pCharacteristic1->setValue("Hello World says Neil");
  pService1->start();

  Serial.println("Service2");
  BLEService *pService2 = pServer->createService(SERVICE2_UUID);
  BLECharacteristic *pCharacteristic2 = pService2->createCharacteristic(SERVICE2_UUID, BLECharacteristic::PROPERTY_READ);
  pCharacteristic2->setValue("Hello World says Neil");
  pService2->start();

  Serial.println("Service3");
  BLEService *pService3 = pServer->createService(SERVICE3_UUID);
  BLECharacteristic *pCharacteristic3 = pService3->createCharacteristic(SERVICE3_UUID, BLECharacteristic::PROPERTY_READ);
  pCharacteristic3->setValue("Hello World says Neil");
  pService3->start();

  Serial.println("Service4");
  BLEService *pService4 = pServer->createService(SERVICE4_UUID);
  BLECharacteristic *pCharacteristic4 = pService4->createCharacteristic(SERVICE4_UUID, BLECharacteristic::PROPERTY_READ);
  pCharacteristic4->setValue("Hello World says Neil");
  pService4->start();

  Serial.println("Service5");
  BLEService *pService5 = pServer->createService(SERVICE5_UUID);
  BLECharacteristic *pCharacteristic5 = pService5->createCharacteristic(SERVICE5_UUID, BLECharacteristic::PROPERTY_READ);
  pCharacteristic5->setValue("Hello World says Neil");
  pService5->start();

  Serial.println("Service6");
  BLEService *pService6 = pServer->createService(SERVICE6_UUID);
  BLECharacteristic *pCharacteristic6 = pService6->createCharacteristic(SERVICE6_UUID, BLECharacteristic::PROPERTY_READ);
  pCharacteristic6->setValue("Hello World says Neil");
  pService6->start();

  Serial.println("Service7");
  BLEService *pService7 = pServer->createService(SERVICE7_UUID);
  BLECharacteristic *pCharacteristic7 = pService7->createCharacteristic(SERVICE7_UUID, BLECharacteristic::PROPERTY_READ);
  pCharacteristic7->setValue("Hello World says Neil");
  pService7->start();

  Serial.println("Service8");
  BLEService *pService8 = pServer->createService(SERVICE8_UUID);
  BLECharacteristic *pCharacteristic8 = pService8->createCharacteristic(SERVICE8_UUID, BLECharacteristic::PROPERTY_READ);
  pCharacteristic8->setValue("Hello World says Neil");
  pService8->start();

  Serial.println("Service9");
  BLEService *pService9 = pServer->createService(SERVICE9_UUID);
  BLECharacteristic *pCharacteristic9 = pService9->createCharacteristic(SERVICE9_UUID, BLECharacteristic::PROPERTY_READ);
  pCharacteristic9->setValue("Hello World says Neil");
  pService9->start();

  Serial.println("Service10");
  BLEService *pService10 = pServer->createService(SERVICE10_UUID);
  BLECharacteristic *pCharacteristic10 = pService10->createCharacteristic(SERVICE10_UUID, BLECharacteristic::PROPERTY_READ);
  pCharacteristic10->setValue("Hello World says Neil");
  pService10->start();


  BLEDevice::startAdvertising();
  Serial.println("Characteristic defined! Now you can read it in your phone!");
}

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