• Hi,
    I'm a first timer here. Fantastic project! I wasn't even looking for a smartwatch, but just had to have one, when I saw it :) .

    I'm trying to store barometer data for the past few hours (to indicate rising/falling pressure on a watch face).
    Current approach : use a widget as a background service. Using a timer, I power up the pressure sensor once or twice per hour, and store the data in a buffer (using fixed-size typed array in a ring-buffer fashion). The array buffer lives in the scope of the widget. Since the widget isn't graphical, it just has width=0 and an empty draw() function.
    However, whenever I leave the watch face, e.g. to open an app or go into settings, the widget seems to be reloaded. The buffer seems to have gone out of scope and gotten garbage-collected, as in the init code of the widget, it is undefined. I'm guessing that the WIDGETS global variable is

    I did a workaround where I write the buffer to flash storage each time I add a value, then re-initialize from that file when loading the widget. But it seems odd to be constantly writing to flash all the time, especially when it's data that is (relatively) short lived. But it does need the history of the past 1-2 hours to make sense.

    • Is there any way to make a service like this in bangle.js? Meaning something that starts when the watch is started, so that a variable may survive widget reloads?
    • Or as a backup plan - is there any way I can hook up to an event before the WIDGET variable is nuked, i.e. before widgets are loaded? That way I could save data to file only on that occasion, instead of scratching the flash constantly.
    • Or, as a backup plan, I guess I could use my own global variable to store the buffer. That feels a bit dirty, however. Would that be considered good practice (I'm not very experienced in javascript programming...).

    A bonus question, slightly related : Is there any event one could hook to, that fires before the watch is reset? Also with saving data to permanent storage in mind.

    btw - I'm running on fw 2v12.70

    Greetings, and thanks for a fantastic project!
    Indriði

About

Avatar for Indridi @Indridi started