• Ahh, ok, thanks! So the CCCD Handle not found error is coming from Espruino via ble_uart.

    When a device provides a 'characteristic' that provides notifications when its value changes, it's supposed to have another characteristic linked to that one called a CCCD that allows you to switch those characteristics on or off.

    It would seem that the Bluefruit is providing the UART TX data characteristic, but somehow the CCCD that's supposed to be for it can't be found by Espruino.

    Without me having a Bluefruit here it might be a bit hard for me to track this down.

    However looking back, it seems that you didn't really want the two-way communication anyway? You just wanted to be able to send some data without disconnecting?

    In that case we can just modify the code from https://www.espruino.com/modules/ble_simple_uart.js slightly and include it in your folder directly:

    var device;
    const feather = "e8:76:9a:13:1a:32 random"; // Change me!
    
    function ble_uart_write(gatt, text) {
      return gatt.getPrimaryService("6e400001-b5a3-f393-e0a9-e50e24dcca9e"
      ).then(function(s) {
        return s.getCharacteristic("6e400002-b5a3-f393-e0a9-e50e24dcca9e");
      }).then(function(c) {
        function sender(resolve, reject) {
          if (text.length) {
            c.writeValue(text.substr(0,20)).then(function() {
              sender(resolve, reject);
            }).catch(reject);
            text = text.substr(20);
          } else  {
            resolve();
          }
        }
        return new Promise(sender);
      });
    }
    
    
    function sendMessage() {
      var promise = (device&&device.gatt.connected) ? Promise.resolve(device.gatt) :
         NRF.requestDevice({ filters: [{ id: feather }] }).then(function(d) {
          device = d;
          console.log("Trying to Connect");
          return device.gatt.connect();
         });
      promise.then(function(gatt) {
        console.log("Sending message");
        return ble_uart_write(gatt, "LED.toggle();\n"); // Change me!
      }).then(function() {
        console.log("Message sent successfully.");  
      });
    }
    

    Just tried this - not on a feather though, and it works well for me - and automatically reconnects if there's no connection

About

Avatar for Gordon @Gordon started