0

I am using the Custom Heart Rate Monitor standalone app in Samsung S3 Gear. I want to display static/dynamic image from the server first in the watch along with the "start and stop " button.

After the HRM data generated, the data should send to the server. And after successful data passing the HRM App should close automatically in the Watch.

Pls share your thoughts and suggestions. Thanks a lot.

Ajitsree
  • 37
  • 2
  • 10
  • Did you write any code for getting static/dynamic image from the server or sending data to server in your app? Define your specific problem. – Yasin shihab Apr 20 '18 at 06:35
  • @ Yasin shihab I didn't write any code I just used the Tizen Sample App ( https://developer.tizen.org/ko/community/tip-tech/accessing-heart-rate-monitor-hrm-sensor-data-native-applications?langredirect=1 ) . – Ajitsree Apr 21 '18 at 06:20
  • I think you may study different resources of this site like https://developer.tizen.org/development/guides before posting. – Yasin shihab Apr 25 '18 at 04:35

1 Answers1

0

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();
}
tymbark
  • 1,279
  • 12
  • 20
  • where should I add this code, because its giving some errors – Ajitsree Apr 21 '18 at 06:18
  • add it to your main `.js` file, it may be named `app.js` or `main.js` something like it – tymbark Apr 21 '18 at 10:10
  • Cannot find javascript file in that folder – Ajitsree Apr 22 '18 at 05:47
  • Did you create native project or WEB? To use this code you need a WEB project. – tymbark Apr 22 '18 at 07:28
  • Can we make a custom design in Web Project? ie. "Start" and "Stop" button. Its a native project https://developer.tizen.org/ko/community/tip-tech/accessing-heart-rate-monitor-hrm-sensor-data-native-applications?langredirect=1 – Ajitsree Apr 22 '18 at 12:37
  • Sure you can make any design you want in both native and web projects. I would say that its even easier in web because you can use html and css for layout. – tymbark Apr 22 '18 at 14:24
  • Can I get any sample app for that – Ajitsree Apr 22 '18 at 16:08
  • You may look through https://developer.tizen.org/development/guides/web-application/user-interface/tizen-advanced-ui for UI design. – Yasin shihab Apr 24 '18 at 05:35
  • The Problem I go for Native Application is that Web Application didn't showing accurate result and it also say it cannot read "clean sensor" message coming often – Ajitsree Apr 24 '18 at 06:37
  • For native look through https://developer.tizen.org/development/tizen-studio/native-tools/writing-and-editing-code/ui-builder. I think you may study different resources of this site before posting. – Yasin shihab Apr 25 '18 at 04:31