element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • More
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • More
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • More
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • More
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Design For A Cause 2021
  • Challenges & Projects
  • Design Challenges
  • Design For A Cause 2021
  • More
  • Cancel
Design For A Cause 2021
Blog Trakcore #5 AI Assisted Posture Modification - Using Cordova Bluetooth (BLE) Plugin to Connect Arduino Nano 33 IoT with Android Phone
  • Blog
  • Forum
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: vlasov01
  • Date Created: 3 May 2021 2:43 AM Date Created
  • Views 133 views
  • Likes 5 likes
  • Comments 4 comments
  • android
  • ble
  • apache cordova
  • mobile apps
  • google chrome
  • arduino nano 33 iot
  • design_for_a_cause_2021
  • apk
Related
Recommended

Trakcore #5 AI Assisted Posture Modification - Using Cordova Bluetooth (BLE) Plugin to Connect Arduino Nano 33 IoT with Android Phone

vlasov01
vlasov01
3 May 2021

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

#6 - Arduino Nano 33 IoT Wearable Design

#7 - Adding Pedometer to Reduce False Positives

#8 - Refining User Experience AKA Bugs Fix

 

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

SET _JAVA_OPTIONS=-Xmx512M

 

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!

Anonymous
  • vlasov01
    vlasov01 over 1 year ago in reply to DAB

    Thank you DAB!

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
  • DAB
    DAB over 1 year ago

    Nice update.

     

    DAB

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
  • vlasov01
    vlasov01 over 1 year ago in reply to amgalbu

    Thank you for the feedback!

     

    Yes,  the following command will generate APK. I've just updated the blog with this detail.

    1. cordova build android 
    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
  • amgalbu
    amgalbu over 1 year ago

    Interesting solution!
    Just one question: in the end apache cordova will generate an Android's apk file?

     

    thanks!

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
Element14

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2022 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube