• Do you know a smart way of selecting a BLE peripheral based on its HID service?

    Well, ideally you would do a NRF.requestDevice and scan for service 0x1812 which is the human interface device one. However Espruino sticks the services it supports in a scan response packet which is different to the normal advertising one.

    It means that when Espruino scans with a normal (non-active) scan it won't request the scan response so won't see the service.

    I've just added the option for an active scan though, so if you do:

    NRF.requestDevice({ active : true, filters: [{ services: ['1812'] }] }).then(function(device) { 
      print(device);
    });
    

    it should work fine.

    How can I tell my Pixl.js to send every received character to the LCD?

    You need to respond to notifications on the input report characteristic, map the key code to the character, and then either use Terminal.print or if you want access to the REPL itself you can do Terminal.inject.

    Responding to the input characteristic should be something like:

    var gatt;
    NRF.requestDevice({ .... }).then(function(device) {
      console.log("Found");
      return device.gatt.connect();
    }).then(function(g) {
      console.log("Connected");
      gatt = g;
      return gatt.getPrimaryService(0x1812);
    }).then(function(service) {
      return service.getCharacteristic(0x2A22);
    }).then(function(c) {
      c.on('characteristicvaluechanged', function(event) {
        console.log("-> "+event.target.value);
      });
      return c.startNotifications();
    }).then(function(d) {
      console.log("Waiting for notifications");
    }).catch(function() {
      console.log("Something's broken.");
    });
    

    However this doesn't work as-is... it looks like you have to do some initialisation work first (setting charactertistics for the type of HID device (boot/normal) and exiting suspend) which you'd need to do a bit of searching around for.

    When it's working this would make a great module though.

About

Avatar for Gordon @Gordon started