Skip to content

Instantly share code, notes, and snippets.

@JoshuaJB JoshuaJB/app.js

Last active Aug 29, 2017
What would you like to do?
Basic Pebble App with WebSockets
* This is free and unencumbered software released into the public domain.
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
var UI = require('ui');
// WARNING: Does not work on emulator
var ws = new WebSocket('ws://');
ws.onopen = function(evt){ console.log("connected!"); };
ws.onmessage = function(evt) { console.log("message: " + JSON.stringify(; };
ws.onerror = function(evt) { console.log("error"); };
var main = new UI.Card({
title: 'RaspPI GPIO',
subtitle: 'Welcome!',
body: 'Press the middle button.'
main.on('click', 'select', function(e) {
var menu = new UI.Menu({
sections: [{
items: [{
title: 'On',
subtitle: 'Turn on LED'
}, {
title: 'Off',
subtitle: 'Turn off LED'
menu.on('select', function(e) {
switch (e.itemIndex) {
case 0:
ws.send(JSON.stringify({type: "broadcast", label: "ctrl", payload: 0}));
case 1:
ws.send(JSON.stringify({type: "broadcast", label: "ctrl", payload: 1}));
console.log('Unknown item selected: ' + e.itemIndex);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.