• OK, some progress on the original Bangle.js. It very rarely works (maybe 1 in 30 times), but I have observed it working and successfully reading out data from the characteristic:

    NRF.connect("34:85:18:00:38:8e").then(function(gatt) {
      console.log(gatt);
      console.log("connected");
      var t = getTime();
      gatt.device.on('gattserverdisconnected', function(reason) {
        console.log("disconnected (" + reason + ") after " + (getTime()-t) + " secs");
      });
      return gatt.getPrimaryService("4fafc201-1fb5-459e-8fcc-c5c9c331914b");
    }).then(function(service) {
      console.log("got service: ");
      console.log(service);
      return service.getCharacteristic("beb5483e-36e1-4688-b7f5-ea07361b26a8");
    }).then(function(characteristic) {
      console.log("got characteristic, value = ");
      characteristic.readValue().then(function(v) { console.log(v); });
      characteristic.on('characteristicvaluechanged', function() {
        console.log("characteristicvaluechanged: ");
      characteristic.readValue().then(function(v) { console.log(v); });
      });
    }).catch(function(e) {
      console.log("error: " + e);
    });
    

    gives:

    BluetoothRemoteGATTServer: {
      "device": BluetoothDevice: {
        "id": "34:85:18:00:38:8e",
        "gatt":  ...
       },
      "connected": true }
    connected
    got service:
    BluetoothRemoteGATTService: {
      "uuid": "4fafc201-1fb5-459e-8fcc-c5c9c331914b",
      "isPrimary": true, "start_handle": 40, "end_handle": 65535 }
    got characteristic, value =
    DataView: {
      "buffer": new Uint8Array([4, 0, 0, 0]).buffer,
      "byteOffset": 0, "byteLength": 4 }
    

    However you'll notice that the "characteristicvaluechanged" callback is not firing. I left it running for several minutes and it didn't fire even once, so I think the "notify" response is not working. But this is progress, at least, and in the worst case I can probably read out the characteristic value on a timer, so there is light at the end of the tunnel!

    It would still be better if it worked on Bangle.js 2, and if it worked every time instead of only 1/30 times.

    (The MAC address is different because I'm using a different ESP32C3, but that's just an accident - it still doesn't work on the Bangle.js 2).

  • However you'll notice that the "characteristicvaluechanged" callback is not firing

    you're missing subscribing to notification step via startNotifications()
    see https://forum.espruino.com/comments/16752991/

    I found ESP32 Wroom-32 module and uploaded the very same sketch to it and from Bangle 2 it works almost fine. Like 9 out of 10 tries or even better. I've seen the same disconnect error but very very rarely - like 3 times out of many. Definitely never twice in a row.

About

Avatar for fanoush @fanoush started