27
TITLE TEXT CONNECTING PEBBLE TO THE WORLD THOMAS SARLANDIE OCT. 17TH 2014 - WEARABLE+THINGS

Connecting Pebble to the World

Embed Size (px)

Citation preview

Page 1: Connecting Pebble to the World

TITLE TEXT

CONNECTING PEBBLE TO THE WORLD

THOMAS SARLANDIE OCT. 17TH 2014 - WEARABLE+THINGS

Page 2: Connecting Pebble to the World

@sarfata

Developer, Hardware tinkerer, Passionate Geek

Developer Evangelist @Pebble

I connect Pebble to the world!

Page 3: Connecting Pebble to the World
Page 4: Connecting Pebble to the World

Wearable Service - Device

Page 5: Connecting Pebble to the World

Wearable Service - Device

API API

Page 6: Connecting Pebble to the World

1 - Identify the APIs available

2 - Prototype

3 - Connect

Page 7: Connecting Pebble to the World

0 - Know your tools

Sensors

Accel. CompassButtons

Phone

Native Apps JavaScript

HTTP/JSON

Bluetooth LE

GPS

Page 8: Connecting Pebble to the World
Page 9: Connecting Pebble to the World

1 - Identify the APIs available

Page 10: Connecting Pebble to the World

http://api.openweathermap.org/data/2.1/find /city?lat=38.89&lon=-77.07=&cnt=1

2 - Prototype

Page 11: Connecting Pebble to the World

3 - Connect

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

var main = new UI.Card({ title: 'WX Station', body: 'Loading ...' });

main.show();

var url = “http://api.openweathermap.org/data/2.1/find/city?" + "cnt=1&lat=38.89&lon=-77.07";

ajax( { url: url, type: 'json' }, function(weather) { var temp = (weather.list[0].main.temp - 273.15) temp = (temp* 1.8 + 32).toFixed(1); main.body('Temperature: ' + temp + " F"); }, function (err) { console.log("AJAX Error: " + err); } );

Page 12: Connecting Pebble to the World

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

var main = new UI.Card({ title: 'WX Station', body: 'Loading ...' });

main.show();

var url = "http://api.openweathermap.org/data/2.1/find/city?cnt=1&lat=38.89&lon=-77.07"; ajax( { url: url, type: 'json' }, function(weather) { var temp = ((weather.list[0].main.temp - 273.15) * 1.8 + 32).toFixed(1); main.body('Temperature: ' + temp + " F"); }, function (err) { console.log("AJAX Error: " + err); } );

Page 13: Connecting Pebble to the World

navigator.geolocation.getCurrentPosition( function(pos) { var url = "http://api.openweathermap.org/data/2.1/find/city?cnt=1" + "&lat=" + pos.coords.latitude + "&lon=" + pos.coords.longitude; ajax( { url: url, type: 'json' }, function(weather) { var temp = (weather.list[0].main.temp - 273.15); temp = (temp * 1.8 + 32).toFixed(1); main.body('Temperature: ' + temp + " F"); }, function (err) { console.log("Error: " + err); } ); }, function (err) { console.log("Gps error: " + JSON.stringify(err)); }, { timeout: 10000 } );

Page 14: Connecting Pebble to the World
Page 15: Connecting Pebble to the World

1 - Identify the APIs available

Page 16: Connecting Pebble to the World

2 - Prototype

$ curl --request PUT --data '{"on":true}' \ http://url/api/username/lights/1/state

Page 17: Connecting Pebble to the World

3 - Connect

Page 18: Connecting Pebble to the World

var setHueState = function(id, state) { ajax( { url: 'http://192.168.0.42/api/newdeveloper/lights/' + id + '/state', type: 'json', method: 'PUT', data: state }, function(data) { console.log('Success: ' + JSON.stringify(data)); }, function(error) { console.log('The ajax request failed: ' + error); } ); console.log("Request sent! New state: " + JSON.stringify(state)); };

Page 19: Connecting Pebble to the World

console.log("Request sent! New state: " + JSON.stringify(state)); };

var ambiances = [ { title: 'Warm', bri: 255, ct: 500 }, { title: 'Cold', bri: 255, ct: 153 }, { title: 'Red', bri: 255, sat: 255, hue: 0 }, { title: 'Yellow', bri: 255, sat: 255, hue: 12750 }, { title: 'Green', bri: 255, sat: 255, hue: 25500 }, { title: 'Blue', bri: 255, sat: 255,hue: 46920 }, { title: 'Purple', bri: 255, sat: 255,hue: 56100 } ];

var menu = new UI.Menu({ sections: [{ items: ambiances }] }); menu.on('select', function(e) { setHueState(3, e.item); }); menu.show();

Page 20: Connecting Pebble to the World
Page 21: Connecting Pebble to the World
Page 22: Connecting Pebble to the World

1 - Identify the APIs available

Page 23: Connecting Pebble to the World

Pebble BLE Robot

“PebbleBot” Service UUID

Characteristic UUID / Properties (R/W/…)

Left Motor Speed

Characteristic UUID / Properties (R/W/…)

1 - Identify the APIs available

Right Motor Speed

Page 24: Connecting Pebble to the World

static void handle_up_button_up(ClickRecognizerRef recognizer, void *context) { ble_client_write_without_response(s_ctx.scratch1_characteristic, (const uint8_t *) &SERVO_STILL, sizeof(SERVO_STILL)); printf("UP=0"); }

static void handle_up_button_down(ClickRecognizerRef recognizer, void *context) { ble_client_write_without_response(s_ctx.scratch1_characteristic, (const uint8_t *) &SERVO_BACK, sizeof(SERVO_BACK)); printf("UP=1"); }

static void handle_down_button_up(ClickRecognizerRef recognizer, void *context) { ble_client_write_without_response(s_ctx.scratch2_characteristic, (const uint8_t *) &SERVO_STILL, sizeof(SERVO_STILL)); printf("DOWN=0"); }

static void handle_down_button_down(ClickRecognizerRef recognizer, void *context) { ble_client_write_without_response(s_ctx.scratch2_characteristic, (const uint8_t *) &SERVO_FWD, sizeof(SERVO_FWD)); printf("DOWN=1"); }

Page 25: Connecting Pebble to the World
Page 26: Connecting Pebble to the World

Illustrations by sam brown, explodingdog

Thomas Sarlandie @sarfata / @pebbledev

1 - Identify the APIs available

2 - Prototype

3 - Connect

4 - Have fun!

Page 27: Connecting Pebble to the World