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