var accel = Bangle.getAccel();
Bluetooth.println(JSON.stringify({acc:accel}));
When you get data, and then convert that back to a structure at the other end:
var j = JSON.parse(line);
console.log("RdData JSON: ",j.acc.x);
If you've got data coming at different rates that's not a big deal (with JS you won't end up with one Bluetooth.println 'interrupting' another one). All you need to do is have a way to figure out which data is which.
The way it's working right now, you're sending an object that looks like : {acc:{x,y,z}}
So you could tell if it's an accelerometer object by seeing if it has an acc member. So for example to handle buttons, on the Bangle.js:
var j = JSON.parse(line);
if ("acc" in j) console.log("RdData JSON: ",j.acc.x);
if ("btn1" in j) console.log("BTN1",j.btn1);
if ("btn2" in j) console.log("BTN2",j.btn2);
if ("btn3" in j) console.log("BTN3",j.btn3);
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
That's really cool! Thanks for posting it up!
For others looking, the code is at https://github.com/kristosb/WebBangle
Right now, you do:
When you get data, and then convert that back to a structure at the other end:
If you've got data coming at different rates that's not a big deal (with JS you won't end up with one
Bluetooth.println
'interrupting' another one). All you need to do is have a way to figure out which data is which.The way it's working right now, you're sending an object that looks like :
{acc:{x,y,z}}
So you could tell if it's an accelerometer object by seeing if it has an
acc
member. So for example to handle buttons, on the Bangle.js:And on the website:
Hope that helps!