You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • 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:

    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:

    // accelerometer handler
    ...{ 
      var accel = Bangle.getAccel();
      Bluetooth.println(JSON.stringify({acc:accel}));
    }...
    // buttons
    setWatch(function(e) {
      Bluetooth.println(JSON.stringify({btn1:e.state}));
    }, BTN1, {repeat:true});
    setWatch(function(e) {
      Bluetooth.println(JSON.stringify({btn2:e.state}));
    }, BTN2, {repeat:true});
    setWatch(function(e) {
      Bluetooth.println(JSON.stringify({btn3:e.state}));
    }, BTN3, {repeat:true});
    

    And on the website:

        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);
    

    Hope that helps!

About

Avatar for Gordon @Gordon started