Retrieve data in the background

Posted on
  • I am still waiting for my watch to be delivered and I am already looking at the docs to understand the programming model!

    As far as I understand it, the "apps" one can develop, are pieces of JS code that run when the user taps on their icon. Now, suppose I want to have some background data collection even when the user is outside of my app, how can I allow that? For example, say I would like to log each single step event on a file.

    1) are events, like the step event, handled even if the app has been killed?
    2) what about timers? will they be kept running?
    3) how can I auto-start my app?
    4) would customising the boot app work for my case?

    thanks and congratulations for the great product and idea, I'm a big fan.

  • There are two ways to do this,

    1. First is to create a widget with a tiny UI on the top to indicate it is running
    2. Take any of the clock apps there is an add functionality to the app.

    1 and 2

    If you build an App, you have the option of handling the kill event and saving app state to a file. When you app is restarted you can continue where you left off. You'll need to wire up the event handlers again though.

    3

    If you build a widget I believe it auto starts on load (I haven't built one yet). If you build an app, and it is the only clock app on the watch it will start automatically on load. If you have multiple clock apps, you have the option of specifying which one is your default clock app.

    4

    Should be doable, all the code is out there but I would explore all other options first :-)

    Have a poke at the existing apps in the Bangle Apps repository on Github it is fairly (Espruino) beginner friendly :-)

  • @PiOfThings is spot on here. I'll be coming up with some proper tutorials soon and I'll try and cover this.

    But right now, Widgets are your answer. The GPS Recorder widget is probably a good place to start: https://github.com/espruino/BangleApps/t­ree/master/apps/gpsrec

    It:

    • Has an app that lets you configure it
    • Has a widget that runs in the background and (when enabled) starts logging data
    • Has an 'interface.html' file which runs inside the App Loader and allows it to read back the recorded data.

    There are a few gotchas:

    • There's no way to leave code permanently running as you change apps - right now it's a design choice because I think at least initially it's important that the watch is really stable (and that means always bringing apps up in a known state). You can respond to a kill event to save state and reload it later though.
    • Not all apps will actually load widgets (games won't for example) so your stuff won't run in the background in that case. I'll be working to modify more apps to make them load widgets where it is sensible to though.
  • Thanks for the answer!
    So, as far as I understand it, the options for this case would be:

    a) customise the boot app
    b) build a widget
    c) customise a clock app

    I didn't realise the widget thing! So I understand that, once installed, a widget is auto-restarted, runs all the time, and will react to events and timers even if the watch is idle.
    The pedometer widget is actually the perfect starting point for my case.

  • That's correct, yes. Potentially if there's a need I may add other options, but I think for the vast majority of cases the widgets work really nicely.

    The pedometer widget is actually the perfect starting point for my case.

    Ok, perfect!

  • @Gordon,

    Not all apps will actually load widgets (games won't for example) so your stuff won't run in the background in that case. I'll be working to modify more apps to make them load widgets where it is sensible to though.

    I could see a runtime option of the platform: app running w/ and app running w/o widgets controlled by the app by providing a particular property or function/method.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Retrieve data in the background

Posted by Avatar for user107850 @user107850

Actions