GithubHelp home page GithubHelp logo

mjohan / cordova-plugin-empatica-device Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 0.0 20 KB

Cordova plugin for Empatica device (android and iOS)

License: MIT License

Java 41.13% JavaScript 3.47% Objective-C 55.40%
cordova-plugin empatica-device android ios

cordova-plugin-empatica-device's Introduction

cordova-plugin-empatica-device

This plugin helps cordova/ionic/phonegap projects to communicate with Empatica device (especially E4).

This plugin implements Empatica mobile SDK and needs SDK library (empalink) and API-KEY provided by Empatica. These should be available for you if you have empatica devices and an Empatica Connect account. Both of them are available from Empatica developer page.

Supported function list:

The details about these functions will be explained in Methods section. All these functions will be available after deviceready event.

// ionic
$ionicPlatform.ready(function() {
  // Empatica-plugin calls
});

// cordova
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
  // Empatica-plugin calls
});

Supported Platform

  • iOS (8.0 or greater)
  • Android (4.4 or greater) as Empatica Android SDK has minSdkVersion = 19 value in it.

Note You should also change the minSdkVersion value on your project to 19 or greater. Please check whether your android platform has already supported this SDK version. Furthermore, please check also your build-tools version on your Android SDK if you have problems using this plugin.

Installation

  • From outside your project directory, clone this repo
git clone -v https://github.com/mjohan/cordova-plugin-empatica-device.git
  • Copy Empatica android framework file (empalink-2.1.aar) into src/android/ directory
  • Copy Empatica ios framework file (EmpaLink-ios-0.7-full.framework) into src/ios/ directory
  • Go to your project directory
  • Add the plugin from the repo directory in your computer
cordova plugin add <path_to_the_cloned_repo>

Methods and Constants

initialize

Initializes the plugin with provided API-Key to bind the device. This method must be called before other method calls.

Empatica.initialize('<API_KEY>', success, failure);

Parameters

  • <API_KEY>: String value of API_KEY provided by Empatica
  • success: Callback function when the initialization process is proceeded
  • failure: Callback function when the initialization process is failed

connect

Connects to the Empatica device.

Empatica.connect(success, failure);

Parameters

  • success: Callback function when the Empatica device is succesfully connected
  • failure: Callback function when the connection is failed

disconnect

Disconnects to the Empatica device.

Empatica.disconnect(success, failure);

Parameters

  • success: Callback function when the Empatica device is succesfully disconnected
  • failure: Callback function when the disconnection is failed

subscribe

Subscribes to any sensor's update value. This method needs the third param which indicates the sensor type. This param should be assigned with one of Empatica.SENSORS constants.

Empatica.subscribe(success, failure, sensor);

Warning The device is in streaming mode when the connection has been made. This subscribe method is only an interface to get the streamed values. In fact, all sensors values are synched by the device to your app.

Parameters

  • success: Callback function if the plugin successfully subscribed to the sensor value
  • failure: Callback function if the subscription process is failed
  • sensor: Sensor type provided by Empatica.SENSORS constants

unsubscribe

Stops subscribing to a certain sensor type.

Empatica.unsubscribe(success, failure, sensor);

Parameters

  • success: Callback function if the plugin successfully unsubscribed to the sensor value
  • failure: Callback function if the unsubscription process is failed
  • sensor: Sensor type provided by Empatica.SENSORS constants

Constants

These are the supported sensors by Empatica E4 device:

  • Empatica.SENSORS.BVP_SENSOR : Blood Volume Pulse
  • Empatica.SENSORS.IBI_SENSOR : Inter-Beat Interval
  • Empatica.SENSORS.GSR_SENSOR : Galvanic Skin Response
  • Empatica.SENSORS.ACC_SENSOR : Accelerometer
  • Empatica.SENSORS.TEMP_SENSOR : Temperature
  • Empatica.SENSORS.BATTERY_SENSOR : Battery level

Sample

This sample shows how we could subscribe to BVP sensor. After initialization and connect process are succeeded, the progam tries to listen for any BVP update value. The program then stop listening to it after 5 seconds and disconnects the device after 15 seconds.

if (typeof Empatica !== 'undefined') {
  Empatica.initialize('<API_KEY>', function(initializeResult) {
    console.log(JSON.stringify(initializeResult));
    
    Empatica.connect(function(connectResult) {
      console.log(JSON.stringify(connectResult));
      
      // subscribes to BVP sensor
      Empatica.subscribe(function(data) {
        console.log(JSON.stringify(data)); // {"bvp": double_value, "timestamp": double_value}
      }, function (error) {
        console.log(JSON.stringify(error));
      }, Empatica.SENSORS.BVP_SENSOR);
      
      // unsubscribes after 5000 ms
      $interval(function () {
        Empatica.unsubscribe(function(data) {
          console.log(JSON.stringify(data));
        }, function (error) {
          console.log(JSON.stringify(error));
        }, Empatica.SENSORS.BVP_SENSOR);
      }, 5000, 1);
      
      // disconnects after 15000 ms
      $interval(function () {
        Empatica.disconnect(function() {
          console.log("Success disconnect");
        }, function(error) {
          console.log(JSON.stringify(error));
        });
      }, 15000, 1);
    }, function (error) {
      console.log(JSON.stringify(error));
    });
  }, function(error) {
    console.log(JSON.stringify(error));
  });
}

Note subscribe and unsubscribe methods do not need to be put inside connect success-callback.

License

MIT

Feedback

If you find any problems with this plugin, please create an issue or create a pull request.

Credits

cordova-plugin-empatica-device's People

Contributors

mjohan avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

cordova-plugin-empatica-device's Issues

Uncaught ReferenceError: Empatica is not defined

I am getting this error, "Uncaught ReferenceError: Empatica is not defined".
I have added the plugin in my phonegap app.
using the command:
C:..phonegapProject>phonegap cordova plugin add <path\cordova-plugin-empatica-device>

next I added a line in config.xml:

And, I tried run it with the sample code (surbscribe to BVP sensor).
But, the code does not find Empatica.
Could you please help me with this?

How to make the call in ionic 2?

Hello!

First of all, congratulations for the project, you can solve many things for me :)
I'm trying to add it to my project in Ionic v2, but I can not make a call correctly, because once I add the plugin with 'cordova plugin add cordova-plugin-empatica-device', I do not know how to make the call of Empatica.success () or Empatica.initialize (), since I do not know how to add the plugin to my controller.
Always the answer is Empatica is not defined.

If you can help me I would appreciate it.

Regards!

cordova plugin add issue

I wanted to use this plugin for a phonegap project to communicate with Empatica device E4.

I got following error when adding plugin using command:
cordova plugin add

Error Message
Unable to load PlatformApi from platform. Error: Cannot find module 'C:..\platforms\browser\cordova\Api.js'
Failed to install 'cordova-plugin-empatica-device': Error: Uncaught, unspecified "error" event. (The platform "browser" does not appear to be a valid cordova platform. It is missing API.js. browser not supported.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.