언어 설정

Menu
Sites
Language
S-Health Pedometer Count Value on Gear 2 Watchface

Hi all,

I want to put S-Health's actual pedometer count value to my watchface but no success. (on Gear 2) (Tizen SDK 2.3.1 installed).

is there any simple code for this? (like pedometer.count)

Could anyone help me?

 

Thanks 

Hakan

Responses

12 댓글
AVSukhov

Hello,

You may use HumanActivityMonitor API to get pedometr data:

https://developer.tizen.org/dev-guide/2.4/org.tizen.web.apireference/html/device_api/mobile/tizen/humanactivitymonitor.html

 

Hakan Albayrak

Hi AVSukhov,

Thank you for quick reply. I've tried to use HumanActivityMonitor API but did not succeed to get any data.

I think there might be another way to get S Health step count value (May be reading shealth db or data files).

By the way i'm using SDK 2.3.1 but when i build and run the code it gives error 61 (I did the certification procedures).

For this reason i've changed to config.xml Required version to 2.2

I wonder if I can not read data is that it?

Could you please share simple code using "create new web project" wizard, "Sample->Watch-Digital Watch" to put S-Health actual step count value that example? I would be very glad if you can share it.

Thank you,

Hakan

 

daniel kim

Hi,

I thinkt that you're looking for a way how to deal with health data as following link.

   http://developer.samsung.com/technical-doc/view.do?v=T000000197&pi=1&ps=10&pb=Y&ct=CT310000&sc=

    http://developer.samsung.com/sample-app/list.do?pi=1&ps=10&pb=Y&ct=CT310000&sc=

 But as AVSukhov's reply, you can directly get pedometer data from Gear device.

I could get stepCount on Gear S2.


 function onPedometerUpdate(pedometerData) {
     var d = pedometerData.stepCountDifferences[0];
     console.log("length:" + pedometerData.stepCountDifferences.length);
     console.log("stepCountDifference:"+ d.stepCountDifference);
     console.log("timestamp:"+ d.timestamp);

    }

  tizen.humanactivitymonitor.setAccumulativePedometerListener(onPedometerUpdate);

  tizen.humanactivitymonitor.start('PEDOMETER', onPedometerUpdate);

  tizen.humanactivitymonitor.getHumanActivityData('PEDOMETER', onPedometerUpdate, null);

 

Regards

Hakan Albayrak

Hi Daniel Kim,

Thank you for the answer but, this code is not work. I'm try to use this code on Gear 2. (not Gear S2).

If I've changed the required version to above 2.2 on config.xml, build gives error 61.

Changed back to 2.2, in watch log file shown this error: "TypeError: 'undefined' is not an object (evaluating 'tizen.humanactivitymonitor.setAccumulativePedometerListener')"

I  guess this method not supported on my Gear 2.

 

 

Marco Buettner

I think on Tizen 2.2 u must use webapis.motion instead of tizen.humanactivitymonitor :)

function onsuccessCB(pedometerInfo) {
console.log("Step status : " + pedometerInfo.stepStatus);
console.log("Cumulative total step count : " + pedometerInfo.cumulativeTotalStepCount);
}

function onerrorCB(error) {console.log("Error occurs");} 

webapis.motion.getMotionInfo("PEDOMETER", onsuccessCB, onerrorCB);
AVSukhov

Hello,

Agree with Marco comment. More info about motion API:

http://developer.samsung.com/technical-doc/view.do?v=T000000186

http://developer.samsung.com/onlinedocs/web_device/webapis/motion.html

Hakan Albayrak

Hi Marco Buettner & AVSukhov,

Thank you for quick replies. But trying to get data with these codes, no success.

Here is my main.js 

var battery = navigator.battery || navigator.webkitBattery || navigator.mozBattery;
var date;
var saat,dk,sn,gun,ay,yil;
var ikinokta;
var renkler = ["cyan","#CEFF03","red","yellow"];
var renk = 0;
var db_yolu = "/opt/usr/apps/com.samsung.shealth/data/";
var db_adi = ".shealth.db";
var getir;

function renkdegis(){
    renk = renk + 1;
	renk = renk % 4;
    document.getElementById('zaman_sa').style.color = renkler[renk];
    document.getElementById('zaman_ikinokta').style.color = renkler[renk];
    document.getElementById('zaman_dk').style.color = renkler[renk];
    document.getElementById('zaman_sn').style.color = renkler[renk];
	}
