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

Quick way to test battery usage of a watchface?

I developed a kitchen-sink like watchface which displayed a bunch of information but it was draining the battery of the ionic to last less than a day.   I was wondering if there was a quick way to test certain APIs or to know how much each API or coding structure drains the watch?

 

My kitchen-sink watchface has the following features, 

  1. heart rate 
  2. accelerometer
  3. barometer
  4. geolocation
  5. get the user profile (age, gender, weight, height, resting heart rate)
  6. current steps / distance / calories
  7. the clock.ontick to display the time
  8. setInterval to perform some animations

 

I'm just wonder which of these components are the culprit to killing the battery on the watch.

 

 

 

Best Answer
0 Votes
12 REPLIES 12

We don't really have any metrics available at this time, but you could optimize your code to prevent things happening when the display is not active.

 

The clock tick event already does this for you, but you can also detect if the screen is awake, and add logic to your code to remain inactive when the screen is off.

 

 

import { display } from "display";
display.onchange = () => { console.log(`The display was turned ${display.on ? "on" : "off"}`) }

 

Best Answer

@JonFitbit, thanks for the code snipplet.  I made the changes you suggested but I'm still having problems with the drainage of the Ionic battery.   My seemingly simple watchface causes the battery to last approximately 12 hours only.  Could it be the heart rate sensor causing the big battery drain?  

 

 

display.addEventListener('change', function() {
  if(display.on) {
getUserActivities(); // displays the steps, goal, distance, calories, floors, active minutes getUserProfile(); // displays the resting heart rate, age, gender, height, weight getHeartRate(); // displays the heart rate from the Heart-Rate API } else { console.log("display:off");
// nothing happens after this } });

clock.granularity = 'seconds'; // seconds, minutes, hours
clock.ontick = function(evt) {
displayClock(); // displays the clock in seconds
};

If I remove the display eventlistener function and only had the ontick function, then the battery on the watch will last 4 days. 

 

Also, is it possible to share the code of one of the existing Ionic watchfaces?  I would like to see how those watches are able to display the steps, heartrate, etc without compromising the battery life.  

Best Answer

Can I see what you're doing inside those get() methods?

 

I can't share the source for existing applications at this time, but we're working to provide more examples and apps.

Best Answer
0 Votes

@JonFitbit, here is my code inside those get functions.  Thanks for taking a look. 

 

import { today, goals } from "user-activity";
import userProfile from "user-profile";
import { HeartRateSensor } from "heart-rate";

function getUserProfile(){ var svgAge = document.getElementById("age"); svgAge.innerText = "Age:" + userProfile.user.age; var svgGender = document.getElementById("gender"); svgGender.innerText = "Sex:" + userProfile.user.gender; var svgHeight = document.getElementById("height"); svgHeight.innerText = "Height:" + userProfile.user.height; var svgWeight = document.getElementById("weight"); svgWeight.innerText = "Weight:" + userProfile.user.weight; var svgRestingHR = document.getElementById("restinghr"); svgRestingHR.innerText = "RestingHR:" + userProfile.user.restingHeartRate; } function getUserActivities(){ // show the user's activity for the day var fieldMap = { distance: { name: "distance", unit: "m" }, calories: { name: "calories", unit: "Cal" }, steps: { name: "steps", unit: "" }, elevationGain: { name: "elevation", unit: "floors" }, activeMinutes: { name: "active minutes", unit: "" } }; ["local", "adjusted"].forEach(function (scope) { var activity = today[scope]; for (var field in fieldMap) { if (activity[field] !== undefined) { console.log(" " + fieldMap[field].name + ": " + activity[field] + " " + fieldMap[field].unit); } } }); var svgSteps = document.getElementById("steps"); svgSteps.innerText = "Steps:" + today.adjusted.steps; var svgCalories = document.getElementById("calories"); svgCalories.innerText = "Calories:" + today.adjusted.calories; var svgDistance = document.getElementById("distance"); svgDistance.innerText = "Distance:" + today.adjusted.distance; var svgGoal = document.getElementById("goal"); svgGoal.innerText = "Goal:" + goals.steps; }
function getHeartRate(){
var hrm = new HeartRateSensor();
hrm.onreading = function() {
console.log("getHeartRate", "Current heart rate: " + hrm.heartRate);
var svgHeartRate = document.getElementById("heartrate");
svgHeartRate.innerText = "HeartRate:" + hrm.heartRate;
hrm.stop();
}
hrm.start();
}
Best Answer
0 Votes

 

I think the culprit might be something else.  I now have a very basic clock face with just the ontick function (basically the LCD clock example), 

 

clock.granularity = 'seconds'; // seconds, minutes, hours
clock.ontick = function(evt) {
 clocker(); // displays the time
};

and even with this simplified version, the battery is still draining fast.  In just one hour, it has used up 10% of the battery.  This is obviously unacceptable.   

 

A little background in how I'm developing. 

1.) I log into my fitbit app with my "dev" account.  

2.) Then I load up studio.fitbit.com and install/upload the watchface to my ionic.  

3.) I logout of my fitbit app and login with my "personal" account. (do the whole ionic detection process again)

4.) My custom watchface still remains on the ionic.  

 

Is this happening to anyone else?

 

Best Answer
0 Votes

have (or do you) you set a HRM sampling frequency?  i think the online documentation defaults to half a second.  if you're not already, maybe try something less frequent eg. every 10 secs.

 

i've only just started playing with hrm - haven't noticed anything unusual so far.

Best Answer
0 Votes

I used the watch face code from the Studio, changed the font and added Date.

After a night of sleep, the battery went from 100% to 30%.

 

Obviously something is missing. I am not an experienced developer, just playing for fun. 

Best Answer
0 Votes

🙂  i wouldn't call myself experienced either - just learning javascript for the first time.   i think i need to give my watchface another night to see how it goes.  but, i've got through the day so far and still at about 35%. don't think it'll be 4 days - but i've been doing a lot of testing/loading/re-loading too.

 

try a lower sampling frequency eg 20 secs..

have a look at thr HR Meter example app code here https://github.com/Fitbit/sdk-hr-meter

 

specifically, this bit..

// And update the display every .5s

setInterval(updateDisplay, 500);

Best Answer
0 Votes

Are you using the geolocation api on the watch side ?

I have a battery issue with my watchface and my investigations make me feel this is the problem

Best Answer

@agsurf5 wrote:

I used the watch face code from the Studio, changed the font and added Date.

After a night of sleep, the battery went from 100% to 30%.

 

Obviously something is missing. I am not an experienced developer, just playing for fun. 


Did you disable the developer bridge when you'd finished with it?

Best Answer
0 Votes

I think I figured out why there is a battery draining.  

 

In the scenario I have a watchface with a companion ( with messaging.peerSocket code ), If I do not enable the Developer Bridge in my mobile phone when I run/install the watchface to my ionic, then there is a major battery drainage.   

 

However, with the same code and I enable the Developer Bridge then there isn't a battery problem.  I'll need to do some more tests to verify this.  But this is what I suspect is the root cause of the battery drainage. 

 

 

 

Best Answer

FYI, in the Fitbit Discord Chatroom someone also mentioned the import of the geolocation will also drain the batteries. 

 

Adding this line of code will drain the batteries fast, 

import { geolocation } from "geolocation";
Best Answer