I am working on an iOS Bluetooth LE application. The functionality which I am able to follow correctly and successfully are as follows :
Here I am facing a problem, I need to read incoming data only when the BLE device transmit it to app. I'm explicitly reading the characteristics on button click. My BLE device is continuously transmitting some data in particular intervals, but I am not able to get it.
I have set the setNotify as well on characteristics, not success on it as well.
[peripheral setNotifyValue:YES forCharacteristic:characteristic];
How can my app be notified by the BLE device event (sending by it to app)? Please help me here or suggest me something.
Thanks in advance.
On the peripheral side, it is necessary to set the properties of the characteristic to enable notifications. You do this with the CBCharacteristicPropertyNotify property. For example, the following is how you might create the characteristic:
CBMutableCharacteristic *alertLevelCharacteristic =
[[CBMutableCharacteristic alloc] initWithType:alertLevelCharacteristicUUID
properties:CBCharacteristicPropertyRead | CBCharacteristicPropertyNotify
value: nil permissions:CBAttributePermissionsReadable];
What you are doing should work. All data that arrives from the Peripheral will come to the didUpdateValueForCharacteristic
callback method. Look for it there.
So whether you explicitly call the readCharacteristic
method or just set up your peripheral to notify you when it has data available (like an alarm, or a heart beat), you will still receive the data the same place.
Note: When you do send the setNotifyValue
message you should receive a callback on the didUpdateNotificationStateForCharacteristic
method with no error. If not, I suggest you look at your Peripheral firmware and make sure that characteristic is not read/write only.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With