function getTime() {
    date = tizen.time.getCurrentDateTime();

    if(Math.floor(battery.level * 100)>90){document.getElementById('pil_yuzdesi').style.color='lightgreen';}
    else {
    	if(Math.floor(battery.level * 100)>20){document.getElementById('pil_yuzdesi').style.color='lightyellow';}
    	else{
    		document.getElementById('pil_yuzdesi').style.color='red';
    	}
    }
    document.getElementById('pil_yuzdesi').innerHTML = '%' + Math.floor(battery.level * 100);
    gun = date.getDate();
    ay = date.getMonth()+1;
    yil = date.getFullYear();
    saat = date.getHours();
    dk = date.getMinutes();
    sn = date.getSeconds();
    
    if (saat < 10) {saat = "0" + saat;}
    if (dk < 10) {dk = "0" + dk;}
    if (sn < 10) {sn = "0" + sn;}
    
    if (gun < 10) {gun = "0" + gun;}
    if (ay < 10) {ay = "0" + ay;}
    
    if(ikinokta == ":"){ikinokta=" "}else{ikinokta=":"}
    
    document.getElementById('tarih').innerHTML = gun+"."+ay+"."+yil;
    document.getElementById('zaman_sa').innerHTML = saat;
    document.getElementById('zaman_ikinokta').innerHTML = ikinokta;
    document.getElementById('zaman_dk').innerHTML = dk;
    document.getElementById('zaman_sn').innerHTML = sn;
    
	}

function initDigitalWatch() {
    setInterval(getTime, 500);
	}

function onsuccessCB(pedometerInfo) {
	console.log("Pedometer Step status : " + pedometerInfo.stepStatus); 
	console.log("Pedometer Cumulative total step count : " + pedometerInfo.cumulativeTotalStepCount);
	//Pedometer step count value to div but no success
	document.getElementById('adim').innerHTML = pedometerInfo.cumulativeTotalStepCount;
	} 
function onerrorCB(error) {
	console.log("Pedometer Error occurs");
	}  

window.onload = function() {
    document.addEventListener('tizenhwkey', function(e) {
        if (e.keyName === "back") {
            try {
                tizen.application.getCurrentApplication().exit();
            } catch (ignore) {}
        }
    });    
    initDigitalWatch(); 
    console.log("Pedometer motion info...");
    webapis.motion.getMotionInfo("PEDOMETER", onsuccessCB, onerrorCB);    
};


And config.xml

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:tizen="http://tizen.org/ns/widgets" id="http://yourdomain/hakoni1" version="2.1.0" viewmodes="maximized">
    <tizen:application id="07rzDd6uFV.hakoni1" package="07rzDd6uFV" required_version="2.2"/>
    <tizen:category name="com.samsung.wmanager.WATCH_CLOCK"/>
    <content src="index.html"/>
    <feature name="http://tizen.org/feature/screen.size.normal.320.320"/>
    <feature name="http://tizen.org/feature/sensor.pedometer"/>
    <feature name="http://tizen.org/feature/humanactivitymonitor"/>
    <icon src="icon2.png" height="117" width="117"/>
    <name>hakoni LCD 2.1</name>
    <tizen:privilege name="http://tizen.org/privilege/healthinfo"/>
    <tizen:profile name="wearable"/>
    <tizen:setting background-support="disable" encryption="disable" hwkey-event="enable"/>
</widget>

 

Marco Buettner

Did u get an error? maybe you have to log the error in the onerrorCB with (error.name or error.message)

Hakan Albayrak

Hi Marco,

I'm looking for error on device log messages. But no error. Strange.

I've uploaded latest build wgt file to wetransfer. Could you please look at this.

http://we.tl/JV7LiLzNbQ

Thank you.

AVSukhov

Hello,

I tested your code:

after add privilege:

<tizen:privilege name="http://developer.samsung.com/privilege/healthinfo"/>

observe following errror:

js/main.js (66) :{"code":0,"name":"ServiceNotAvailableError","type":"ServiceNotAvailableError","message":"service not available"}

this means that sensor is turn off, and to turn it on need to call start() method:

webapis.motion.start("PEDOMETER", onchangedCB);

after start, on changeCB you can get data using getMotioINfo.

I hope this will helps you.

Marco Buettner

Yeah, I forget the call the start() method in my code above =)

Hakan Albayrak

Hi AVSukhov,

I've tested that code before but it's not worked.

But, I noticed something. I was using the SDK, version 2.3.1.

But all this codes for SDK 2.2

In samsung web site I found Tizen IDE SDK for wearable 2.2. Downloaded and installed.

And as you said, I've added the privilege "http://developer.samsung.com/privilege/healthinfo" instead of "http://tizen.org/privilege/healthinfo".

Also webapis.motion.start command.

And its work now :)

But still, its not showing same value of shealth daily step value.

Now I'm trying to get correct value.

Thank you for all.

Best regards