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 around
myNewt nimble for
Arduino.
Right out of the box, I got into problems with advertising multiple services. Here is my code:
#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!