Fix BLE discovery sketch for current NimBLE API
This commit is contained in:
@@ -14,7 +14,7 @@ void setup() {
|
||||
NimBLEDevice::init("XterraESP32");
|
||||
NimBLEDevice::setPower(ESP_PWR_LVL_P9);
|
||||
|
||||
NimBLEAddress address(TARGET_ADDRESS);
|
||||
NimBLEAddress address(std::string(TARGET_ADDRESS), BLE_ADDR_PUBLIC);
|
||||
NimBLEClient* client = NimBLEDevice::createClient();
|
||||
|
||||
Serial.println("Connecting...");
|
||||
@@ -28,29 +28,19 @@ void setup() {
|
||||
Serial.println("Connected.");
|
||||
Serial.println("Discovering services...");
|
||||
|
||||
std::vector<NimBLERemoteService*>* services = client->getServices(true);
|
||||
|
||||
if (!services) {
|
||||
Serial.println("No services found.");
|
||||
client->disconnect();
|
||||
return;
|
||||
}
|
||||
const std::vector<NimBLERemoteService*>& services = client->getServices(true);
|
||||
|
||||
Serial.print("Service count: ");
|
||||
Serial.println(services->size());
|
||||
Serial.println(services.size());
|
||||
|
||||
for (auto service : *services) {
|
||||
for (NimBLERemoteService* service : services) {
|
||||
Serial.print("Service UUID: ");
|
||||
Serial.println(service->getUUID().toString().c_str());
|
||||
|
||||
std::vector<NimBLERemoteCharacteristic*>* chars =
|
||||
const std::vector<NimBLERemoteCharacteristic*>& chars =
|
||||
service->getCharacteristics(true);
|
||||
|
||||
if (!chars) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (auto ch : *chars) {
|
||||
for (NimBLERemoteCharacteristic* ch : chars) {
|
||||
Serial.print(" Characteristic UUID: ");
|
||||
Serial.print(ch->getUUID().toString().c_str());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user