Need help with Background process

Need to arrange background process, which will be called for every round hour (min and sec = 0), get data from API, store it in arrey in property or base and exit bg process.

Main question, how to call bg process for requestd time momen even if app inactive.

Thsnks for ideas)))

  • Finnaly get to internet)))

    Yap... Already understood, that for watch face, no chance to catch button-press...
    Just drops to unknown error...
    Hope, that Garmin, one day, will give access to Btn listener for WF. It will be really useful.

    In my case: done pressure diagram, one :traditional from SensorHystory (abt. 4hrs period) + same type other diagrams for temperature and elevation (just to have); and 24hrs pressure diagram, which collecting data in BG process. So, I want to make switch, by catching single unused key for WF - "Back", just to switch flag from 1 to 0 and back, so in view part, by simple "if" jump between 24hr and standard diagram.

    Any-how, for that WF i want to make - all done. With BT listener ? just a toy)))
    Now making 24hr test, so far all ok, after will post update for WF with 24hr pressure)))

    Great thanks everyone for help and advises))) It's really great, that on this forum, such a fast and useful assistance)))
  • Hermo, Thanks!

    Dmytri, he's the basics of how I do pressure data in the background.. No sensor history involved, and I do both ambient and MSL pressure. This will only work with 2.x devices with a baro altimeter.
    function onTemporalEvent() {
    var old=Background.getBackgroundData();

    var actInfo=Activity.getActivityInfo();

    var data=[[Time.now().value(),actInfo.ambientPressure,actInfo.meanSeaLevelPressure]];
    //at this point, merge "old" with "data", so readings aren't lost in the main app, and in a way the main app can use and understand it it. This is also where I limit what's returned to the 48 samples I mentioned before
    Background.exit(data);
    }


    Very interesting idea))
    Will try to play with Activity))
  • Through Activity not working... Returns "null"...
  • Which watch? The watch has to have a baro altimeter. Or are you seeing this in the sim? There you have to Simulate data, under Simulation>FIT Data.
  • 5x. fw 8.0

    Shure, in simulatir, when Activiti runs, all in order, when, stops - get null...

    On device, WF not started at all. From log , can see same null...
    Looks like activity must be started first, at list on 5x...
    However with sensor hystory all works good.
  • In my background code for the widget I use this in (and it runs on the f5x), I do check for null values, as there was a case when when I watch first booted, it took a minute or so to get a reading. Did you wait for a second cycle in the background? Also, I have watchfaces that read these values in the foreground that runs fine on the f5x.

    When I get time, I try the background in a watchface on the f5x.
  • Ok, so I took my background stuff that uses Acitivity.Info for the pressure into a simple watch face I have, and it's functioning as inspected. I have the temporal event set for 5 minutes, and I'm getting the changing values when I should. I suspect the first time your background runs, it might not have any data yet if it's right after a boot, but when it runs again, it will. You wanted to run the background on the top of the hour, but you may want to include something like, make that every 5 minutes, until non-null data is seen, and then switch to the top of the hour.

    In the mean time, when you have no data and nothing you saved in the object store, You can check in the foreground and use that data.for a first reading
  • Ok, thanks for advice, will play with delays. But, if from the beginig it gives null, looks like it needs for some activity to appear, to get data... Not shure that it will works, let's at night time, when user sleeps.

    Anyhow thanks for advise, will try to play with it.
  • It's for a very brief time I'll see a null after a boot. With the f5x I'm using to test, I've not recorded an activity on in a week or more. No need to start an activity.

    Like I said, it's working fine for me, and currently have 4hrs of data.
  • Jim, you are, as usual right)))
    And thanks again for your advices and patience))))
    So, for initial call, i,'ve just made trasfer null to 0, in case of null. And all working))))
    With yours help, now my WF will have ambient, raw and msl pressures)))
    Thanks again)))