Update remote characteristic value from a notification

* Add NimBLERemoteCharacteristic::getValue(time_t *timestamp = nullptr) to get the latest remote characteristic and (optionally) it's timestamp.

* Added a timestamp to NimBLEAdvertisedDevice for the moment a device was scanned
This commit is contained in:
h2zero
2020-05-29 18:26:41 -06:00
parent 5667c97efe
commit 10f544f80a
7 changed files with 37 additions and 6 deletions

View File

@@ -720,6 +720,11 @@ uint16_t NimBLEClient::getMTU() {
if(characteristic != cVector->cend()) {
NIMBLE_LOGD(LOG_TAG, "Got Notification for characteristic %s", (*characteristic)->toString().c_str());
if((*characteristic)->m_semaphoreReadCharEvt.take(0, "notifyValue")) {
(*characteristic)->m_value = std::string((char *)event->notify_rx.om->om_data, event->notify_rx.om->om_len);
(*characteristic)->m_timestamp = time(nullptr);
(*characteristic)->m_semaphoreReadCharEvt.give();
}
if ((*characteristic)->m_notifyCallback != nullptr) {
NIMBLE_LOGD(LOG_TAG, "Invoking callback for notification on characteristic %s",
(*characteristic)->toString().c_str());
@@ -727,7 +732,6 @@ uint16_t NimBLEClient::getMTU() {
event->notify_rx.om->om_len,
!event->notify_rx.indication);
}
break;
}
}