The Pebble namespace is where all of the Pebble specific methods and properties exist. This class contains methods belonging to PebbleKit JS and allows bi-directional communication with a C or JavaScript watchapp, as well as managing the user's timeline subscriptions, creating AppGlance slices and obtaining information about the currently connected watch.
Adds a listener for PebbleKit JS events, such as when an AppMessage is received or the configuration view is opened or closed.
Event Type Options
Possible values:
ready - The watchapp has been launched and the PebbleKit JS component is now ready to receive events.
appmessage - The watch sent an AppMessage to PebbleKit JS. The AppMessage Dictionary is contained in the payload property (i.e: event.payload). The payload consists of key-value pairs, where the keys are strings containing integers (e.g: "0"), or aliases for keys defined in package.json (e.g: "KEY_EXAMPLE"). Values should be integers, strings or byte arrays (arrays of characters).
showConfiguration - The user has requested the app's configuration webview to be displayed. This can occur either upon the app's initial install or when the user taps 'Settings' in the 'My Pebble' view within the phone app.
webviewclosed - The configuration webview was closed by the user. If the webview had a response, it will be contained in the response property (i.e: event.response). This response can be used to feed back user preferences to the watchapp.
The type of the event, from the list described above.
The developer defined EventCallback to receive any events of the type specified that occur.
Remove an existing event listener previously registered with Pebble.addEventListener().
The type of the event listener to be removed. See Pebble.addEventListener() for a list of available event types.
The existing developer-defined function that was previously registered.
Show a simple modal notification on the connected watch.
The title of the notification
The main content of the notification
Send an AppMessage to the app running on the watch. Messages should be in the form of JSON objects containing key-value pairs. See Pebble.sendAppMessage() for valid key and value data types. Pebble.sendAppMessage = function(data, onSuccess, onFailure) { };
A JSON object containing key-value pairs to send to the watch. Values in arrays that are greater then 255 will be mod 255 before sending.
A developer-defined AppMessageAckCallback callback to run if the watch acknowledges (ACK) this message.
A developer-defined AppMessageNackCallback callback to run if the watch does NOT acknowledge (NACK) this message.
The transaction id for this message
The Pebble mobile app returns a token only for apps installed from the appstore. Sideloaded apps receive the failure callback. The timeline web API is no longer available, so the token cannot be used to push pins. Use insertTimelinePin instead.
Get the user's timeline token for this app. This is a string and is unique per user per app. Note: In order for timeline tokens to be available, the app must be submitted to the Pebble appstore, but does not need to be public. Read more in the timeline guides.
A developer-defined TimelineTokenCallback callback to handle a successful attempt to get the timeline token.
A developer-defined callback to handle a failed attempt to get the timeline token.
Not supported in the Pebble mobile app. The timeline web API is no longer available and the callbacks never fire. Use insertTimelinePin instead.
Subscribe the user to a timeline topic for your app. This can be used to filter the different pins a user could receive according to their preferences, as well as maintain groups of users.
The desired topic to be subscribed to. Users will receive all pins pushed to this topic.
A developer-defined callback to handle a successful subscription attempt.
A developer-defined callback to handle a failed subscription attempt.
Not supported in the Pebble mobile app. The timeline web API is no longer available and the callbacks never fire. Use insertTimelinePin instead.
Unsubscribe the user from a timeline topic for your app. Once unsubscribed, the user will no longer receive any pins pushed to this topic.
The desired topic to be unsubscribed from.
A developer-defined callback to handle a successful unsubscription attempt.
A developer-defined callback to handle a failed unsubscription attempt.
Not supported in the Pebble mobile app. The timeline web API is no longer available and the callbacks never fire. Use insertTimelinePin instead.
Obtain a list of topics that the user is currently subscribed to. The length of the list should be checked to determine whether the user is subscribed to at least one topic.
Pebble.timelineSubscriptions(function(topics) { console.log(topics); }, function() { console.log('error'); } );
The developer-defined function to process the retuned list of topic strings.
The developer-defined function to gracefully handle any errors in obtaining the user's subscriptions.
Insert a pin into the user's timeline. The pin is created by the newPebble app and synced to the watch, so no timeline token, API key orappstore listing is required and sideloaded apps can use it. The pin isassociated with your app, and its id only needs to be unique withinyour app - inserting a pin with an existing id updates that pin. Thenew Pebble app does not support the timeline web API, so this is how newapps should create pins. Read more in thelocal pins guide.
The pin to insert, in the format described inCreating Pins. A JSONstring of the same object is also accepted.
Remove a pin previously added withinsertTimelinePin from the user's timeline.
The id of the pin to delete.
Obtain an object containing information on the currently connected Pebble smartwatch.
A WatchInfo object detailing the currently connected Pebble watch.
Returns a unique account token that is associated with the Pebble account of the current user.
A string that is guaranteed to be identical across devices if the user owns several Pebble or several mobile devices. From the developer's perspective, the account token of a user is identical across platforms and across all the developer's watchapps. If the user is not logged in, this function will return an empty string ('').
Returns a a unique token that can be used to identify a Pebble device.
A string that is is guaranteed to be identical for each Pebble device for the same app across different mobile devices. The token is unique to your app and cannot be used to track Pebble devices across applications.
Not supported in the Pebble mobile app. The callbacks never fire. Use the C AppGlance API from the watchapp instead.
Triggers a reload of the app glance which first clears any existing slices and then adds the provided slices.
AppGlanceSlice JSON objects to add to the app glance.
The developer-defined callback which is called if the reload operation succeeds.
The developer-defined callback which is called if the reload operation fails.
When an app is marked as configurable, the PebbleKit JS component must implement Pebble.openURL() in the showConfiguration event handler. The Pebble mobile app will launch the supplied URL to allow the user to configure the watchapp or watchface. See the App Configuration guide.
The URL of the static configuration page.
Returns the installed plugins. Each entry has uuid, name, sources and actions, copied from the plugin's manifest. Returns an empty array when the call fails.
Preview. Does nothing useful until the plugins preview is turned on in the Pebble mobile app. The API will change. See the Plugins (Preview) guide.
An array of plugin descriptions.
Subscribes to one item of one category and delivers every update to config.onData as an envelope with pluginUuid, validUntilMs and instances. Throws when category or item is missing. Failures the Pebble mobile app detects, such as no plugin for the item or a missing permission, are reported to config.onError as { code, message }.
Preview. Does nothing useful until the plugins preview is turned on in the Pebble mobile app. The API will change. See the Plugins (Preview) guide.
An object with category and item (required), and optional properties (array of property names), plugin (UUID of a preferred plugin), iconPixelSize ({ w, h }, needed for icon and image shapes), onData and onError callbacks.
A subscription object with an unsubscribe() method. The subscription also ends when the app's JavaScript stops.
Invokes one action on one plugin. The returned Promise always resolves: with { ok: true, text, refreshed } on success, or { ok: false, code, message }, with text, refreshed and message omitted when the plugin did not set them. Throws when plugin or action is missing. Actions never fall back to another plugin.
Preview. Does nothing useful until the plugins preview is turned on in the Pebble mobile app. The API will change. See the Plugins (Preview) guide.
An object with plugin (the plugin's UUID) and action (required), args (an object matching the action's parameters schema, default {}) and timeoutMs (1 to 60000, default 15000).
A Promise that resolves with the action result.
Pushes a message to the app's own settings page while that page is open. The page receives it as a message event with e.target set to "pkjs" and e.data set to the message. There is no reply, and nothing happens when no page is open.
Preview. Does nothing useful until the plugins preview is turned on in the Pebble mobile app. The API will change. See the Plugins (Preview) guide.
Any JSON value to deliver to the page.
Called when the user's list of subscriptions is available for processing by the developer.
of topic strings that the user is subscribed to
Called when AppGlanceReload has failed.
An AppGlanceSlice object containing the app glance slices.
Called when an AppMessage is acknowledged by the watch.
An object containing the callback data. This contains the transactionId which is the transaction ID of the message.
Called when an AppMessage is not acknowledged by the watch.
An object containing the callback data. This contains the transactionId which is the transaction ID of the message
The error message
Called when an event of any type previously registered occurs. The parameters are different depending on the type of event, shown in brackets for each parameter listed here.
An object containing the event information, including:
type - The type of event fired, from the list in the description of Pebble.addEventListener().
payload - The dictionary sent over AppMessage consisting of key-value pairs.
response - The contents of the URL navigated to when the configuration page was closed, after the anchor. This may be encoded, which will require use of decodeURIComponent() before reading as an object.
Called when the user's timeline token is available.
The user's token.
Called when AppGlanceReload is successful.
An AppGlanceSlice object containing the app glance slices.
Provides information about the connected Pebble smartwatch.
The hardware platform, such as basalt or emery.
The watch model, such as pebble_black
The user's currently selected language on this watch.
An object containing information about the watch's firmware version, including:
major - The major version
minor - The minor version
patch - The patch version
suffix - Any additional version information, such as beta3
The structure of an app glance.
Optional ISO date-time string of when the entry should expire and no longer be shown in the app glance.
An object containing:
icon - URI string of the icon to display in the app glance, e.g. system://images/ALARM_CLOCK.
subtitleTemplateString - Template string that will be displayed in the subtitle of the app glance.
Web API by Mozilla Contributors is licensed under CC-BY-SA 2.5.
Do you need some help understanding the something on this page?
Ask on the developer forum.