Post on 12-Jul-2015
transcript
TITLE TEXT
CONNECTING PEBBLE TO THE WORLD
THOMAS SARLANDIE OCT. 17TH 2014 - WEARABLE+THINGS
@sarfata
Developer, Hardware tinkerer, Passionate Geek
Developer Evangelist @Pebble
I connect Pebble to the world!
Wearable Service - Device
Wearable Service - Device
API API
1 - Identify the APIs available
2 - Prototype
3 - Connect
0 - Know your tools
Sensors
Accel. CompassButtons
Phone
Native Apps JavaScript
HTTP/JSON
Bluetooth LE
GPS
1 - Identify the APIs available
http://api.openweathermap.org/data/2.1/find /city?lat=38.89&lon=-77.07=&cnt=1
2 - Prototype
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); } );
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); } );
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 } );
1 - Identify the APIs available
2 - Prototype
$ curl --request PUT --data '{"on":true}' \ http://url/api/username/lights/1/state
3 - Connect
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)); };
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();
1 - Identify the APIs available
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
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"); }
Illustrations by sam brown, explodingdog
Thomas Sarlandie @sarfata / @pebbledev
1 - Identify the APIs available
2 - Prototype
3 - Connect
4 - Have fun!