Search code examples
javascriptpebble-watchcloudpebble

Pebble.js update view frequently


I'm building an app for the Pebble watch using Pebble.js in cloudpebble.

When I look at the Javascript tips & tricks there is a really big heading that says:

Do not use setInterval(). And of course, do not use setTimeout() to simulate intervals.

As an alternative.. It does say

If you need some function to run at regular intervals, set a timer on Pebble and send a message to the JavaScript. If the JavaScript is dead, the mobile app will re-initialize it and run the message handler.

But I can't find any way to do this with pure javascript

Do you guys have any experience with this?


Solution

  • The advice we gave about setInterval() applied in the early days but not anymore. Feel free to use setInterval() now, your JavaScript will run properly as long as your app is running.

    Of course, every time your JavaScript wakes up it will use some battery on the phone. And even more battery if you communicate with the watch. Be aware of the battery impact. This is true for both PebbleKit JS and Pebble.js.

    In Pebble.js, if you just want to update the time on the screen, you can use the TimeText Element.