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

    Thanks!

  • 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 });
    
    NRF.on('connect',()=>{
      digitalPulse(LED2,1,1000);
    });
    NRF.on('disconnect',()=>{
      digitalPulse(LED1,1,1000);
      NRF.connect();
      return;
    });
    
    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() {
       digitalWrite(LED3,1);
      start_mag();
    }, BTN, {edge:"rising", debounce:10, repeat:true});
    setWatch(function() {
      stop_mag();
      if(volumeChanged === null){
        onBtnTap();
      }
      all_lights_off();
    }, 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);
            controls.volumeDown();
          }else{
            console.log(" + :" + offset_ang);
            controls.volumeUp();
          }
          last_ang = cur_ang;
          volumeChanged = 5;
          all_lights_off();
          digitalWrite(LED2,1);
        }else if(Math.abs(offset_ang) > 45){
          last_ang = cur_ang;
        }
      }, 500);
    }
    function stop_mag(){
      clearInterval(IntervalID);
    }
    function onBtnTap(){
      if(timerID !== null){
        clearTimeout(timerID);
      }
      tempTimer+=1;
      timerID = setTimeout(function () {  
        if(tempTimer == 1){
          controls.playpause();
        }else if(tempTimer == 2){
          controls.next();
          console.log("next");
        }else if(tempTimer >= 3){
          controls.prev();
          console.log("prev");
        }
        tempTimer = 0;
        timerID = null;
                              
      }, 500);
    }
    function all_lights_off(){
       digitalWrite(LED1,0);
       digitalWrite(LED2,0);
       digitalWrite(LED3,0);
    }
    
    //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%
    =undefined
    Uncaught Error: BLE HID not enabled
     at line 1 col 55
    NRF.sendHIDReport(a,function(){NRF.sendH­IDReport(0,b)})
                                                          ^
    in function "b" called from line 1 col 6
    b(8,a)
         ^
    in function "playpause" called from line 72 col 26
          controls.playpause();
                             ^
    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.

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

Uncaught Error: BLE HID not enabled

Posted by Avatar for BrianB @BrianB

Actions