• There is the need for a additional try catch to handle Uncaught Error: BLE task DISCONNECT is already in progress

    bleSendJS = function(_id, _cmd) {
        console.log('s');
        try {
            NRF.requestDevice({ timeout: 5E3, filters: [{ id: _id }] }).then(function(device) {
                console.log('f');
                console.log(device);
                return require("ble_uart").connect(device);
            }).then(function(uart) {
                console.log('c');
                var data;
                uart.on('data', function(d) {
                    data += d;
                });
                uart.write(`\x03\x10(${_cmd})\n`).then(f­unction() {
                    setTimeout(function() {
                        uart.disconnect();
                        console.log('output:', data);
                        console.log("Disconnected");
                    }, 2000);
                }).catch(function() {
                    console.log("Promise Rejected - disconnect");
                    uart.diconnect();
                });
            }).catch(function(e) {
                console.log("ERROR:", e);
            });
        } catch (e) {
            console.log("ERROR:", e);
        }
    };
    
  • Sat 2021.09.25

    Without writing any code or testing on my part;

    I originally thought the try/catch would have to wrap/start at L14 as the user forced disconnect is within the setInterval(). So is that the promise reponse isn't really attached to any code as it responds, that the catch wrapper had to be around the entire code block as you have shown perhaps?

    In any event, thank you for the snippet @MaBe as this will come in handy down the road. . . .

About

Avatar for Robin @Robin started