Instantly share code, notes, and snippets.

Embed
What would you like to do?
Continua health application on NodeJS.
#!/usr/bin/env node
var dbus = require("dbus");
var xpath = require('xpath');
var dom = require('xmldom').DOMParser
var BODY_WEIGHT_SCALE = 0x100f; // data type of a body weight scale device
var MDC_MASS_BODY_ACTUAL = 57664; // metric id for body mass measurement
dbus.start(function() {
var bus = dbus.system_bus();
var manager;
try {
manager = dbus.get_interface(bus, "com.signove.health", "/com/signove/health", "com.signove.health.manager");
} catch (err) {
console.log('Cannot connect to the continua dbus interface. Is the healthd process running?');
process.exit(1);
}
dbus.requestName(bus, 'org.servicelab.healthapp');
var objectName = '/org/servicelab/healthapp/' + process.pid;
var register = new dbus.DBusRegister(dbus, bus);
var Methods = {
Connected: function(device, address) {
},
Associated: function (device, xmldata) {
device = dbus.get_interface(bus, 'com.signove.health', device, 'com.signove.health.device');
device.RequestDeviceAttributes();
},
MeasurementData: function(device, xmldata) {
var doc = new dom().parseFromString(xmldata);
var weight = parseFloat(xpath.select("//meta-data[meta='" + MDC_MASS_BODY_ACTUAL + "']/../simple/value/text()", doc));
console.log('Measured weight is: ' + weight);
},
DeviceAttributes: function(device, xmldata) {
console.log(xmldata);
},
Disassociated: function(device) {
},
Disconnected: function(device) {
},
PMStoreData: function(device, handle, xmldata) {
},
SegmentInfo: function (device, handle, xmldata) {
},
SegmentDataResponse: function(device, handle, segment, response) {
},
SegmentData: function(device, handle, segment, xmldata) {
},
SegmentCleared: function(device, handle, segment, xmldata) {
}
};
register.addMethods(objectName, 'com.signove.health.agent', Methods);
manager.ConfigurePassive(objectName, [BODY_WEIGHT_SCALE]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment