Languages

Menu
Sites
Language
Heart Rate and RR-interval value (Please please help!!)

Hello,

I am trying to retrieve the heart rate value and the RR-interval using the motion API (Samsung Extension).
The device I'm using is Samsung Gear S2.
I have several issues I'm struggling with...

1.
I was able to find some relevant topics in this forum and was able to use the code in the posts to get the heart rate value.
This is that code.

 

window.webapis.motion.start("HRM", onchangedCB);

function onchangedCB(hrmInfo)
{
  time = new Date().getTime() - initial;
  console.log("[" + time + ", "+ hrmInfo.heartRate + ", " + hrmInfo.rRInterval + "]" );
}

 

The code above gives me the right heart rate value with the right time in milliseconds,
but the rr-interval value always seem to be zero.
Does anyone know why the rr-inverval isn't giving me the right value?


2.
I also want to write the output to a text file,
So I looked up the filesystem API and tried to start from the top by writing hello world in the sample code.

 

 
var documentsDir;

tizen.filesystem.resolve("documents", function(result) {documentsDir = result; } );
var testFile = documentsDir.createFile("test.txt");
if (testFile != null) 
    {
       testFile.openStream("rw", onOpenSuccess, null, "UTF-8");
    }
function onOpenSuccess(fs)
{
       /* Write HelloWorld to the file */
       fs.write("HelloWorld");

       /* Move pointer to the beginning */
       fs.position = 0;

       /* Read the file content from the beginning */
       fs.read(testFile.fileSize);

       /* Close the file */
       fs.close();
}

 

This code seems to run fine without any errors, but I can't locate where the file is!
Is the file saved in the watch's internal memory?


3.
And one more question!
The sampling rate of retrieving the heart rate seems to be approximately 100ms.
Can I set the sampling rate into a shorter interval?

 

I'd really appreciate it if anyone can give help because I am using Tizen and samsung sdk for the first time
and it is giving me a lot of trouble...
Thank you in advance!

Edited by: Danielle Jeong on 25 Oct, 2016

Responses

8 Replies
Marco Buettner

1. IDK, I never used some sensors of any device, so I cant tell anything about it

2. Before your interact with any file (read, create, delete), you have to RESOLVE the location. 

https://developer.tizen.org/development/api-references/web-application?redirect=https://developer.tizen.org/dev-guide/2.4.0/org.tizen.web.apireference/html/device_api/mobile/tizen/filesystem.html

so before your create a file use

var location = 'documents'; // internal memory!
var dir;

function success(openDir) {
    dir = openDir;
    
    var file;
    
    try { //if file not exists
       file = dir.createFile('mynewfile.txt');
    } catch(exc) { // if file already exists
        file = dir.resolve('mynewfile.txt');
    }
}

tizen.filesystem.resovle(location, success, error);

Also dont forget to setup filesystem.read and filesystem.write to allow your application to use the filesystem-apis

If you read careful the documentation from the begin, you will understand the filesystem a little bit better ;) 

If you use write operation of documents, it will saved to the internal memory of your smartwatch... File Explorer -> Documents

3. Imo you cant change the interval. But like I wrote above: I never use the sensor stuff in my applications.

Danielle Jeong

Thank you so much for your answer!!
It was great help!
I'll try reading the filesystem documentation carefully! :)

Danielle Jeong

Hello again :)

I have another question to ask!
I tried reading through the filesystem API but still am having trouble locating the documents directory.
It says it is the virtual root for the document related files but I have no idea what the document virtual root directory is in galaxy s2 device.

The directories in the device are

bin
boot
dev
etc
home
initrd
lib
lost+found
media
mnt
opt
proc
root
run
sbin
sdcard
smack
srv
sys
tmp
usr
var

I also tried to search the created file through the sdb shell but it gives me permission denied error.
Do you know how I can locate and access the created file in the internal memory?

Marco Buettner

The 'documents' is the virtual root for documents file in opt/media/documents ? I'm not sure about the full path... But I'm sure it was are virtual root for something in opt, look at these.

Danielle Jeong

Wow I found it! It was in opt/usr/media/Documents directory!
(I never thought i'd be in the opt directory!)
Thank you soooo much for your help.

Armaan-Ul- Islam

Hello,

I would suggest you to use Tizen HumanActivityMonitor API to read heartRate and rRInterval data. I've recieved correct 'rRinterval' dtata using Tizen HumanActivityMonitor API . I am sharing a sample code snippet using HumanActivityMonitor API & Filesystem API. (Ans 1 & 2)


function writeToFile(hrmInfo){
    var HRMdata,HRMInterval;	
   
    HRMdata=hrmInfo.heartRate;
    HRMInterval=hrmInfo.rRInterval;

    console.log("Data from Sensor:",HRMdata); 
    console.log("Interval from Sensor:",HRMInterval);

    var documentsDir,read;
		
    tizen.filesystem.resolve("documents", function(result) {
	documentsDir = result;
        var testFile = documentsDir.createFile("testData.txt");
        if (testFile != null) {
            testFile.openStream("rw", onOpenSuccess, null, "UTF-8");
	 }
	

        function onOpenSuccess(fs){
		                        	   
	    fs.write(HRMdata); // write HRM sensor data to file
        
            fs.position = 0;
            read=fs.read(testFile.fileSize);  //read from file
            console.log("Data from File:",read);  //output to console
		                        	
            fs.close();
       }
    });
}

tizen.humanactivitymonitor.start("HRM", writeToFile);

Ans 3. The HumanActivity API Documentation states 'readonly attribute long rRInterval' as output data from HRM sensor. It doesn't takes any custom interval as input. Same for HRMRawSensorData , no input interval parameter.

Links:

HumanActivityMonitor Guide

HumanActivityMonitor API Reference

FileSystem Guide

FileSystem API

HRMRawSensor

 

 

Danielle Jeong

Thank you so much for your kind reply!
It was great help!

I tried to run the code using your code snipped (HumanActivityMonitor API)
and it gives me the right heart rate value,
but it still gives me zero for the rRInterval value.

Maybe the problem is with the watch.
I will try to find another watch and run the code!

Thank you!!

Armaan-Ul- Islam

Check out this response on bug report:

https://bugs.tizen.org/browse/TW-47?jql=

Response:

" Currently, we serve rr-interval as always zero. Due to a low power consumption policy of Tizen wearable products, HR sensor chip cannot run with 10ms sampling rate. Technically, rr-interval can be confidential one with 10ms sampling rate data of HR. Now, we are investigating how supports rr-interval with over 10ms sampling rate.
I will update if there are any positive results. Plus, I want to make sure one thing. rr-interval has been opened only in Human Activity Monitor web API not in Sensor native CAPI.
As a result, there is no work-around until now and you need to explain it to the 3rd party clients. "