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

How to monitor steps in background (watch app) when display is off?

ANSWERED

I want to do some background processing of the step data (changes) when the display is off.  I use setInterval() to pole for information and then do some processing - it appears that the heart beat hrm.onreading still functions but step count is stationary (today.local.steps).  Is there an event for steps that I can get at while the display is off?  I assume that local.steps is just a static record that gets updates when display is on, maybe there is a steps.onreading?   I am also curious (without setting up tests) what other sensor data is refreshed in this state, if any. 

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

A workaround I've found is to trick the display into thinking the user has turned it on.

 

Using the display API 

import { display } from "display";

make the following calls inside your setInterval(), before polling today.local.steps

display.poke();
display.on = false;

Simply setting display.on to true and then back to false doesn't seem to "flush" the waiting step count into today.local.steps

View best answer in original post

Best Answer
14 REPLIES 14

The tracker counts steps in the background (regardless of whether is display is on or not). When you change the display, read the updated today.local.steps and display that. 

 

Also maybe use today.adjusted.steps vs today.local as the former will get a step count from everything you own.

Best Answer
0 Votes

@FlyBoyJIt wrote:

The tracker counts steps in the background (regardless of whether is display is on or not). When you change the display, read the updated today.local.steps and display that. 

 

Also maybe use today.adjusted.steps vs today.local as the former will get a step count from everything you own.


Yeah, I know that the tracker itself works well in the background,  but, with the display OFF, the steps (today.local.stepsare NOT undated during that period although the tracker is working & recording.  It sort of plays catch-up when the display shows or turns ON updating all correctly.

 

To determine this, I put in a simple console output of the steps reading, and step updates stop when the display goes off.  I had it initially in a clock loop that gets serviced once a second.   I also put in an interval timer to write to the console the step data too (just in case there is an anomaly) and the step data does not update until the display comes back on.   The 'timer' works fine showing it's time marks and static steps reading. 

 

I am doing some processing of step data & time lapse in both the foreground and the 'background', the background being defined as display OFF.  It appears FitBit chose to stop some processes when the watch does not have focus or is showing, to save battery.   Luckily, the setInterval() works.

 

I want to process some of the sensor data 24/7 as they say, not just when the watch 'wakes up' for view.   I do wonder if a 'side loaded watch' gets the same treatment as one installed from the FB 'store'.

 

 

Best Answer
0 Votes

The steps is updated regardless of whether the display is on or off:

 

steps_updating.PNG

 

This is from a console log on a setInterval

 

 sensorLogTimer=setInterval(() => this.logCurrentReadings(),2000);

logCurrentReadings() {
console.log("Distance:"+today.local.distance+" Steps:"+today.local.distance+" Display:"+display.on);
}
Best Answer
0 Votes

FIRST, Thanks for looking into this!   Appreciated, as it has driven me up a wall , and I had repeated my tests in different ways, with the same results, over a few days. 

 

Note: In your test, you do not monitor steps, but repeat the distance reading. 

Regardless, it appears to update with display off.  (I did not test the distance field)

 

console.log("Distance:"+today.local.distance+" Steps:"+today.local.distance+" Display:"+display.on);

 In your test, was the project configuration a Watchface  or App?   

 

I only tried the test using a Watchface type - 

 

I will repeat my tests because the distance field does appear to update and that is a very good sign! 

 

I did not monitor 'display.on' and will do so - I just watched the display go off and then my step counter stayed at the current count (console log) and updating again when the display turned on with jump in count.   Using display.on lets the log stand on it's own.

 

 I'll post my results.  Thanks again - 

 

Best Answer
0 Votes

This is in an app.

 

Just winding down and just have my tablet with me .... got the same results as you in the console having just corrected distance to steps (that was embarrassing). I will do a little more testing too and will try the same in a watch face too.

Best Answer
0 Votes

A quick test of distance & steps with display off - you can see distance changing, but not steps:

[5:14:14 PM]Distance:1638 Steps:2352 Display: false
[5:14:15 PM]Distance:1641 Steps:2352 Display: false
[5:14:16 PM]Distance:1643 Steps:2352 Display: false
. . .
[5:14:31 PM]Distance:1662 Steps:2352 Display: false

[5:14:57 PM]Distance:1662 Steps:2352 Display: false

[5:14:58 PM]Distance:1662 Steps:2384 Display: false << steps updated here

then the steps change - it does a catch up, display still off, so roughly 45 sec. from actual start of steps changing or maybe 30 sec or so after steps stop changing. 

  

And here is a test of generating steps with display off and then turning display on and seeing the instant update to the correct number of steps. 

Again, in the 'background' distance is changing, but not steps, at least not reported continuously.

[5:46:37 PM]Distance:1662 Steps:2384 Display: false

[5:46:38 PM]Distance:1662 Steps:2384 Display: false

5:46:40 PM]Distance:1668 Steps:2384 Display: false

