Difference between revisions of "Quantified-Self Application"

From AGILE IoT Wiki
Jump to: navigation, search
Line 5: Line 5:
  
 
== Features ==  
 
== Features ==  
 +
* Stream data from sensors and cloud-based data sources
 +
* Define goals and monitor progress
  
 
== Implementation ==
 
== Implementation ==
Line 89: Line 91:
  
 
=== Integrating new device drivers ===
 
=== Integrating new device drivers ===
 +
New Devices can be added by implementing functionality in agile-devicefactory
 +
 +
* Clone [https://github.com/Agile-IoT/agile-core agile-core] and [https://github.com/Agile-IoT/agile-dev agile-dev]
 +
* Create a new device instance in agile-core/rg.eclipse.agail.DeviceFactory/src/main/java/org/eclipse/agail/device/instance and implement the required device functionality. An example can be found at [https://github.com/Agile-IoT/agile-core/pull/45]
 +
 +
* in the agile-stack directory create/modify docker-compose.override.yml. Modify the path to the agile-core directory accordingly 
 +
<pre>
 +
agile-devicefactory:
 +
    command: [ "bash", "/usr/src/app/scripts/start.sh", "DeviceFactory" ]
 +
    #image: agileiot/agile-core-armv7l:v0.2.12
 +
    build:
 +
      context: ../../agile-core
 +
      dockerfile: Dockerfile
 +
    depends_on:
 +
      - agile-dbus
 +
    volumes:
 +
      - agile-dbus-dir:/usr/src/app/.agile_bus
 +
      - agile-data-core-plugins:/usr/src/app/plugins
 +
    environment:
 +
      DBUS_SESSION_BUS_ADDRESS: "unix:path=/usr/src/app/.agile_bus/agile_bus_socket"
 +
    restart: always
 +
    privileged: true
 +
</pre>
 +
* Deploy to a device according to instructions in [https://github.com/Agile-IoT/agile-dev]

Revision as of 08:27, 13 March 2018

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.

Features

  • Stream data from sensors and cloud-based data sources
  • Define goals and monitor progress

Implementation

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
agile.protocolManager.discovery.start()
	.then(function() {
  		console.log('General discovery is on');
		return agile.protocolManager.devices();
	})
	.then(function(devices) {
           //do something
	}).catch(function(err){
	console.log("discovery error:"+ err);
	});
  • Check for discovered devices
agile.protocolManager.devices().then(function(devices) {
       devices.forEach(function(device){
         //do something
       })
}).catch(function(err){
       console.log("available devices err :"+ err);
})
  • Register a device
  • Check if it registered correctly and connect
var registeredDevices =  agile.deviceManager.get().then(devices => {
if (devices.length != 0 ){
   devices.forEach(function(device){
         agile.deviceManager.get([deviceId])
	.then(function(device, onRejected) {
	if (onRejected != null) {
		console.log("rejected: "+ onRejected);
	}
	  agile.device.connect([deviceId]).then(function(){
		resolve();
	   })
	}).catch ( err => {
	    console.log ("Device not defined: " + err);
	    reject(err);
	});
}).catch(err => {
	console.log("Device "+device+" not registered " + err);
	reject(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

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/rg.eclipse.agail.DeviceFactory/src/main/java/org/eclipse/agail/device/instance and implement the required device functionality. An example can be found at [3]
  • in the agile-stack directory create/modify docker-compose.override.yml. Modify the path to the agile-core directory accordingly
 agile-devicefactory:
    command: [ "bash", "/usr/src/app/scripts/start.sh", "DeviceFactory" ]
    #image: agileiot/agile-core-armv7l:v0.2.12
    build: 
       context: ../../agile-core
       dockerfile: Dockerfile
    depends_on:
      - agile-dbus
    volumes:
      - agile-dbus-dir:/usr/src/app/.agile_bus
      - agile-data-core-plugins:/usr/src/app/plugins
    environment:
      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]