Maybe I'm not phrasing it correctly in the search engines to find what I'm looking for. But what I need is the Core Bluetooth (Swift 3) code that will allow my app the listen for a button press on a connected peripheral. And then the code that handles that event.
Asked
Active
Viewed 2,428 times
1 Answers
2
You may want to take a look to this question:
There the answer shows most of the Swift 3 code that you may need to make BLE to work. But keep in mind that you need to provide the UUIDs, etc., and you will need knowledge of what kind of data your peripheral is giving to you. Also, you need to know the characteristic's UUID that you want listen for.
-
That is good for sending data to the peripheral, but It doesn't really go over how to get a pressed button. I think I know that the characteristic UUID for the buttons is FFE1 and when the button is pressed, it returns 0+001 thru 0+003 (used the LightBlue app to help with that) Also, I'm outputting everything that's in all the event functions I have but nothing is outputted when I press a button on the device. – Chris Sep 26 '16 at 21:38
-
Please read that answer (not just the question) again: it also shows the Swift 3 code needed for setting a notification (take a look to the "txCharacteristic"), which is what you will need. Also there is what you call the "event" (callback) that will notify you when there is a change on that characteristic's value. Finally, FFE1 is not a valid BLE UUID. Take a look to the format of the UUIDs defined on that answer too. – nbloqs Sep 26 '16 at 21:41
-
Ok. I got the notification code --- peripheral.setNotifyValue(true, for: characteristic). Thank you. As for UUID format, how do I get the full UUID. characteristic.uuid outputs only 4 character codes. – Chris Sep 26 '16 at 21:49
-
There are 2 ways: the UUID should be documented on your device's datasheet. But if not, take a look to LightBlue, which is a free app that you can install on an iOS device. It will allow you to scan the services (don't forget services!) and characteristics of your device. – nbloqs Sep 26 '16 at 21:51