I am attempting to log Pebble accelerometer data to my computer. I was hoping to use PebbleKit JS to communicate with the watch itself, and then use websockets to send that data to my computer, but currently the websocket only sends one message and then the iOS app crashes.
Here is the content of pebble-js-app.js:
var ws = new WebSocket('ws://192.168.1.134:8888');
// Called when JS is ready
Pebble.addEventListener("ready",
function(e) {
console.log("js initialized");
}
);
// Called when incoming message from the Pebble is received
Pebble.addEventListener("appmessage",
function(e) {
console.log(ws.readyState);
if (ws.readyState === 1) {
ws.send('this gets sent');
ws.send(e.payload.message);
}
console.log("acc data: " + e.payload.message);
}
);
And here is the log that I get when I run the app:
[INFO ] Enabling application logging...
[INFO ] Displaying logs ... Ctrl-C to interrupt.
[INFO ] JS: starting app: 4C74DC80-A54E-4D0B-9BAB-FD355D364334 accelero
[INFO ] app is ready: 1
[INFO ] JS: accelerometer: js initialized
[INFO ] JS: accelerometer: 0
[INFO ] JS: accelerometer: acc data: 3131
[INFO ] JS: accelerometer: 1
[ERROR ] Lost connection to Pebble
The websocket server running on my computer logs the first message sent from the javascript. Only one message is sent, even when the order is changed (e.g. it prints either this gets sent
or a single actual reading from the accelerometer). Curiously, the built-in logging (console.log
) from javascript started only printing 3131
for the received data, even when the websocket sends some valid data. Can you see any errors in the code or do you have any other suggestions?