node package manager
Love JavaScript? Your insights can make it even better. Take the 2017 JavaScript Ecosystem Survey »

cordova-pebble

cordova-pebble

Implementation of the Pebble SDK for Cordova. Supports Android and iOS.

Installation

Cordova CLI

cordova plugin add https://github.com/tgardner/cordova-pebble.git

Telerik AppBuilder

appbuilder plugin fetch https://github.com/tgardner/cordova-pebble.git

Usage

Set the UUID of your companion app, and register callbacks for connect/disconnect events from watches:

Pebble.setAppUUID("cb2efd3c-4fa5-4bb9-b99b-9e0a1f3f9b62", 
    function() { console.log('success'); },
    function(event) { console.log('failure'); });
Pebble.onConnect(
    function(event) { alert('connected'); }
    function(event) { alert('disconnected'); });

Launch your app:

Pebble.launchApp(
    function() { console.log('success'); },
    function(event) { console.log('failure'); });

Send a message to the watch:

Pebble.sendAppMessage({0: "hello"},
    function() { console.log('success'); },
    function(event) { console.log('failure'); });

Receive messages from the watch:

Pebble.onAppMessageReceived(function(message){
    console.log(message);
});

Kill your app:

Pebble.killApp(
    function() { console.log('success'); },
    function(event) { console.log('failure'); });

Example

Pebble.setAppUUID("cb2efd3c-4fa5-4bb9-b99b-9e0a1f3f9b62", 
    function() { 
        Pebble.onConnect(function(event) { 
            Pebble.onAppMessageReceived(function(message){
                console.log(message);
            });
 
            Pebble.sendAppMessage({0: "hello"},
                function() { console.log('message sent'); });
        });
    }
);