Commit graph

32 commits

Author SHA1 Message Date
h2zero
cf482f9112 Cleanup ARM-gcc compiler warnings. 2022-01-15 12:43:17 -07:00
h2zero
d47cf59ba9 Cleanup compile errors in arm-gcc. 2022-01-14 20:45:24 -07:00
h2zero
0957d7f6ad The latest versions of IDF include a new esp_timer library that seems to be incrementing the task notification values in unexpected places depending on other tasks in operation.
This causes task blocking to fail in client operations leading to exceptions and crashing.

This is a workaround for this situation and will need to be reworked properly in the future.
2022-01-09 19:04:41 -07:00
h2zero
f2ade345f4 Fix missing data when reading large values.
The wrong length value was being used to set the values read from peer attributes.
This has been corrected to use the proper value size.
2021-12-29 14:01:37 -07:00
h2zero
9debfcd226 Use NimBLE calls for critical sections 2021-12-29 08:10:57 -07:00
h2zero
ccea428b9e Refactor include directives to use different paths for arduino/idf.
* Sets macros to allow compiling when Central role is enabled and Observer disabled, or Peripheral enabled and Broadcaster disabled.

* Adds a macro definition for CONFIG_NIMBLE_CPP_IDF to enable different include paths/functionality for IDF / Arduino.
2021-09-12 18:43:31 -06:00
boozer2
30d6c399b8 [Client] Fix for truncation of strings with null in writeValue std::string overload 2021-05-21 19:54:08 -06:00
h2zero
946b971750 Properly find the remote characteristic end handle for descriptor discovery.
Previously we used the service end handle or, if available, the handle of the next characteristic in the service
as the end handle when retrieving the descriptors of a characteristic. This process would fail when connecting to some
devices if the characteristics were retrieved individually instead of all together. The cause of failure was requesting
a handle range that is out of characteristic scope which is also out of line with BLE
specifications.

The fix included in this is to set the end handles of the characteristics either after retrieving all the characteristics
in a service by using the next charactertistic definition handle or, if the characteristic was retrieved separately,
we retrieve the next characteristic just before retrieving the descriptors.
2021-05-17 14:37:03 -06:00
wakwak_koba
b064cc65d4 Find characteristic end handle using the next characterisic handle.
On some devices, searching for descriptors using the service end handle would return an invalid error.
This patch instead uses the handle of the next characteristic as the end handle (if available).
2021-01-13 18:05:19 -07:00
h2zero
39a3a63f80 Fix attributes not found with 16/32bit UUIDs.
* Some peripherals will advertise 16/32bit UUIDs but when queried for their handles
they do not convert the UUID to 128 bit locally and will return attribute not found.

This patch will query the peripheral a second time with a 128bit converted UUID.
2020-12-28 15:40:01 -07:00
h2zero
27fc792952 Fix UUID comparison for 16bit + base UUID's
* Add more information to UUID debug messages.
2020-12-28 12:05:54 -07:00
Deepak Singhal
36317e18db Allow subscribing to characteristics if CCCD does not exist on peer device.
- This changes NimBLERemoteCharacteristic::subscribe and NimBLERemoteCharacteristic::registerForNotify functionality
such that the notification callback will always be set.

Additionally these methods will always return true unless the descriptor write fails.

