• Hello, i have a problem with the command line Espruino and noble in my node.js server.
    When i want to disconnect et reconnect my device, it often stuck in 'connecting' status.
    I'm working with a Raspberry Pi 3 B+ with Raspbian Stretch OS.

    my HCIDUMP when i connect device with some code sent to puck.js :

    HCI sniffer - Bluetooth packet analyzer ver 5.43
    device: hci0 snap_len: 1500 filter: 0xffffffff
    > HCI Event: Command Status (0x0f) plen 4
        Disconnect (0x01|0x0006) status 0x00 ncmd 1
    > HCI Event: Disconn Complete (0x05) plen 4
        status 0x00 handle 64 reason 0x16
        Reason: Connection Terminated by Local Host
    > HCI Event: Command Complete (0x0e) plen 4
        LE Set Scan Enable (0x08|0x000c) ncmd 1
        status 0x0c
        Error: Command Disallowed
    > HCI Event: Command Complete (0x0e) plen 4
        Set Event Mask (0x03|0x0001) ncmd 1
        status 0x00
    > HCI Event: Command Complete (0x0e) plen 4
        LE Set Event Mask (0x08|0x0001) ncmd 1
        status 0x00
    > HCI Event: Command Complete (0x0e) plen 12
        Read Local Version Information (0x04|0x0001) ncmd 1
        status 0x00
        HCI Version: 4.1 (0x7) HCI Revision: 0x8b
        LMP Version: 4.1 (0x7) LMP Subversion: 0x6119
        Manufacturer: Broadcom Corporation (15)
    > HCI Event: Command Complete (0x0e) plen 4
        Write LE Host Supported (0x03|0x006d) ncmd 1
    > HCI Event: Command Complete (0x0e) plen 6
        Read LE Host Supported (0x03|0x006c) ncmd 1
    > HCI Event: Command Complete (0x0e) plen 10
        Read BD ADDR (0x04|0x0009) ncmd 1
        status 0x00 bdaddr B8:27:EB:DC:0C:65
    > HCI Event: Command Complete (0x0e) plen 4
        LE Set Scan Enable (0x08|0x000c) ncmd 1
        status 0x0c
        Error: Command Disallowed
    > HCI Event: Command Complete (0x0e) plen 4
        LE Set Scan Parameters (0x08|0x000b) ncmd 1
        status 0x00
    > HCI Event: Command Complete (0x0e) plen 4
        LE Set Scan Enable (0x08|0x000c) ncmd 1
        status 0x0c
        Error: Command Disallowed
    > HCI Event: Command Complete (0x0e) plen 4
        LE Set Scan Parameters (0x08|0x000b) ncmd 1
        status 0x00
    > HCI Event: Command Complete (0x0e) plen 4
        LE Set Scan Enable (0x08|0x000c) ncmd 1
        status 0x00
    > HCI Event: Command Complete (0x0e) plen 4
        LE Set Scan Enable (0x08|0x000c) ncmd 1
        status 0x00
    > HCI Event: Command Status (0x0f) plen 4
        LE Create Connection (0x08|0x000d) status 0x00 ncmd 1
    > HCI Event: Command Status (0x0f) plen 4
        LE Read Remote Used Features (0x08|0x0016) status 0x00 ncmd 1
    > HCI Event: Command Complete (0x0e) plen 14
        LE Read Remote Used Features (0x08|0x0016) ncmd 1
    

    then when i want to disconnect and reconnect with another code

    > HCI Event: Command Status (0x0f) plen 4
        Disconnect (0x01|0x0006) status 0x00 ncmd 1
    > HCI Event: Disconn Complete (0x05) plen 4
        status 0x00 handle 64 reason 0x16
        Reason: Connection Terminated by Local Host
    > HCI Event: Command Complete (0x0e) plen 4
        LE Set Scan Enable (0x08|0x000c) ncmd 1
        status 0x0c
        Error: Command Disallowed
    > HCI Event: Command Complete (0x0e) plen 4
        LE Set Scan Enable (0x08|0x000c) ncmd 1
        status 0x0c
        Error: Command Disallowed
    > HCI Event: Command Complete (0x0e) plen 4
        Set Event Mask (0x03|0x0001) ncmd 1
        status 0x00
    > HCI Event: Command Complete (0x0e) plen 4
        LE Set Event Mask (0x08|0x0001) ncmd 1
        status 0x00
    > HCI Event: Command Complete (0x0e) plen 12
        Read Local Version Information (0x04|0x0001) ncmd 1
        status 0x00
        HCI Version: 4.1 (0x7) HCI Revision: 0x8b
        LMP Version: 4.1 (0x7) LMP Subversion: 0x6119
        Manufacturer: Broadcom Corporation (15)
    > HCI Event: Command Complete (0x0e) plen 4
        Write LE Host Supported (0x03|0x006d) ncmd 1
    > HCI Event: Command Complete (0x0e) plen 6
        Read LE Host Supported (0x03|0x006c) ncmd 1
    > HCI Event: Command Complete (0x0e) plen 10
        Read BD ADDR (0x04|0x0009) ncmd 1
        status 0x00 bdaddr B8:27:EB:DC:0C:65
    > HCI Event: Command Complete (0x0e) plen 4
        LE Set Scan Enable (0x08|0x000c) ncmd 1
        status 0x0c
        Error: Command Disallowed
    > HCI Event: Command Complete (0x0e) plen 4
        LE Set Scan Parameters (0x08|0x000b) ncmd 1
        status 0x00
    > HCI Event: Command Complete (0x0e) plen 4
        LE Set Scan Enable (0x08|0x000c) ncmd 1
        status 0x0c
        Error: Command Disallowed
    > 
    

    the Espruino command line tool STDERR :
    noble warning: unknown handle 64 disconnected!
    Port "c6:93:50:de:bc:bd" not found
    Unable to connect!

    It seems like puck.js stay connected with my bluetooth controler after a simple espruino command
    "espruino -t -p c6:93:50:de:bc:bd -e 'LED3.set();'"

    Thanks !

  • Is the OS properly up to date?

    What happens if you wait for a few seconds? I think sometimes the Bluetooth stack can take a while to register a disconnection properly.

  • Actually I may have misunderstood - so you're trying to connect using your own code in Node.js, and are having trouble getting it to disconnect?

    Could you share a simple bit of code where it happens for you?

  • Yes the OS ( raspbian Stretch ) is up to date, i use the noble module to scan the puck when the button is clicked , the code :

     // get the mac address of new puckJS - we use noble.js to scan BLE device whose peripheral name is Puck.js then get the mac address and store it
    
            function onDiscovery(peripheral) {
                    if (peripheral.advertisement.localName == undefined || peripheral.address == 'unknown') {
                            return;
                    }
                    if (peripheral.advertisement.localName.incl­udes("Puck.js")) {
                            if (peripheral.address == puckJSdevice) {
                                   
                                    if (!peripheral.advertisement.manufacturerD­ata ||
                                            peripheral.advertisement.manufacturerDat­a[0] != 0x90 ||
                                            peripheral.advertisement.manufacturerDat­a[1] != 0x05) return;
                                  
                                    var data = peripheral.advertisement.manufacturerDat­a.slice(2);
    
                                    //console.log(data);
                                    if (lastAdvertising[peripheral.address] == undefined) {
                                            lastAdvertising[peripheral.address] = data.toString();
                                    }
                                    // check for changed services
                                    if (lastAdvertising[peripheral.address] != data.toString()) {
                                            console.log(lastAdvertising[peripheral.a­ddress], data.toString());
                                            puckClicked.onDeviceChanged(peripheral.a­ddress, data);
                                    } else {
                                            currentNumberClicked = data.readInt8(); justOnePass = 0;
                                    }
                                    lastAdvertising[peripheral.address] = data;
                            }
                            if (puckJSnoble) {
                                    return;
                            }
                            puckJSnoble = peripheral;
                            if (puckJSdevice) {
                                    return;
                            } else {
                                    console.log("passage config puck");
                                    puckJSdevice = peripheral.address;
                                    //save the new PuckJS button mac address in the database in tv_config.puckjs
                                    request(serverFamily + '/1.0/tvs/addPuckJSConfig/' + process.env._MAC + '?puckjs=' + puckJSdevice, function (error, res) {
                                            console.log(error || res.message, 'puck button saved');
                                    });
     resetScriptPuck();
    

    Then when the clicked button event is triggered i use this code to light the LED ( with espruino ) :

     // send command to puck - light the LED
    exec('espruino -t -p ' + puckJSdevice + ' -e "LED2.set();"',function(error,stdout,std­err){
                                            console.log("ESPRUINO LIGHT THE LED error : ", error, "stdout : ", stdout, "stderr : ",stderr);
                                    });
    
    

    On node.js server start i reset and upload this code to puck :

    var presses = 0;
    
    setWatch(function() {                                                          
     if(presses > 100){presses=0} 
     presses++;
     LED2.reset();
     LED3.reset();
      NRF.setAdvertising({},{manufacturer: 0x0590, manufacturerData:[presses]});   
    }, BTN, {edge:"rising", repeat:1, debounce:50})
    

    Sometimes it cannot light the led and i have this message : unable to connect "MAC ADDRESS"
    or it stop to emit DATA from BLE ( because it still connected to my raspberry controller after the LED is turned on ).
    Would it be a solution to force remove the connected puck with "bluetoothctl" before sending the expression with espruino to avoid this? or just waiting a few seconds before trying to connect ?

    Thanks !

  • Ok - so you call into the espruino CLI to send data to Espruino?

    I imagine that would cause some problems as you have two separate processes trying to use the BLE device? Could you not use the same espruino package from Node.js itself? See https://github.com/espruino/EspruinoTool­s#npm-module

    You may also have to explicitly call noble.startScanning() again after you complete the connection as well...

  • OK thank you i'll try it !

  • I have tried with the npm module but i have the same problem. When i want to send an expression after uploading a JS script .. i have "Una"

  • ** i have "Unable to connect"
    Thank you

  • could it be a battery problem ? now i have " Error Getting services/characteristics " when i send a expression with module "espruino.expr(puckJSdevice, 'LED2.set()',function(){ noble.StartScanning([],true); }).

    Thank you.

  • You could try with a fresh battery just in case . You could also try /etc/init.d/bluetooth restart just in case the OS has got itself confused.

    Have to stopped scanning before calling espruino.expr? I guess that might help.

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

Unable to connect Puck.js - problem with noble after disconnect

Posted by Avatar for Christof550 @Christof550

Actions