Suggested method to sleep/wake Puck configured as HID

Posted on
  • I build a simple keyboard emulator for a scoring system using Puck.js. 5 Pucks are configured to send a different key code when clicked by the judge holding it, another one when double clicked.

    I am now trying to put the units to sleep after 15mins and wake them up and reconnect them again on the next key click - similar to my Logitech BT keyboard

    Putting to sleep seems to works, but I can't get the automatically reconnect working - I always have to go through the BT menu of the laptop.

    Any suggetsions are appreciated.

    Klaus

  • Hi Klaus,

    NRF.sleep and NRF.wake should work - however I'm not sure there is much you can do to force a reconnect if your PC isn't interested.

    What about NRF.setLowPowerConnection? That keeps the connection but will use drastically less power: http://www.espruino.com/Reference#l_NRF_­setLowPowerConnection

    Basically it just changes the polling interval from ~20ms to ~500ms - so keypresses will register more slowly but otherwise it's the same.

  • Thanks Gordon, that would be worth a try.

    I suspected it had something to do with HID over BLE and sleep and wake as I see my (classic) BT keyboard auto-connecting without a problem. Wondering what the difference is. Maybe a special type of service or advertismsnt is requireed for the PC to reconenct automatically?

  • So your Logitech Bluetooth Keyboard isn't a Bluetooth LE one, just classic Bluetooth?

    I'm sure I have seen BLE auto-connecting, but it might depend on the device. BLE draws so much less power than classic Bluetooth that it might be that many devices just don't bother with the reconnect, since very few BLE devices will ever voluntarily turn themselves off.

    It looks like it's possible to renegotiate the connection speed on the fly with BLE - so Puck.js should be able to automatically drop to a ~1 sec interval when connected, and to then speed itself up when there is data to transfer. That's not something that has been implemented yet though.

  • Looking at the docs, I was wondering, whether it is necessary to advertise HID as well?

    The example I followed only sets it as a service:

    NRF.setServices(undefined, { hid : kb.report });

    while the API docs say 'Note: Just creating a service doesn't mean that the service will be advertised. It will only be available after a device connects.'

  • Using hid for setServices does something special, and does actually advertise a service.

    In the API docs for setServices it also mentions you can do stuff like this:

    NRF.setServices(undefined, {
      hid : new Uint8Array(...), // optional, default is undefined. Enable BLE HID support
      uart : true, // optional, default is true. Enable BLE UART support
      advertise: [ '180D' ] // optional, list of service UUIDs to advertise
    });
    

    So you can specify services to advertise.

    It's all a bit confusing but with BLE you can advertise data (exposed by setAdvertising) as well as advertising services, which you can do with setServices.

  • Thanks for the clarification and confirmation that the HID service is advertised correctly when following the example.

    Will keep poking around...

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

Suggested method to sleep/wake Puck configured as HID

Posted by Avatar for krheinwald @krheinwald

Actions