Retrieving Data from GEAR S3 Heart Rate Monitor (HRM) to Mobile or Server

我只是一个虾纸丫 提交于 2019-12-02 10:48:14

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!