Author Topic: Starting out with BLE - can multiple services be advertised?  (Read 293 times)

0 Members and 1 Guest are viewing this topic.

Offline dvhTopic starter

  • Contributor
  • Posts: 18
  • Country: hu
Starting out with BLE - can multiple services be advertised?
« on: March 04, 2024, 08:33:02 am »
Hello everyone!

I'm working on a tiny project where I'd like some connectivity between my phone and a BLE enabled devboard (ESP-WROOM-32). Ideally, it'd be a non-connectable, undirected broadcaster with pieces of sensor data embedded in advertisement packets.

I've been digging through some arduino BLE libraries and found a wrapper aroundmyNewt nimble for Arduino.

Right out of the box, I got into problems with advertising multiple services. Here is my code:

Code: [Select]
#include <NimBLEDevice.h>

// [url]https://www.uuidgenerator.net/[/url]

#define SERVICE_UUID1        "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define SERVICE_UUID2        "525bb0f4-7856-47d8-8f92-7f209aa3fb2e"

static NimBLEUUID serviceID1(SERVICE_UUID1);
static NimBLEUUID serviceID2(SERVICE_UUID2);
static NimBLEAdvertising *pAdvert = nullptr;
static uint32_t count = 0;

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

  NimBLEDevice::init("SmartPot"); 
  pAdvert = NimBLEDevice::getAdvertising();
}

void loop() {

  pAdvert->stop();
  pAdvert->setAdvertisementType(BLE_GAP_CONN_MODE_NON);
  pAdvert->setServiceData(serviceID1, std::string((char*)&count, sizeof(count))); 
  pAdvert->setServiceData(serviceID2, std::string("bleh"));

  pAdvert->start();   
  Serial.printf("Advertising count = %d\n", count);
  count++;
  delay(5000);
}

Questions:

  • Am I correct assuming that it should be possible to advert multiple 128 bit services with data by the spec?
  • Could it be that it's the wrapper that does something weird for which reason the code sample doesn't work?
  • Do you have experience with that library? Should I keep investing time learning it or should I go straight to ESP-IDF?
  • Do you have recommendations for a decent higher level abstraction for working with BLE & Arduino?

Thanks in advance!
« Last Edit: March 04, 2024, 08:34:43 am by dvh »
 

Offline Smokey

  • Super Contributor
  • ***
  • Posts: 2597
  • Country: us
  • Not An Expert
 

Offline dvhTopic starter

  • Contributor
  • Posts: 18
  • Country: hu
Re: Starting out with BLE - can multiple services be advertised?
« Reply #2 on: March 05, 2024, 08:52:08 am »
That didn't help much.

But I managed to piece together from other sources that there is a 31 octet limit on the size of the advert packet. If I want to advertise multiple services, I have to implement scan response too.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf