This code may help you with reading HRM, sending to server and closing the app afterwards.
function startHRMSensor() {
tizen.humanactivitymonitor.start('HRM', onchangedHRValue);
}
function onchangedHRValue(hrmInfo) {
var hr = hrmInfo.heartRate;
sendData(hr);
}
function sendData(hr) {
var API_URL = "https://foobar.foo/endpoint"
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
console.log('done');
if (xmlHttp.status == 200) {
// exit the app when data is send
tizen.application.getCurrentApplication().exit();
} else {
alert("failed to send data!");
}
}
}
xmlHttp.open("POST", API_URL);
xmlHttp.setRequestHeader("Content-Type", "application/json");
var data = {
"key" : "heart_rate",
"value": hr
};
xmlHttp.send(JSON.stringify(data));
}
window.onload = function() {
startHRMSensor();
}