├── .gitignore ├── package.json ├── README.md └── EmpaticaE4.js /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | npm-debug.log 3 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "empatica-e4-client", 3 | "version": "1.0.3", 4 | "dependencies": { 5 | "net": "1.0.2", 6 | "binstring": "0.2.1" 7 | }, 8 | "description": "EmpaticaE4 is a node.js module, which can communicate with Empatica BLE Server to fetch the sensor stream data from the EmpaticaE4 device. ", 9 | "main": "EmpaticaE4.js", 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "git+https://github.com/htil/empatica-e4-client.git" 16 | }, 17 | "keywords": [ 18 | "EmpaticaE4", 19 | "client" 20 | ], 21 | "author": "Arpan Man Sainju", 22 | "license": "ISC", 23 | "bugs": { 24 | "url": "https://github.com/htil/empatica-e4-client/issues" 25 | }, 26 | "homepage": "https://github.com/htil/empatica-e4-client#readme" 27 | } 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # empatica-e4-client 2 | 3 | empatica-e4-client is a node.js module, which can communicate with Empatica BLE Server to fetch the sensor stream data from the EmpaticaE4 device. 4 | 5 | Instruction to setup the Emaptica BLE Server is provided in [link](http://developer.empatica.com/windows-ble-server.html "Emaptica Windows BLE Server") 6 | 7 | # Installation 8 | ```sh 9 | $ cd 10 | $ npm install empatica-e4-client 11 | ``` 12 | # Subscribe Options 13 | ```code 14 | EmpaticaE4.E4_ACC //3-axis accleration 15 | EmpaticaE4.E4_BVP //Blood Volume Pulse 16 | EmpaticaE4.E4_GSR //Galvanic Skin Response 17 | EmpaticaE4.E4_TEMP //Skin Temperature 18 | EmpaticaE4.E4_IBI //Interbeat Interval 19 | EmpaticaE4.E4_BATT //Device Battery 20 | EmpaticaE4.E4_TAG //Device Tag 21 | ``` 22 | 23 | # Demo 24 | ```javascript 25 | var EmpaticaE4 = require('empatica_e4-client'); 26 | var dev1 = new EmpaticaE4(); 27 | 28 | var portNumber = 28000; 29 | var ipAddress = '127.0.0.1'; 30 | var deviceID = 'XX1234'; //Empatica E4 device ID 31 | dev1.connect(portNumber ,ipAddress, deviceID, function(data){ 32 | var sensorData = EmpaticaE4.getString(data); 33 | console.log(sensorData); 34 | }); 35 | setTimeout(function() { 36 | dev1.subscribe(EmpaticaE4.E4_BVP); 37 | }, 1000); 38 | ``` 39 | -------------------------------------------------------------------------------- /EmpaticaE4.js: -------------------------------------------------------------------------------- 1 | var EmpaticaE4 = function() { 2 | EmpaticaE4.getString = function (data) { 3 | return EmpaticaE4.conv(data, {out: "utf8"}).trim(); 4 | } 5 | }; 6 | 7 | var device_connect = "device_connect "; 8 | var device_subscribe = "device_subscribe"; 9 | var ON = "ON"; 10 | var newline = " \n"; 11 | 12 | EmpaticaE4.prototype.onConnect = function(){ 13 | console.log('Socket connected to', EmpaticaE4.ip,':',EmpaticaE4.port); 14 | var connCmd = device_connect + EmpaticaE4.deviceID + " \n"; 15 | var byteStream = EmpaticaE4.conv(connCmd, { in: 'binary' }); 16 | EmpaticaE4.client.write(byteStream,'ascii'); 17 | }; 18 | 19 | 20 | EmpaticaE4.prototype.connect = function(port, ip, deviceID, cb) { 21 | //sensor variables 22 | EmpaticaE4.E4_ACC = "acc"; //3-axis accleration 23 | EmpaticaE4.E4_BVP = "bvp"; //Blood Volume Pulse 24 | EmpaticaE4.E4_GSR = "gsr"; //Galvanic Skin Response 25 | EmpaticaE4.E4_TEMP = "tmp"; //Skin Temperature 26 | EmpaticaE4.E4_IBI = "ibi"; //Interbeat Interval 27 | EmpaticaE4.E4_BATT = "bat"; //Device Battery 28 | EmpaticaE4.E4_TAG = "tag"; //Device Tag 29 | 30 | //connection data 31 | EmpaticaE4.port = port; //port nummber 32 | EmpaticaE4.ip = ip; //EmpaticaBLEserver ip address 33 | EmpaticaE4.deviceID = deviceID; //Empatica E4 Device id..dispalyed in Empatica BLE Server after server connection with device 34 | EmpaticaE4.isConnected = false; 35 | 36 | //library imports 37 | EmpaticaE4.net = require('net'); //for sokets 38 | EmpaticaE4.conv = require('binstring'); //to convert string to byte stream 39 | EmpaticaE4.client = new EmpaticaE4.net.Socket(); //to make connection with server 40 | 41 | //make connection request to the server 42 | EmpaticaE4.client.connect(EmpaticaE4.port, EmpaticaE4.ip, this.onConnect); 43 | 44 | EmpaticaE4.client.on('data', cb); 45 | }; 46 | 47 | EmpaticaE4.prototype.subscribe = function (sensor) { 48 | var cmd = 'device_subscribe '+ sensor +' ON \n'; 49 | var cmdBinary = EmpaticaE4.conv(cmd, { in:'binary' }); 50 | EmpaticaE4.client.write(cmdBinary,'ascii'); 51 | } 52 | 53 | module.exports = EmpaticaE4; --------------------------------------------------------------------------------