In Part 1 of this blog, we looked at building Hybrid Mobile Apps and the technologies one could use. In part 2, we looked at the translation of the app so users can interface with the app in the language of their choice. In this concluding part of the blog, we will look at peripheral integration in Hybrid Mobile Apps.
The app that we developed connects to a smart pillbox which is essentially a Bluetooth Low Energy (BLE) device. Ionic Native BLE plugin (https://ionicframework.com/docs/native/ble/) comes in handy.
A little background on the data organization in a BLE device:
Every BLE device advertises something called as services. Each service corresponds to a feature. Usually one of these services deals with device discovery, which holds device identifying information in one of its characteristics. Services and characteristics are UUIDs and they are specific to a class of BLE devices that your application supports. Typically, you get this information from your BLE device manufacturer. So, before you start integrating to a BLE device, you should have this information ready.
Some of the best practices for integrating a BLE device:
- Always scan for a specific service for connecting to a BLE device. Scanning for all services slows down the discovery process.
- Some BLE devices require you to connect with them before they give out device identifying information. In those cases, if you are connected to a wrong BLE device, you should disconnect and continue with the discovery process. Remember that BLE devices can only connect to one device (master) at a time, if you do not disconnect, then this BLE device will not be discoverable.
- A very important usability aspect is the information you provide to the user. You need to have the Bluetooth turned on in the device before you initiate any BLE discovery process. As a developer, you need to identify the start of Bluetooth in the device and provide options for the user to turn on Bluetooth. On mobile devices, turning on Bluetooth can only be user initiated, so you can put up messages, possibly navigate to the settings screen where the user can turn on Bluetooth.
- Always display the state of the Bluetooth discovery process to the user. The user needs to know if you are searching for devices, whether you discovered any devices or if you are connected to the target device, the battery state of the connected device etc.
- It is always a good practice to create a common service/module to deal with Bluetooth connection. Encapsulate all the methods and data in this module so that it can be imported into other apps if required.
If you have any query regarding Hybrid Mobile Apps, please write to us at firstname.lastname@example.org and we shall answer your queries at earliest.