How to get notification from Bluetooth LE devices in iOS app

I am working on an iOS Bluetooth LE app. The functionality with which I can follow correctly and successfully is as follows:

  • Peripheral device discovery.
  • Connection to a peripheral device.
  • Getting services and features.
  • The ability to read data from the characteristics when you click the read button.
  • Ability to record data.

Here I ran into a problem, I only need to read the incoming data when the BLE device passes it to the application. I explicitly read the specifications when the button is clicked. My BLE device continuously transmits some data at specific intervals, but I cannot receive it.

I also set setNotify by characteristics, but did not have time on it.

[peripheral setNotifyValue:YES forCharacteristic:characteristic]; 

How can my application be notified by a BLE device event (sending it to the application)? Please help me here or suggest something.

Thanks in advance.

+6
source share
2 answers

What you do should work. All data coming from the peripheral device will return to the didUpdateValueForCharacteristic callback method. Look for him there.

That way, if you explicitly call the readCharacteristic method or just set up a peripheral device to notify you when it has available data (like an alarm clock or heart rate), you will still receive data in the same place.

Note When you send a setNotifyValue message, you should receive a callback using the didUpdateNotificationStateForCharacteristic method without errors. If not, I suggest you look at your peripheral firmware and make sure that the feature is not only read / write.

+9
source

On the peripheral side, you must set the characteristics properties to enable notifications. You do this with the CBCharacteristicPropertyNotify property. For example, in the following way you can create a characteristic:

 CBMutableCharacteristic *alertLevelCharacteristic = [[CBMutableCharacteristic alloc] initWithType:alertLevelCharacteristicUUID properties:CBCharacteristicPropertyRead | CBCharacteristicPropertyNotify value: nil permissions:CBAttributePermissionsReadable]; 
0
source

Source: https://habr.com/ru/post/922332/


All Articles