• Level 1 issue:
    I have a Pixl.js that is meant to print on its LCD every character sent by a BLE peripheral behaving as a HID Keyboard (yes, that's a Puck.js running the example seen here ).
    Unfortunately I don't know which one of my Puck.js devices is the one acting as a HID Keyboard. I cannot filter by ID. I cannot filter by name because I want also to be able to connect to HID keyboards not built on top of Puck.js devices.
    Do you know a smart way of selecting a BLE peripheral based on its HID service?

    Level 2 issue:
    Once connected to a HID peripheral, how can I tell my Pixl.js to send every received character to the LCD? Is there any BLE Event on top of the HID service?

    Thank you!

  • 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.

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

How to make a Pixl.js connects only to a Peripheral device exposing a HID Keyboard profile?

Posted by Avatar for Jean-Philippe_Rey @Jean-Philippe_Rey

Actions