Quantified-Self Application

From AGILE IoT Wiki
Revision as of 10:49, 18 December 2018 by Dpapadimatos (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Quantified-Self Application

The Quantified-Self Application is a Node js application which uses the AGILE software stack to provide connectivity to supported Bluetooth Low Energy Devices.


The Quantified Self application uses the AGILE software stack to access data from the supported sensors. The application allows the user to monitor his activity against predefined goals. Sensor based and cloud-sourced data can be used to quantify the progress

The application also allows the monitoring of the following biosignals via supported devices

  • Blood Pressure
  • Heart Rate
  • Oxygen Saturation
  • Body Weight

Quantified Self Application User Inteface

The Quantified Self application is a multi - user system. Agile-security is used as the access framework.

User login

Landing page

Registration UI

Registration Page

Home page containing user statistics. The user sets specific goals and can see relevant statistics

Home page

The user can set personal parameters such as height and age. He can also set the current timezone



Available devices can be registered on a per user basis. Also automatic and manual connections can be configured for supported devices.

Device Registration

Available devices

Discovered Devices

Devices after registration

Registered Devices

Re-registration option

Re-registering devices for another user

Visualization of User sensor data. The user can access activity and sleep data from the activity device. Daily, weekly and monthly visualizations are available

Current Day

Activity Data for current day

Current Month

Monthly Activity Data


Biosignal Data

Device Management

We are currently using balena cloud to manage the devices

Balena cloud dashboard


The Quantified Selp Application is a Node JS application which uses Agile-IoT functions for data collection and security. Access to the Agile functionality is done via the agile-sdk

Architecture of Quantified Self Application

Functionality and mappings to AGILE services

The QS app carries out the following steps to access sensor data

  • Discovery of compatible devices
  • Registration of sensors
  • Connection Setup
  • Subscription to Sensor services
  • Setup of websockets to accept streaming data
  • Saving of Data to QS database
  • User parameterized query of data for visualization

The following modules are used

Development Environment

A Linux based development environment is recommended. Development can either be done using available Linux distributions such as Ubuntu or directly on the Raspberry PI - Virtualization software such as VirtualBox or VMware - Ubuntu16.04 or newer

  • Required (for AGILE component build using agile-dev)
    • docker
    • git
  • optional for local component compilation and debugging (Advanced!)
    • java JDK (preferably Oracle)
    • maven
    • d-feet (to check communication between AGILE modules on DBUS)
    • others


Follow the steps needed [1] to install and then setup access to the Agile stack

var agile = require('agile-sdk')({
  api: 'http://agile.local:8080',
  idm: 'http://agile.local:3000',
  token: "LQCL7C14y84Ayqedjmbm1LuIes1TsSyn5Cv"

Javascript promises [2] can then be used to asynchronously access the stack.

An example flow is as follows

  • Turn on Device Discovery
	.then(function() {
  	   console.log('General discovery is on');
	   console.log("discovery error:"+ err);
  • Check for discovered devices
agile.protocolManager.devices().then(function(devices) {
         //do something
       console.log("available devices err :"+ err);
  • Register a device (agile management user interface can be used)
  • Check if it registered correctly and connect
var registeredDevices =  agile.deviceManager.get().then(devices => {
if (devices.length != 0 ){
	.then(function(device, onRejected) {
	if (onRejected != null) {
		console.log("rejected: "+ onRejected);
	}).catch ( err => {
	    console.log ("Device not defined: " + err);
}).catch(err => {
	console.log("Device "+device+" not registered " + err);
  • Subscribe to data
agile.device.subscribe(deviceId, componentId).then(stream => {
  stream.onerror = (error) => {
     console.log('Websocket Connection Error ' + JSON.stringify(error));
  stream.onopen = () => {
  stream.onclose = () => {
  stream.onmessage = (e) => {
     if (typeof e.data === 'string') {
     console.log("Received: '" + e.data + "'");
     // do something
}).catch(err => {
  console.log("Can't subscribe " + err);

Integrating new device drivers

The QS application uses devices which have a proprietary BLE implementations so a new driver must be implemented.

Sensor values from BLE devices can have various formats depending on the underlying parameter that is being measured. The values sent to the gateways can be sent as:

  • Single Measurements: The information of the measured parameter is fully described in a single transaction. Devices that send data in this way include blood pressure monitors and glucometers
  • Multiple Measurements: Information is dependent upon a sequence of measured values in a specific timeframe ranging from seconds to hours. Devices which fall in this category include oximeters and ECGs
  • Continuous Monitoring: In this case data is sent to the gateway in real-time or stored continuously on the device until connectivity to the gateway is possible. Wearables (activity trackers and smartwatches) as well as sensors that monitor continuously various biosignals belong to this category.

New Devices can be added by implementing functionality in agile-devicefactory

  • Clone agile-core and agile-dev
  • Create a new device instance in agile-core/org.eclipse.agail.DeviceFactory/src/main/java/org/eclipse/agail/device/instance and implement the required device functionality. An example can be found at [3]

Using one of the example implementations, the methods that need to be implemented may include

  • Connect: Device specific initialization functionality
  • Subscribe/Unsubscribe: Device specific configuration of BLE GATT notifications
  • DeviceRead/DeviceWrite: Manual reading/writing of GATT characteristics
  • formatReading: Transformation of device data

Compilation of new device driver bundle

  • in the agile-stack directory create/modify docker-compose.override.yml. Modify the path to the agile-core directory accordingly
    command: [ "bash", "/usr/src/app/scripts/start.sh", "DeviceFactory" ]
    #image: agileiot/agile-core-armv7l:v0.2.12
       context: ../../agile-core
       dockerfile: Dockerfile
      - agile-dbus
      - agile-dbus-dir:/usr/src/app/.agile_bus
      - agile-data-core-plugins:/usr/src/app/plugins
      DBUS_SESSION_BUS_ADDRESS: "unix:path=/usr/src/app/.agile_bus/agile_bus_socket"
    restart: always
    privileged: true
  • Deploy to a device according to instructions in [4]