Unable to send data from watchface to http endpoint

I’m on Pebble Time 2 and am building a watchface with custom gesture detection. I’m trying to get data to train a model (accelerometer sampling for gesture recognition training data). App installs and runs fine via .pbw sideload, but no data is reaching my collector that is a python flask app running on my Mac.

Setup:

  • Pebble Time 2, app installed via .pbw upload (not CloudPebble Install and Run, which fails separately with connection errors)
  • C watchapp samples accelerometer at 50Hz into 75-sample windows, then sends via AppMessage in 5-sample chunks
  • PebbleKit JS appmessage listener forwards each chunk via XMLHttpRequest POST to a local Flask server on my Mac
  • Flask server confirmed working via curl (same network, same IP) — POSTs succeed and write to CSV correctly outside of the watch

Any ideas what I’m missing?

--

var MAC_URL = “http://192.168.0.22:5050/chunk”; // Change to your Mac’s IP

Pebble.addEventListener(“ready”, function() {
console.log(“PebbleKit JS ready”);
});

Pebble.addEventListener(“appmessage”, function(event) {
var payload = event.payload;

var xhr = new XMLHttpRequest();
xhr.open(“POST”, MAC_URL, true);
xhr.setRequestHeader(“Content-Type”, “application/json”);

xhr.onload = function() {
console.log("HTTP " + xhr.status);
};

xhr.onerror = function() {
console.log(“HTTP failed”);
};

xhr.send(JSON.stringify({
window_id: payload.WINDOW_ID,
label: payload.LABEL,
offset: payload.OFFSET,
chunk: payload.CHUNK
}));
});

I’m not very familiar with this topic yet, but as I understand it, the request to your endpoint runs on your phone. The watch doesn’t have Wi-Fi and is connected only via Bluetooth. So your phone needs to be able to reach the specified IP address. Have you checked this yet?

Test the connection by running the same cURL command from your phone. If that works, make sure your PKJS is actually running the code that sends the request.

Thanks guys! I can connect to that URL/IP from my iPhone and I have dev mode enabled in Pebble app too

@Flynn could you elaborate on this?

make sure your PKJS is actually running the code that sends the request

If the code that sends the request isn’t being run, then it won’t send the data. Add logs and make sure that the appMessage function is being run and isn’t failing silently halfway through.

Will try, thank you!