Design for A Cause 2021Trakcore #1 AI Assisted Posture Modification - Project Introduction

#1 - Project Introduction

#2 - Acquiring Data and Designing a Model

#3 - Deploying and Testing Edge Impulse ML Model on Arduino Nano 33 IoT

#4 - Enabling IMU and BLE with Edge Impulse ML on Arduino Nano 33 IoT

#5 - Using Cordova Bluetooth (BLE) Plugin to Connect Arduino Nano 33 IoT with Android Phone


The mobile app for posture modification

I've described in my previous blog post how I've created a custom Bluetooth (BLE) service for posture position detection using Arduino Nano 33 IoT, So in this blog post I'll describe how I've build an Android app to connect my phone with the board.


Why I used Apache Cordova Framework to build a mobile App?

I've build in the past several application for BlackBerry 10 (QNX) using Blackberry WebWorks Framework which had a close relationship with an open source project Apache Cordova. It was introduced 10+ years ago, so it is a quite mature framework. And it has a very active community. I was considering Flutter, but it requires significant time investment, so it was natural for me to start with something 've worked before to save some time. Apache Cordova allows to develop applications using standard Web tools - HTML, JavaScript and CSS and deploy them on modern mobile platforms, including Android and iOS. It has as well a lot of different plugins, which allow to leverage native device capabilities like Bluetooth connectivity, vibration. As any hybrid solution it is not perfect and has its weaknesses too. But I think it is a good enough tool for initial prototype.


Apache Cordova Installation and Configuration

It is quite easy to install Cordova  toolset. It requires Node.js and Android SDK. I already had them installed on my PC.

npm install -g jshint
npm install -g eslint
npm install -g cordova


I've adjusted Java memory settings



Bluetooth Low Energy (BLE) Central Plugin for Apache Cordova

There are several BLE plugins for Apache Cordova, but  BLE Central Plugin is the most popular. It has a good documentation and a lot of examples. One of this examples is BLE Heart Rate Demo. It connects to BLE Heart Rate device and subscribes to a heart rate notification service. I've decided to use as a template.


Cordova App Development

After I've cloned code from Github, Than I've added Android as my target platform in my project folder.

cordova platform add android


And I've add the BLE plugin:

cordova plugin add cordova-plugin-ble-central


Cordova JavaScriot code is located in www/js/index.js file. I've changed service and measurement from a standard values for a hear rate service to my custom posture service:

const trakcore = {
     name: "Trakcore",
     serviceUUID: "b7469627-3ad1-4b96-8684-14d6cb73014a",
     postureCharUUID: "b7469627-3ad1-4b96-8684-14d6cb73014a"


Than I've build the code:

cordova build android

And it created Android apk binary file.


I've switched my Android phone to the Developer Mode and connected it to PC using USB cable as a media device.

Than I've deployed my app to my Android phone:

cordova run android --device


My application got loaded to the phone and automatically got started.

After the app started it scans BLE devices and connects to my Posture Service on Arduino Nano 33 IoT and subscribes to this service for notifications. It transforms received data from the service and displays "POSTURE: 0" if posture is curved and "POSTURE: 1" if the posture is straight,

{gallery} Posture App

I've used Google Chrome built-in debugger during development: It saved a lot of my time and effort.

Summary and Next Steps

Now I have a basic app that can connect over BLE to MCU and read data. The next step is to make UI more friendly and add a vibration alert if my posture is curved, as well some recommendations on what to do about it.

Thank you for reading my project blog post!