pebble
  • Tutorials
  • Get the SDK
  • Guides
  • Documentation
  • Examples
  • Community
  • Blog
  • More
Privacy
Cookies
Publish

Guides

  • Table of Contents
  • Alloy
    • Getting Started with Alloy
    • Piu UI Framework
    • Poco Graphics
    • Sensors and Input
    • Storage
    • Networking
    • App Messages
    • Watchfaces
    • Animations
    • Port (Custom Drawing)
    • Advanced Networking
    • Native Functions (FFI)
    • Dictation
    • Wakeups
    • Vibration
    • Device Info and App Events
  • App Resources
  • Best Practices
  • Communication
  • Debugging
  • Design and Interaction
  • Events and Services
  • Graphics and Animations
  • Pebble Packages
  • Pebble Timeline
  • Tools and Resources
  • User Interfaces

Wakeups

Wakeups let your Alloy app schedule itself to launch at a future time, even if it isn't running. When the wakeup fires, the system launches your app and you can read the wakeup details to know why it was started.

Platform Support: Wakeups are available on Emery (Pebble Time 2) and Gabbro (Pebble Time 2 round).

Scheduling a Wakeup

Import the WakeUp class and call schedule() with a timestamp (in milliseconds, as returned by Date.now()), a numeric cookie of your choice, and whether the user should be notified if the wakeup is missed:

import WakeUp from "pebble/wakeup";

// Fire 3 seconds from now
const id = WakeUp.schedule(Date.now() + 3000, 12345678, false);
console.log(`Scheduled WakeUp id ${id}`);

schedule() returns an id you can later use to query or cancel the wakeup. Persist the id (for example with localStorage) if you need it across launches.

Methods

Method Description
WakeUp.schedule(time, cookie, notifyIfMissed) Schedule a wakeup at time (ms). cookie is a number passed back to your app. notifyIfMissed shows a missed-event notification if the wakeup couldn't fire. Returns an id.
WakeUp.cancel(id) Cancel a previously scheduled wakeup.
WakeUp.query(id) Return a { time, scheduled } object describing the wakeup - time is the scheduled time in ms and scheduled is true if it is still pending - or a falsy value if it no longer exists.

Detecting a Wakeup Launch

When your app is launched by a wakeup, watch.wake is set and contains the wakeup's id and cookie:

console.log(`Launch reason ${watch.launch.reason}, arguments ${watch.launch.arguments}`);

if (watch.wake) {
    console.log(`Launched by wakeup id ${watch.wake.id}, cookie ${watch.wake.cookie}`);
}

Receiving a Wakeup While Running

If a wakeup fires while your app is already running, it is delivered as a "wakeup" event on watch:

watch.addEventListener("wakeup", wake => {
    console.log(`wakeup id ${wake.id} occurred while running`);
    WakeUp.cancel(wake.id);
});

Managing Stored Wakeups

Because a wakeup id outlives a single launch, it's good practice to validate a stored id on startup and discard it if the wakeup is gone or stale:

const id = localStorage.getItem("wakeid");
if (id) {
    const wakeup = WakeUp.query(id);
    if (!wakeup) {
        // The wakeup no longer exists
        localStorage.removeItem("wakeid");
    } else if (wakeup.time < Date.now()) {
        // The wakeup is in the past; cancel it
        WakeUp.cancel(id);
        localStorage.removeItem("wakeid");
    }
}

See the hellowakeup example for a complete project.

You need JavaScript enabled to read and post comments.

Overview

  • Scheduling a Wakeup
  • Methods
  • Detecting a Wakeup Launch
  • Receiving a Wakeup While Running
  • Managing Stored Wakeups