BLE is a complicated and volatile protocol implementation on mobile. This repository is meant to demonstrate my proficiency in understanding how the ecosystem of BLE on Android + iOS works. We will use This plugin for Capacitor for the Satellite Manager logic to speed up the process. While it doesn't implement modern Swift/Kotlin best practices, neither does it provide peripheral management nor reconnection management, it's sufficient for this demonstration. The devices that I posess do not have open ended APIs or GATT services for demonstration purposes, so I used LightBlue for virtual BLE simulation.
Note that for practical purposes related to the business associated with this project, I used Angular and Typescript for the front end. However, my experience is limited to around a year in these areas-which was some time ago-so be mindful that there may be some misses on perfect execution.
The BLESatelliteManagerService
controls the state management of the BLE service layer. It'll keep track of state and execute actions managing current detected satellites, connection status, and notifications on when state changes (handled via Android Toasts for simplicity). This is also the service where Unit Testing was covered (with some help from Github CoPilot due to a lack of TS knowledge).
The service has five main functionalities:
- Scanning for Satellites using a simulated device
GATT service-uuid
(180D) onLightBlue
. - Connecting to a Satellite.
- Disconnecting from a Satellite.
- Perform a
Read
operation to a simulated Characteristic. - Similarly perform a
Write
operation to a simulated Characteristic.
The HomePage
uses a UI similar to Go-Pro's demonstration of using this library. We use the Observable
patterns (or Pub-sub pattern
) to communicate state changes from the BLESatelliteManagerService
to the HomePage
.
For the screenshots below note that the Heart Rate we read is a Little Endian
2-byte representation of current heart rate. 0x5200 is 82 in this case, which is Toast-ed to the user when they send the read command.
screen-20230914-120350.mp4
Requirements for Running this Repo
Node >=16 & NPM
Recommend using nvm to install & manage node versions - https://github.com/nvm-sh/nvm
- nvm install 16
- nvm use 16
Ionic CLI 7.1.1
- npm i -g @ionic/[email protected] Run project for development
Install dependencies
- npm install
Run project in browser @ http://localhost:4200/
- npm run start
Run On Android
Add Android Platform
- npm install @capacitor/android
- npx cap add android
Ensure that you have a www/ assets folder in the root; please add one and drop in a copy of the index.html from the src/ folder Open Android Studio
Confirm you are using the embedded JDK of 11 or above Run the build and run directly on device Make Changes to the Src Files
- npm run build
- npx cap copy
Re-run on the device from Android Studio Documentation for reference: https://capacitorjs.com/docs/android