EmpaLink is a library that allows to:
- Connect to and manage one or more Empatica E4 devices via Bluetooth Low Energy (BLE)
- Receive realtime raw data from the connected devices, such as Galvanic Skin Response (GSR), Blood Volume Pulse (BVP), and accelerometers
- Receive computed data derived from raw data, such as interbeat intervals (IBI)
EmpaticaAPI is the main singleton class that handles API authentication and devices discovery. EmpaticaDeviceManager is the class that handles the connection the communication with a single E4 device.
EmpaticaAPI Class
Authentication
+ authenticateWithAPIKey:completionHandler:
Device discovery
+ discoverDevicesWithDelegate:
Background communication handling
+ prepareForBackground
+ prepareForResume
EmpaticaDelegate
- didUpdateBLEStatus:
- didDiscoverDevices:
BLEStatus
Class Methods
authenticateWithAPIKey:completionHandler:
Authenticate the user with the given API key.
+ (void)authenticateWithAPIKey:(NSString *)key completionHandler:(void (^)(BOOL success, NSString *description))handler;
Discussion
It is mandatory to call this method before using the EmpaLink API. If the key is not set or it results invalid, the connection to an E4 device will not be available and an exception will be raised at discovery time. It is recommended to call the method in the app delegate. The completion handler allows you to understand if authentication succeeded (and you can start invoking the API methods) or failed (the description
argument will help you understand why).
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[EmpaticaAPI authenticateWithAPIKey:@"HERE_GOES_YOUR_API_KEY" completionHandler:^(BOOL success, NSString *description) {
// Handle success/failure
}];
return YES;
}
discoverDevicesWithDelegate:
Ask the BLE manager to scan for Empatica E4 devices.
+ (void)discoverDevicesWithDelegate:(id
Parameters
empaticaDelegate
The object implementing EmpaticaDelegate that will receive notifications about discovered devices and BLE manager status.
Discussion
During the scan, the BLE status is set to kBLEStatusScanning.
After a successful scan, the BLE status is set to kBLEStatusReady and the list of peripherals is notified to the empaticaDelegate with a call to didDiscoverDevices:. If no devices are available, didDiscoverDevices: will be called with an empty array of devices.
prepareForBackground
Ask the BLE manager to optimize the transmission for background activity.
+ (void)prepareForBackground
Discussion
It is mandatory to implement this method in the app delegate. If not implemented, an exception will be raised at discovery time.
- (void)applicationDidEnterBackground:(UIApplication *)application {
[[EmpaticaAPI sharedInstance] prepareForBackground];
}
prepareForResume
Ask the BLE manager to resume the normal transmission for foreground activity.
+ (void) prepareForResume
Discussion
It is mandatory to implement this method in the app delegate. If not implemented, an exception will be raised at discovery time.
- (void)applicationDidBecomeActive:(UIApplication *)application {
[[EmpaticaAPI sharedInstance] prepareForResume];
}
EmpaticaDelegate Protocol
didDiscoverDevices:
- (void) didDiscoverDevices:(NSArray*)devices
Parameters
devices
The list of discovered devices.
didUpdateBLEStatus:
Notify when the status property of the BLE manager changes.
- (void)didUpdateBLEStatus:(BLEStatus)status
Parameters
status
The current status of the BLE manager
BLEStatus
Defines the possible status of the BLE manager.
typedef enum {
kBLEStatusNotAvailable,
kBLEStatusReady,
kBLEStatusScanning
} BLEStatus;
Constants
kBLEStatusNotAvailable
The iOS device does not support Bluetooth LE, or the Bluetooth LE module is not active.
kBLEStatusReady
The BLE central manager is ready to scan for devices.
kBLEStatusScanning
The BLE central manager is scanning for E4 devices.
EmpaticaDeviceManager Class
Device Connection
- connectWithDeviceDelegate:
- connectWithDeviceDelegate:andConnectionOptions:
Device Disconnection
EmpaticaDeviceDelegate
- didReceiveTagAtTimestamp:fromDevice:
- didReceiveIBI:withTimestamp:fromDevice:
- didReceiveGSR:withTimestamp:fromDevice:
- didReceiveBVP:withTimestamp:fromDevice:
- didReceiveTemperature:withTimestamp:fromDevice:
- didReceiveAccelerationX:y:z:withTimestamp:fromDevice:
- didReceiveBatteryLevel:withTimestamp:fromDevice:
- didUpdateDeviceStatus:forDevice:
DeviceStatus
Instance Methods
connectWithDeviceDelegate:
Ask the device manager to estabilish a connection to the corresponding E4 device.
- (void) connectWithDeviceDelegate:(id
Parameters
deviceDelegate
The object implementing EmpaticaDeviceDelegate that will receive data from the connected device and notifications about the connection status of the device.
Discussion
During the connection attempt, the device manager status is set to kDeviceStatusConnecting.
After a successful connection, the device manager status is set to kDeviceStatusConnected.
If the connection fails, the device manager status is set to kDeviceStatusDisconnected.
When connecting to multiple devices, it is recommended to instantiate, for each device, one object implementing the EmpaticaDeviceDelegate protocol.
connectWithDeviceDelegate:andConnectionOptions:
This method is reserved for future implementation.
disconnect
Ask the device manager to disconnect to the currently connected device. It has no effect if no device is connected.
- (void) disconnect
Discussion
After a successful disconnection, the device manager status is set to kDeviceStatusDisconnected.
EmpaticaDeviceDelegate Protocol
didReceiveTagAtTimestamp:fromDevice:
Receives a Tag notification when the button on the E4 is pressed at a given timestamp.
-(void)didReceiveTagAtTimestamp:(double) timestamp fromDevice:(EmpaticaDeviceManager*) device
Parameters
ibi
The timestamp of the button press in seconds defined as time interval between the button press and the reference date, 1 January 1970, GMT.
device
The device of type EmpaticaDeviceManager that acquired the sample.
Discussion
Tags are available with latest version of E4 firmware.
didReceiveIBI:withTimestamp:fromDevice:
Receives an Inter Beat Interval (IBI) sample detected at the given timestamp.
-(void)didReceiveIBI:(float) ibi withTimestamp:(double) timestamp fromDevice:(EmpaticaDeviceManager*) device
Parameters
ibi
The value of the IBI sample. The value is the distance from the previous detected heartbeat in seconds.
timestamp
The timestamp for the IBI sample in seconds defined as time interval between the sample received and the reference date, 1 January 1970, GMT.
device
The device of type EmpaticaDeviceManager that acquired the sample.
Discussion
IBIs are calculated in real time, using the latest samples of raw data from the optical sensor. An algorithm filters out data affected by movements. After an initialization period of about 20 seconds, IBIs are sent as soon as heart beats are detected.
didReceiveGSR:withTimestamp:fromDevice:
Receives a GSR sample acquired at the given timestamp.
- (void) didReceiveGSR:(float) gsr withTimestamp:(double) timestamp fromDevice:(EmpaticaDeviceManager*) device
Parameters
gsr
The value of the GSR sample. The value is expressed in microsiemens.
timestamp
The timestamp for the GSR sample in seconds defined as time interval between the sample received and the reference date, 1 January 1970, GMT.
device
The device of type EmpaticaDeviceManager that acquired the sample.
didReceiveTemperature:withTimestamp:fromDevice:
Receives an temperature value acquired at the given timestamp.
- (void) didReceiveTemperature:(float) temp withTimestamp:(double) timestamp fromDevice:(EmpaticaDeviceManager*) device
Parameters
temp
The value of the temperature sample expressed in Celsius degree. The value is derived from the optical temperature sensor placed on the wrist.
timestamp
The timestamp for the temperature sample in seconds defined as time interval between the sample received and the reference date, 1 January 1970, GMT.
device
The device of type EmpaticaDeviceManager that acquired the sample.
didReceiveBVP:withTimestamp:fromDevice:
Receives an IBI value acquired at the given timestamp.
- (void) didReceiveBVP:(float) bvp withTimestamp:(double) timestamp fromDevice:(EmpaticaDeviceManager*) device
Parameters
bvp
The value of the BVP sample. The value is derived from the light absorbance of the arterial blood. The raw signal is filtered to remove movement artifacts.
timestamp
The timestamp for the BVP sample in seconds defined as time interval between the sample received and the reference date, 1 January 1970, GMT.
device
The device of type EmpaticaDeviceManager that acquired the sample.
didReceiveAccelerationX:y:z:withTimestamp:fromDevice:
Receives an acceleration sample acquired at the given timestamp.
- (void) didReceiveAccelerationX:(char)x y:(char)y z:(char)z withTimestamp:(double)timestamp fromDevice:(EmpaticaDeviceManager*) device
Parameters
x
The acceleration value for x axis. The x axes is defined by the vector whose starting point is set to the center of the device and whose direction points towards the USB slot.
y
The acceleration value for y axis. The y axes is defined by the vector whose starting point is set to the center of the device and whose direction points towards the shorter strap.
z
The acceleration value for z axis. The x axes is defined by the vector whose starting point is set to the center of the device and whose direction points towards the bottom of the device.
timestamp
ƒ
The timestamp for the acceleration sample in seconds defined as time interval between the sample received and the reference date, 1 January 1970, GMT.
device
The device of type EmpaticaDeviceManager that acquired the sample.
Discussion
The values of acceleration include the gravitational acceleration on each of the 3 axis. Accelerometer sensitivity is +-2g and values goes from -127 to +128 where -127 correspond to an acceleration of -2g and +128 correspond of an acceleration of to +2g.
didReceiveBatteryLevel:withTimestamp:fromDevice:
- (void)didReceiveBatteryLevel :(float)level withTimestamp:(double)timestamp fromDevice:(EmpaticaDeviceManager*) device
Notify when the batteryLevel property of the connected device changes.Parameters
level
The battery level of the device. Values: [0.0 - 1.0]
timestamp
The timestamp for the battery sample in seconds defined as time interval between the sample received and the reference date, 1 January 1970, GMT.
device
The device of type EmpaticaDeviceManager that acquired the sample.
didUpdateDeviceStatus:forDevice:
Notify when the status property of the connected device changes.
- (void)didUpdateDeviceStatus:(DeviceStatus)status forDevice:(EmpaticaDeviceManager*) device
Parameters
status
The current status of the device
device
The device of type EmpaticaDeviceManager that updated its status.
DeviceStatus
Defines the possible status of the E4 device
typedef enum {
kDeviceStatusDisconnected,
kDeviceStatusConnecting,
kDeviceStatusConnected,
kDeviceStatusDisconnecting
} DeviceStatus;
Constants
kDeviceStatusDisconnected
The E4 device is not connected.
kDeviceStatusConnecting
A connection with the E4 device is in progress
kDeviceStatusConnected
The E4 device is connected.
kDeviceStatusDisconnecting
A disconnection with the E4 device is in progress.