Uncaught Error: BLE HID not enabled

Posted on
  • I've been playing around with this for several weeks now, and I'm loving it!

    I'm just having one main problem: when I take the puck and walk out of range of the central device (my laptop), it auto-reconnects to the laptop's bluetooth when I get back into range but doesn't execute any of the commands I have written on button press. When I look at the console, it says

    Uncaught Error: BLE HID not enabled

    It's registering that it's connected, but doesn't allow me to do anything. I have to click "remove" on my computer's bluetooth menu, turn bluetooth off, then back on, then pair again through the Web IDE to get it to not get caught in the error.

    Any help understanding the error or fixing it would be great. (I've done extensive Googling to no avail.)


  • Hi,

    I'd have to see your code to be sure, but are you calling NRF.setServices anywhere other than where it'd used to enable Bluetooth HID mode?

    Basically, when you call NRF.setServices, HID will take effect after a disconnect and reconnect - before that time you'll get the BLE HID not enabled error.

    It works the other way too. If you were connected with HID enabled, then you uploaded code that didn't enable it, or that actually disabled it, the changes wouldn't take effect until you disconnected and reconnected - which might explain the problems you're having?

  • Here's the code:

    var controls = require("ble_hid_controls");
    NRF.setServices(undefined, { hid : controls.report });
    var tempTimer = 0;
    var timerID = null;
    console.log("Battery : "+Puck.getBatteryPercentage()+"%");
    var init_mag = Puck.mag();
    var cur_mag,last_mag,IntervalID,offset_ang,v­olumeChanged;
    function cal_ang(xyz){
      xyz.x -= init_mag.x;
      xyz.y -= init_mag.y;
      xyz.z -= init_mag.z;
      return (Math.atan2(xyz.y, xyz.x) * 180) / Math.PI;
    var cur_ang = cal_ang(Puck.mag());
    var last_ang = cur_ang;
    setWatch(function() {
    }, BTN, {edge:"rising", debounce:10, repeat:true});
    setWatch(function() {
      if(volumeChanged === null){
    }, BTN, {edge:"falling", debounce:10, repeat:true});
    function start_mag(){
      volumeChanged = null;
      IntervalID = setInterval(function () {
        cur_ang = cal_ang(Puck.mag());
        offset_ang = cur_ang - last_ang;
        if(Math.abs(offset_ang) > 3 && Math.abs(offset_ang) <45){
          if(offset_ang < 0){
            console.log(" - :" + offset_ang);
            console.log(" + :" + offset_ang);
          last_ang = cur_ang;
          volumeChanged = 5;
        }else if(Math.abs(offset_ang) > 45){
          last_ang = cur_ang;
      }, 500);
    function stop_mag(){
    function onBtnTap(){
      if(timerID !== null){
      timerID = setTimeout(function () {  
        if(tempTimer == 1){
        }else if(tempTimer == 2){
        }else if(tempTimer >= 3){
        tempTimer = 0;
        timerID = null;
      }, 500);
    function all_lights_off(){
    //process.on('uncaughtException', function() {
    //  digitalWrite(LED1,1);
    //  load();

    After looking at lots of examples, I thought it should be put at the top. But perhaps that's the wrong place.

    Here's the full error I'm getting now:

    >BLE Connected, queueing BLE restart for later
    Battery : 100%
    Uncaught Error: BLE HID not enabled
     at line 1 col 55
    in function "b" called from line 1 col 6
    in function "playpause" called from line 72 col 26
    in function called from system
  • It's this: >BLE Connected, queueing BLE restart for later

    As I said above, BLE HID support can't just be added on the fly. You need to disconnect and reconnect first before it will take effect.

  • I have the same problem (Uncaught Error: BLE HID not enabled) happening with both the keyboard and media key examples... could perhaps be some regression in recent firmware releases? I'll try now to give informations as detailed as i can.

    I tried to disconnect and reconnect as you suggest, but the error is still the same.
    I also tried to save the example on the puck flash and then reboot and reconnect, but to no avail.
    I tried on both firmware 1v94 and 1v95, as client os I tried withLlinux and Android but neither works.
    One thing that may or may not tell something, is that the puck seems to never advertise as a keyboard device, at least on both operating systems it always shows a generic bluetooth icon instead of a keyboard of some sort (while on a youtube tutorial was clearly listed as a keyboard on android https://www.youtube.com/watch?v=3iZ9j_ga­6zs&t=126s).

  • I just tried this again on one of the latest builds and it works fine with this code here: http://www.espruino.com/Puck.js+Music+Co­ntrol

    I just uploaded that code exactly as it was (no save or anything), disconnected, then reconnected with an Android phone's Bluetooth menu (which showed it as a keyboard device).

    Maybe you could try one of the latest builds here and see if it's any better? http://www.espruino.com/binaries/travis/­master/

  • I tried the latest build, but seems the keyboard module isn't present anymore:

    1v95.188 (c) 2017 G.Williams

    Uncaught Error: Module ble_hid_keyboard not found
    at line 1 col 36
    var kb = require("ble_hid_keyboard");


    Uncaught Error: Field or method "report" does not already exist, and can't create it on undefined
    at line 1 col 38
    NRF.setServices(undefined, { hid : kb.report });



  • It's probably because you just pasted the code into the left-hand side of the IDE?

  • Nope, right hand and then clicked upload

  • not sure what the issue was yesterday night, but now with firmware 1v95.188 all works like a charm, thanks :)

  • Odd... could have been a bad network connection I guess?

  • yeah, the last problem was likely to be that

  • I thought that "disconnect and reconnect" meant to disconnect the Espruino puck.js from its battery and then put the battery back in again, and/or to disconnect and reconnect it from the Espruino Web IDE.

    For anyone out there with the same issue as me, where I just kept seeing that error, just wanted to clarify that the replies above mean to turn on/off the bluetooth on your laptop/computer itself, not the Espruino Web IDE. On a Mac, this means toggling the bluetooth button on/off in the top right menu bar of the Mac, as you would if you were disconnecting and reconnecting your AirPods, for example.

    This resolved the issue for me!

    1 Attachment

    • Screenshot 2024-03-01 at 7.48.54 AM.png
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Uncaught Error: BLE HID not enabled

Posted by Avatar for BrianB @BrianB