mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2026-01-26 17:12:31 +01:00
Add iterators to client remote attributes.
Add iterators for NimBLEScan: NimBLEadvertisedDevice, NimBLEClient: NimBLERemoteService, NimBLERemoteService: NimBLERemoteCharacteristic and NimBLERemoteCharacteristic: NimBLERemoteDescriptor
This is handy e.g. for showing every address of the advertised devices from a scan. To do so, first get a new scan and next:
```
for(auto pAdvertisedDevice: pBLEScan->getResults()) {
Serial.printf("Address is %s\n", std::string(pAdvertisedDevice->getAddress()).c_str());
}
```
Of course any other property of the advertised device can be shown (or looked up, if that is your use case)
Also this is handy e.g. for showing every UUID in a peripheral. To do so, first connect to a peripheral and next:
```
for(auto pService: *pClient) {
Serial.printf("Service UUID is %s\n", std::string(pService->getUUID()).c_str());
for(auto pCharacteristic: *pService) {
Serial.printf("Characteristic UUID is %s\n", std::string(pCharacteristic->getUUID()).c_str());
for(auto pDescriptor: *pCharacteristic) {
Serial.printf("Descriptor UUID is %s\n", std::string(pDescriptor->getUUID()).c_str());
}
}
}
```
Again of course any other property can be shown, or looked up.
This commit is contained in:
@@ -404,6 +404,24 @@ NimBLEAdvertisedDevice NimBLEScanResults::getDevice(uint32_t i) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get iterator to the beginning of the vector of advertised device pointers.
|
||||
* @return An iterator to the beginning of the vector of advertised device pointers.
|
||||
*/
|
||||
std::vector<NimBLEAdvertisedDevice*>::iterator NimBLEScanResults::begin() {
|
||||
return m_advertisedDevicesVector.begin();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get iterator to the end of the vector of advertised device pointers.
|
||||
* @return An iterator to the end of the vector of advertised device pointers.
|
||||
*/
|
||||
std::vector<NimBLEAdvertisedDevice*>::iterator NimBLEScanResults::end() {
|
||||
return m_advertisedDevicesVector.end();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Return a pointer to the specified device at the given address.
|
||||
* If the address is not found a nullptr is returned.
|
||||
|
||||
Reference in New Issue
Block a user