This allows for notifications to trigger the callback when a peer device sends them and does not have a CCCD.
Also it should not be flagged as a failure if the CCCD does not exist.
It should only be flagged when an acutal write operation fails.
2020-12-24 19:59:45 -07:00
Anthony Doud
7ed962d963 Fix crashing caused by calling time() in a critical section (#159)
* Fix for random notify crash in ISR context

Tested for stability over 30 minutes with a daisy chain of 3 esp32

Co-authored-by: h2zero <powellperalta@gmail.com>
2020-12-19 21:58:37 -07:00
h2zero
6df7b1331a Refactor NimBLERemoteCharacteristic::subscribe
* Rearrange subscribe parameters to remove requirement of specifying write response to register a callback.
2020-07-08 21:10:11 -06:00
h2zero
aae2a8f1e3
Fix comments for doxygen (#16)
* Fix comments for doxygen

* Add documentation and update readme.
2020-07-08 19:27:26 -06:00
h2zero
8d2821a429 Use templates for attribute values.
* Add timestamps for NimBLECharacteristic.
2020-07-01 17:32:41 -06:00
h2zero
05a5d0dea9 Make getDescriptors() work as getCharacteristics() 2020-06-24 19:33:04 -06:00
h2zero
f5541d18de
Replace semaphores with task notifications. (#9)
* Replace all semaphores with task notifications.

* use critical sections to prevent concurrent data access.

* Ensure scan stop has been called before connecting.

* Optimize and cleanup

* Add template casting to NimBLERemoteDescriptor::readValue()

* Removed storage of the descriptor value read as it did not serve any purpose.
2020-06-21 22:07:01 -06:00
h2zero
f624deacb5 Add register for notify without callback
* Add subscribe() and unsubscribe() methods to replace registerForNotify() in NimBLERemoteCharacteristic.

* registerForNotify() remains as a (depreciated) method.
2020-06-19 12:30:32 -06:00
h2zero
143631d327 Make attribute delete functions public and selective by UUID
* Make remote attribute delete functions public.

* Rename clear...() functions to delete...(), with ... equals Service(-s), Characteristic(-s) or Descriptor(-s), depending on what the function actually deletes
2020-05-29 21:21:56 -06:00
h2zero
ffcb325aea Remove getRawData() and getDataLength()
Previously getRawData() made an unnecessary copy of the remote characteristic value data in order to return a uint8_t*. The resources used for this was unjustified by the value it provided as templates to retrieve such data have been added. Also the application writer could cast the std::string result of readValue() and/or getValue() however they choose using the data() method on the container if desired.

getDataLength() is also an unnecessary function as the length can be retrieved by the returned std::string from readValue() and/or getValue() with the length() method.
2020-05-29 20:49:46 -06:00
h2zero
99ad62cdd4 Add template casting to readValue and advertisement data (#52)
The value returned by reading a remote characteristic or by getting a notification for it is kept in the class instance of the NimBLERemoteCharacteristic. This value can be accessed as a std::string type using the getValue() function.

This adds templates to read the value in the type used by the peripheral. The same functionality is implemented for getting the manufacturer data or the service data of an advertised device.
2020-05-29 20:02:26 -06:00
h2zero
10f544f80a 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
2020-05-29 18:26:41 -06:00
h2zero
c5c9423893 Remove automatic discovery in NimBLEClient::connect().
Instead of discovering the peripheral database on connection and consuming
the associated resources this will give the user more control over the
discovery operation.

* Adds void NimBLEClient::discoverAtrributes() for the user to discover all
the peripheral attributes as a replacement for the former functionality.

* getServices(), getCharacteristics(), getDescriptors() now take an
optional bool parameter (default false).
If true it will clear the respective vector and retrieve all the respective
attributes from the peripheral. If false it will retrieve the attributes
only if the vector is empty, otherwise the vector is returned with the
currently stored attributes.

* getService(NimBLEUUID), getCharacteristic(NimBLEUUID), getDescriptor(NimBLEUUID)
will now check the respective vectors for the attribute object and, if not
found, will retrieve (only) the specified attribute from the peripheral.
2020-05-23 10:30:11 -06:00
h2zero
10e50a8791 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.
2020-05-22 20:13:52 -06:00
h2zero
6f4ee4b498 Breaking: Use std::vector instead of std::map in client classes (#46)
* Exchange map for vector, saving 1,076 bytes of program memory and 5,024 bytes of heap for a small device (LYWSD03MMC)

* Removing m_characteristicMapByHandle (using the handles form m_characteristicVector instead) saving in total (compared to the current master) 1,508 bytes of program memory and 6,500 bytes of heap for a small device (LYWSD03MMC)

* Change NimBLEScan container from std::map to std::vector

* Add function to get advertised device by address

* Update documentation
2020-05-17 20:22:58 -06:00
h2zero
03cb7b21d9 Conditionally compile code for specific roles.
This allows NimBLE options in menuconfig to reduce code size based on
the roles selected (scan/advertising/central/peripheral).

Significant code space can be saved by removing unnecessary roles for the application.
2020-05-13 22:03:56 -06:00
h2zero
f0191eb1e6 Add ==,!= operators to NimBLEAddress, pass parameters by const reference. 2020-05-10 07:21:46 -06:00
h2zero
59823b4bf0 Implement client long read / write
Client will now read/write long characteristics and descriptors.
2020-05-07 19:51:15 -06:00
h2zero
3327a32341 Merge bugfix branch into master 2020-04-13 19:13:51 -06:00
h2zero
74ba03e3a8 Add CMakeLists.txt.
Fix compilation in strict enviroments.
Fix compliation in IDF v4.0.
2020-03-31 20:16:27 -06:00
h2zero
5d4332e945 Initial commit. 2020-03-29 17:44:20 -06:00