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
});
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.
git clone -v https://github.com/mjohan/cordova-plugin-empatica-device.git
src/android/
directorysrc/ios/
directorycordova plugin add <path_to_the_cloned_repo>
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);
<API_KEY>
: String value of API_KEY provided by Empaticasuccess
: Callback function when the initialization process is proceededfailure
: Callback function when the initialization process is failedConnects to the Empatica device.
Empatica.connect(success, failure);
success
: Callback function when the Empatica device is succesfully connectedfailure
: Callback function when the connection is failedDisconnects to the Empatica device.
Empatica.disconnect(success, failure);
success
: Callback function when the Empatica device is succesfully disconnectedfailure
: Callback function when the disconnection is failedSubscribes 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.
success
: Callback function if the plugin successfully subscribed to the sensor valuefailure
: Callback function if the subscription process is failedsensor
: Sensor type provided by Empatica.SENSORS constantsStops subscribing to a certain sensor type.
Empatica.unsubscribe(success, failure, sensor);
success
: Callback function if the plugin successfully unsubscribed to the sensor valuefailure
: Callback function if the unsubscription process is failedsensor
: Sensor type provided by Empatica.SENSORS constantsThese are the supported sensors by Empatica E4 device:
Empatica.SENSORS.BVP_SENSOR
: Blood Volume PulseEmpatica.SENSORS.IBI_SENSOR
: Inter-Beat IntervalEmpatica.SENSORS.GSR_SENSOR
: Galvanic Skin ResponseEmpatica.SENSORS.ACC_SENSOR
: AccelerometerEmpatica.SENSORS.TEMP_SENSOR
: TemperatureEmpatica.SENSORS.BATTERY_SENSOR
: Battery levelThis 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
andunsubscribe
methods do not need to be put inside connectsuccess-callback
.
MIT
If you find any problems with this plugin, please create an issue or create a pull request.
NSBluetoothPeripheralUsageDescription
and UIBackgroundModes
for iOS platformsetKeepCallback
method