Bangle multiple sensors readout

Posted on
  • Hi all,
    Just starting with espruino. I was working on some hobby project involving esp32, web app and bluetooth communication. In the meantime my pebble broke down and I looked for alternatives. Bought myself bangle and started messing around with espruino. Since then I order MDBT420Q module and moving my project to it. The learning curve is incomparable. Also I recently started learning JS anyway so it works out great.
    I have some watch apps developed but nothing worth sharing yet. Here is my first web bluetooth exercise project. I want to add all bangle sensors to the GUI. So far its only accelerometer. It took me one afternoon and I am just starting with JS so quality might be poor. I had to make a small edit to puck.js to add method.
    Since I am new to espruino and JS here is a question:
    I used low level event readout and set up interval on the bangle sending acc out.


    How would you set up readout for sensors that have different intervals plus sensors that just need the single readout on action?

  • That's really cool! Thanks for posting it up!

    For others looking, the code is at

    Right now, you do:

    var accel = Bangle.getAccel();

    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();
    // buttons
    setWatch(function(e) {
    }, BTN1, {repeat:true});
    setWatch(function(e) {
    }, BTN2, {repeat:true});
    setWatch(function(e) {
    }, 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!

  • Thats perfect. I will send an update when I cover all peripherals and finish the website. Maybe someone can leverage from it in any way. I think next step I will use it as a frame for a website with graphics from threeJS and maybe develop some simple game.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Bangle multiple sensors readout

Posted by Avatar for kri100s @kri100s