0

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.

Ajitsree
  • 37
  • 2
  • 10

1 Answers1

0

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.

enter image description here

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.

Iqbal hossain
  • 1,778
  • 3
  • 17
  • 24
  • I have test this https://stackoverflow.com/questions/40233692/how-to-integrate-samsung-gear-steps-in-android-application/40529913#40529913 and its working fine in Wear and Mobile. But I want to know how I can integrate this Code with the Heart Rate Monitor. So that I can get Heart Rate Data in my Android mobile. Pls share if you have any sample code. Thanks a lot – Ajitsree Apr 18 '18 at 07:52
  • I check the above code but its giving error. Can you share your sample code in full which you developed for android mobile and Samsung Gear Watch. Thanks in advance – Ajitsree Apr 18 '18 at 11:30
  • Full code https://drive.google.com/file/d/0B6KEP_6UcxrATllCWTlmeUh1M28/view?usp=sharing – Iqbal hossain Apr 18 '18 at 11:39
  • I have just modified dataOnReceive of Tizen part – Iqbal hossain Apr 18 '18 at 11:39
  • Thanks a lot. It worked. How can I pass the data to a server directly from the watch. – Ajitsree Apr 18 '18 at 12:04
  • If it works, then select it as accepted :-) You can send data to server using Http request simply – Iqbal hossain Apr 18 '18 at 12:59
  • I found one http Request code. Can I use the below code var http = new XMLHttpRequest(); var url = "get_data.php"; var params = "lorem=ipsum&name=binny"; http.open("POST", url, true); //Send the proper header information along with the request http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.onreadystatechange = function() {//Call a function when the state changes. if(http.readyState == 4 && http.status == 200) { alert(http.responseText); } } http.send(params); – Ajitsree Apr 18 '18 at 16:21
  • Yes! you can .. i have updated the answer with Ajax ..please check ...also gave XmlHtpRequest help link – Iqbal hossain Apr 19 '18 at 03:57
  • I used the above code in last (after the function(tau ) of the app.js file to send data to server and using server as localhost.But cannot send the data. – Ajitsree Apr 19 '18 at 06:36
  • There is no errors but the data is not sending to the server – Ajitsree Apr 19 '18 at 07:15
  • XmlHttpRequest added ...please check – Iqbal hossain Apr 19 '18 at 08:30
  • I cannot connect the App from Mobile to Wear after inserting the XmlHttpRequest: code. – Ajitsree Apr 19 '18 at 09:39
  • please add internet privilege and allow domain policy according to links given above – Iqbal hossain Apr 19 '18 at 12:36