Since the introduction of Bluetooth LE or “BLE” or Bluetooth Smart back in 2010, it increasingly gained too much attention from both manufacturers and developers equally since it brought numerous improvements such as low energy consumption, relatively small size, and most importantly the ability to broadcast signals between multiple devices; just to name a few. Some might ask why should we even care about Bluetooth 4.0 now knowing that Bluetooth 5.0 has been already out for almost a year; The reason I am writing this now is that Bluetooth 5.0 is not adopted but most IoT/smartphones OEM just yet; Samsung GALAXY S8 might be the only device supporting the latest Bluetooth standard while this post is written.
If you are an iOS developer who is working on a application that involves broadcasting data to one or more Bluetooth 4.0 enabled devices (Peripheral) or receiving advertised data (central) and everything in between. This article is for you.
Before diving deeper into the details. let us clarify some BLE basics.
- BLE-enabled devices can play one of these roles:
– Central (client): this is mainly means that your device is receiving data advertised from broadcasting device(s) called peripherals or servers.
– Peripheral (server): this device broadcasts data to listening clients or centrals.
- Each BLE-enabled device has to have a set of information (characteristics), some of them hard coded by the manufacturer and cannot be changed these information help other devices identify and communicate with that device. I will go through the details later on.
Figure. Heart Rate here shown as peripheral broadcasting data
What we are going to achieve
After going though the overall basics, we could go one further step to the implementation of our solution. Before that, I might deliberately omitted the point that the peripheral can be made to broadcast multiple “topics”. These topics are called services. The centrals can read those services before pairing so the user can pair if a certain service is relevant before pairing. To simplify things we can think of a Bluetooth LE peripheral device as a bulletin board and central devices as viewers of the board.
Now let us get our hands dirty and jump right to xCODE.
This repository will get you through all the methods you will need from scanning available BLE-Enabled devices to reading broadcasted data.
Your app will be able to:
- discover advertising Bluetooth LE peripherals ( servers ).
- Connect to a specific device.
- list available services.
- read each service characteristics.
- read available descritors.
- list allowed permission for read/write.
The classes and HOW-TOs are available in this repos on GITHUB
Please don’t forget to leave a comment to help improve this article.