Quantified-Self Application

From AGILE IoT Wiki
Revision as of 10:06, 18 March 2018 by Dpapadimatos (talk | contribs)
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 Agile sdk is used for access.


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

Sensors and Activity visualizations



The QS app carries out the following steps to access 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

Using Agile SDK

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
  • 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]