3

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?

andars
  • 1,384
  • 7
  • 12
  • Your code works fine for me. Do you get something on the server when you send the data? – Antoine Mar 19 '14 at 22:46
  • The server receives the whatever message is sent over the websocket first, no matter what it is, and after that the iOS app crashes. Did your test include an app on the pebble sending messages to the phone? – andars Mar 20 '14 at 03:53
  • For my tests, the flow of messages is something like that: Pebble => Phone (js framework) => server (over ws) => Phone (js framework, over ws again) => Pebble. If you don't use 'e.payload.message' in your listener, does it still crash? – Antoine Mar 20 '14 at 09:15

0 Answers0