Quantcast
Channel: OpenEnergyMonitor aggregator
Viewing all articles
Browse latest Browse all 328

Nathan Chantrell.net: Sending Pins to the Pebble Timeline

$
0
0
Pins added via Node.js
Pins added via Node.js

There are a number of different libraries available for sending pins to the Timeline on a Pebble watch, including those for Javascript, Node.js, Ruby, Python, PHP and C.  To use any of these you need a unique user token which is a UUID unique to both an app installed on the watch and the user, I couldn’t find a straightforward description of what is required to get a token so I’ve detailed what needs to be done below.

Getting a token the easy way

If you just want to do it the easy way I’ve created a Timeline Token app which is available on the Pebble Appstore, once installed on your Pebble it will display the token and give you a short URL to view it on the web (to save retyping the lengthy UUID from the Pebble screen).

token
My Timeline Token app, aka the easy way

If you use my app you can jump straight to step 5 below to test it.

Regardless of whether you use my app or create one using the process below it will need to remain installed in the Pebble phone app for pins using the resulting token to come through to your watch.

Step by step guide

This is the process to create your own simple app to get a Timeline user token.

Step 1: Create an app

The app serves two purposes, it gets us the unique user token and enables pins to be sent to the watch.

Creating an app is easy to do online, no need to install an SDK or dev environment, first log in to CloudPebble.

Create a new app with the project type of “Pebble.js (beta)” and give it a name, eg. Timeline Token

Click on app.js under SOURCE FILES, delete the default code it gives you and replace it with the following:


/**
* Just gets the Timeline token
*/

var UI = require('ui');
var myToken;

Pebble.getTimelineToken(
function (token) {
console.log('My timeline token is ' + token);
myToken = token;
var tokenDisplay = new UI.Card({
subtitle: 'Timeline Token',
body: myToken
});
tokenDisplay.show();
},
function (error) {
console.log('Error getting timeline token: ' + error);
}
);

Then go to COMPILATION on the left and then click BUILD, when that is done click GET PBW to download the .pbw file.

Step 2: Add the app to the Pebble app store

This step is required so that Pebble have the UUID of your app and allows you to enable timeline support for it. You don’t need to publish the app, just uploading it and enabling timeline is sufficient.

Create a Pebble developer profile if you don’t already have one.

Click “Create a Watchapp”

Give it a name and click create

On the next page click “Add a release” and upload the .pbw file you downloaded from step 1 above.

You do not need to publish the application, it just needs to be uploaded so that Pebble have the apps UUID which is required for sending the pins.

If the release status says “Validation pending” wait a few seconds and refresh the page and you should now see it showing Ready and you will now see the UUID in the Application data section above.

Now click Enable timeline button.

Step 3. Get the timeline token

Now back in CloudPebble, under COMPILATION click the BASALT button at the top to run the app in the Pebble Time emulator.

When it runs and shows the token on the emulated Pebble’s screen click the “VIEW APP LOGS” button where you will see your timeline token in the log, eg.

My timeline token is e6b41993c9604c458f7bee3cd501d0ec

Copy the token and save it in a safe place.

You need never use CloudPebble or the Developer Portal again once you have the token.

Step 4. Install the app on your phone

The final step is to load the app on to your phone as the pins will only work while the app is installed in the Pebble Time app.

Step 5. Test it

Now we can try a test, there are a number of libraries available or you can do a PUT to the web API with Curl.

As an example, to test it with the node.js:

Install with: npm install pebble-api

Create a file eg. pebble.js with the following (inserting your user token where indicated)


var Timeline = require('pebble-api').Timeline;

var timeline = new Timeline();

var userToken = 'ENTER YOUR USER TOKEN HERE';

var pin = new Timeline.Pin({
time: new Date(),
duration: 10,
layout: new Timeline.Pin.Layout({
type: Timeline.Pin.LayoutType.GENERIC_PIN,
tinyIcon: Timeline.Pin.Icon.NOTIFICATION_FLAG,
title: 'Pin Title'
})
});

timeline.sendUserPin(userToken, pin, function (err) {
if (err) {
return console.error(err);
}

console.log('Pin sent successfully!');
});

Then run it with node pebble.js and you should shortly see the pin arrive on your Pebble.

The help page here details how you can create notifications, reminders and open apps using the pins as well as the names for the different icons that are available.

In the next post I’ll talk about the node I created for Node-RED to do this.

 


Viewing all articles
Browse latest Browse all 328

Trending Articles