Retrieving Data from GEAR S3 Heart Rate Monitor (H

2020-05-07 08:32发布

问题:

I have used the Tizen sample Heart Rate Monitor code for Samsung Gear S3 from https://developer.tizen.org/ko/community/tip-tech/accessing-heart-rate-monitor-hrm-sensor-data-native-applications?langredirect=1

I want to develop Android or Tizen for Retrieving Data from the Heart Rate Monitor which is in S3 Gear. I found the sample code from https://developer.tizen.org/ko/development/guides/web-application/sensors/human-activity-monitor?langredirect=1#retrieve

How can I integrate this. Pls share your ideas. Thanks a lot.

回答1:

With Samsung Accessory SDK, you can develop an app in Android which can communicate with Tizen app(Gear). Here is a working example

How to integrate Samsung Gear Steps in android Application?

Edit:

Here i am giving the code to measure Heart Rate and return back to Android phone when a request is sent from Android . I have just modified code from previously mentioned post and sharing here.

Here i am giving only contents from dataOnReceive function

            if (!SAAgent.channelIds[0]) {
                createHTML("Something goes wrong...NO CHANNEL ID!");
                return;
            }

            function sendHrData(heartRate){
                 // return Data to Android
                 SASocket.sendData(SAAgent.channelIds[0], 'HR: '+heartRate);
                 createHTML("Send massage:<br />" +
                             newData);

             tizen.humanactivitymonitor.stop('HRM');

            }

            var heartRateData=0;

            function onsuccessCB(hrmInfo) {

                console.log('Heart rate: ' + hrmInfo.heartRate);
                heartRateData = hrmInfo.heartRate;
                // holding 15 seconds as HRM sensor needs some time 
                setTimeout(function(){
                    sendHrData(heartRateData);
                    }, 15000);

            }

            function onerrorCB(error) {
                tizen.humanactivitymonitor.stop('HRM');
                console.log('Error occurred: ' + error.message);
            }



            function onchangedCB(hrmInfo) {
                //alert("onChanged...");
                tizen.humanactivitymonitor.getHumanActivityData('HRM', onsuccessCB, onerrorCB);

            }

            tizen.humanactivitymonitor.start('HRM', onchangedCB);

And this code continuously returning Heart Rate. Please modified according to your requirements, i am just sharing the idea to communicate between Android phone and Samsung Gear.

Send Data to Server:

You can use Ajax or XmlHttpRequest to send data to server

Ajax:

    function sendDataToServer() {
            'use strict';

            console.log( "ready!" );
              $.ajax({
                type: "Post",
                url: "http://YOUR_URL",
                success: function (data) {
                      console.log(JSON.stringify(data));
                 }
           });
        }

XmlHttpRequest:

function postDataToServer() {
var xmlHttp = new XMLHttpRequest();

xmlHttp.onreadystatechange = function() {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            alert("data posted successfully..");
        } else {
            alert("failed to send data..");
        }
    }
}

xmlHttp.open("POST", "YOUR_URL");

xmlHttp.send("_TEST_STRING_DATA");

Auto generated code from REST viewer not working in Tizen IDE(Wearable) web app

XmlHttpRequest on Tizen TV exits application

RESTful service on emulator

Note: You need to install Samsung Gear application in your Android phone.