Download - Connecting Pebble to the World
![Page 1: Connecting Pebble to the World](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/1.jpg)
TITLE TEXT
CONNECTING PEBBLE TO THE WORLD
THOMAS SARLANDIE OCT. 17TH 2014 - WEARABLE+THINGS
![Page 2: Connecting Pebble to the World](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/2.jpg)
@sarfata
Developer, Hardware tinkerer, Passionate Geek
Developer Evangelist @Pebble
I connect Pebble to the world!
![Page 3: Connecting Pebble to the World](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/3.jpg)
![Page 4: Connecting Pebble to the World](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/4.jpg)
Wearable Service - Device
![Page 5: Connecting Pebble to the World](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/5.jpg)
Wearable Service - Device
API API
![Page 6: Connecting Pebble to the World](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/6.jpg)
1 - Identify the APIs available
2 - Prototype
3 - Connect
![Page 7: Connecting Pebble to the World](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/7.jpg)
0 - Know your tools
Sensors
Accel. CompassButtons
Phone
Native Apps JavaScript
HTTP/JSON
Bluetooth LE
GPS
![Page 8: Connecting Pebble to the World](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/8.jpg)
![Page 9: Connecting Pebble to the World](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/9.jpg)
1 - Identify the APIs available
![Page 10: Connecting Pebble to the World](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/10.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/11.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/12.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/13.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/14.jpg)
![Page 15: Connecting Pebble to the World](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/15.jpg)
1 - Identify the APIs available
![Page 16: Connecting Pebble to the World](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/16.jpg)
2 - Prototype
$ curl --request PUT --data '{"on":true}' \ http://url/api/username/lights/1/state
![Page 17: Connecting Pebble to the World](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/17.jpg)
3 - Connect
![Page 18: Connecting Pebble to the World](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/18.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/19.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/20.jpg)
![Page 21: Connecting Pebble to the World](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/21.jpg)
![Page 22: Connecting Pebble to the World](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/22.jpg)
1 - Identify the APIs available
![Page 23: Connecting Pebble to the World](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/23.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/24.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/25.jpg)
![Page 26: Connecting Pebble to the World](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/26.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062419/55a22e811a28ab92428b4612/html5/thumbnails/27.jpg)