Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Heartrate sensor not working on Ionic but OK in simulator.

ANSWERED

Hi,

 

I'm working on adding the heart rate sensor on my own clock face.

 

It seems working in the simulator (showing 65 BPM), but when deploying the app on my girlfriend's Ionic, the label is empty.

 

Here is basically what I'm doing :

 

  • heartrate.js : 
import document from "document";
import { HeartRateSensor } from "heart-rate";
import * as util from "../common/utils";

// Get a handle on the <text> element.
const heartRateLabel = document.getElementById("heartRateLabel");

// Create a new instance of the HeartRateSensor object.
const hrm = new HeartRateSensor();

hrm.onreading = function() {
  // Update the <text> element with the current heart rate sensor value.
  heartRateLabel.text = util.monoDigits(hrm.heartRate || 0);

  // Stop monitoring the sensor.
  hrm.stop();
}

export function update() {
  // Begin monitoring the sensor.
  hrm.start();
}

 

  • index.js :
import clock from "clock";
import * as activity from "activity";
import * as battery from "battery";
import * as date from "date";
import * as heartRate from "heartrate";
import * as time from "time";
import * as util from "../common/utils";

// Update the clock every second.
clock.granularity = "seconds";

// Each second.
clock.ontick = (evt) => {
  heartRate.update();
  battery.update();

  const todayDate = evt.date;
  date.update(todayDate);
  time.update(todayDate);

  activity.update();
}

 

Am I wrong somewhere?

 

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

I've found the problem.


When we update an app/clock face, the Fitbit App doesn't re-ask for permission, so the app doesn't have access to HR.

 

I've installed another clock and then mine back and it works properly now.

View best answer in original post

Best Answer
0 Votes
4 REPLIES 4

Did you enable the Heart Rate Sensor permission in the package.json?

Best Answer

Yes it is. 😕

Best Answer
0 Votes

My very simple clockface (still very experimental) has a miraculously working HR measurement in this way

 

// Reading heartrate
const hrm = new HeartRateSensor();

hrm.onreading = function() {
  heartrateHandle.text = `${hrm.heartRate}`;
}
hrm.start();

it shall be noted that for some reason it is not under the clock.ontick block 

Best Answer

I've found the problem.


When we update an app/clock face, the Fitbit App doesn't re-ask for permission, so the app doesn't have access to HR.

 

I've installed another clock and then mine back and it works properly now.

Best Answer
0 Votes