[5:46:41 PM]Distance:1669 Steps:2384 Display: false

[5:46:54 PM]Distance:1684 Steps:2384 Display: false

[5:46:56 PM]Distance:1684 Steps:2413 Display: true << steps update with display turned on

[5:46:58 PM]Distance:1684 Steps:2413 Display: true

 

My conclusion is that there is some update of the step count with the display off, but appears to be incremental with 30 to 45 sec period from step start or stop. 

 

Best Answer
0 Votes

I concur with your test:

steps_updating.PNG

We need some official clarification. @SunsetRunner / @JonFitbit. Apologies for tagging you in directly, but are you able to comment on whether we should be able to see steps updating on a background listener whilst the display is off? It seems patchy at best. Is this a known issue that is being addressed? This issue seems to be more problematic in a watch app, @dde33 having investigated that angle, mine is in an app (still problematic).

Best Answer

I'm in discussion with the product team as I don't know the answer. It seems that it's on purpose: the steps are updated less frequently when the display is off. My guess is that steps are more complicated to calculate: there is an initial step count calculated by the smart watch, but there are some algorithms working on our servers to adjust this depending on different data (for example, you were driving). I'll get more information about this.

 

As for the interval to check, I would highly suggest checking way less often, for the battery’s sake. Unless what you are trying to do really needs to be updated every second.

 

Hope that help.

Best Answer
0 Votes

For my application @SunsetRunner I am looked to calculate SPM, which will need to be an average. to give any sort of meaning.

 

I get what your saying about battery, but we are talking about a background task without the display on.

 

Thanks for the information, I look forward to additional information when it becomes available.....

Best Answer
0 Votes

I use the the clock loop which is set at one second and it still runs with the display off.   I did go to setInterval() and tested the same situation re steps as I initially thought that there may be an anomaly in using the clock loop.  Not true, so I'd prefer to use only the clock to keep overhead down and not use another time interruption.  Maybe 'good practice' would have 'us' using  'display.on' as a state variable and limit processing when off as an energy consideration as the clock runs 24/7 so to speak. 

Best Answer
0 Votes

A workaround I've found is to trick the display into thinking the user has turned it on.

 

Using the display API 

import { display } from "display";

make the following calls inside your setInterval(), before polling today.local.steps

display.poke();
display.on = false;

Simply setting display.on to true and then back to false doesn't seem to "flush" the waiting step count into today.local.steps

Best Answer

Nice - will need to try this one. Thanks for the tip 🙂

 

Edit: Tried it and great workaround @6EQUJ5 works a treat. Solved a problem I was having.

 

@SunsetRunner: Background calculations for steps is working just fine - just not being reliably updated to today.local.steps when the display is off.

Best Answer
0 Votes

make the following calls inside your setInterval(), before polling today.local.steps

display.poke();
display.on = false;

Simply setting display.on to true and then back to false doesn't seem to "flush" the waiting step count into today.local.steps


Works!  Thanks!  Good catch .  .  . 

Best Answer
0 Votes

Thanks @6EQUJ5, it's a great workaround!

Best Answer