0

i'm trying to build a BLE scan module on nodeJs using Bluez here is the code i have been using:

exec('sudo hcitool lescan --duplicates &', function (error, stdout, stderr) { });

exec('sudo hcitool lescan --duplicates &', function (error, stdout, stderr) {
    var result = exec('sudo hcidump --raw &');

    /*
     * Whenever hcidump returns a  raw data, this function calls itself. And pushes 
     * the raw data to createBeaconDevice function.
     */
    result.stdout.on('data', function (data) {
        var currentDate = new Date();
        writeLog('scanData', data, currentDate.toISOString().replace(/T/, ' ').replace(/\..+/, ''))
        createBeaconDevice(data);
    });
});

But the problem is it stops working after a while without giving any warnings or errors. What could be the problem? Would be glad if anyone could help

ozata
  • 542
  • 1
  • 5
  • 16

1 Answers1

0

How does it stop working?

You could handle the error parameter like this

function (error, stdout, stderr) {
    if (error) throw new Error(error) // to get info
    ...
}

to get some info where things go south.

pspi
  • 11,189
  • 1
  • 20
  • 18
  • rest of the code keeps working, but scanning process just stops. – ozata Aug 11 '16 at 11:51
  • @ozata could you add the error param handling, just to be safe, and if it'd reveal anything we could help you better – pspi Aug 11 '16 at 11:52
  • The problem with that usage is you typed is i can not get async data that way while it is scanning – ozata Aug 11 '16 at 11:56
  • @ozata true that, how about console logging, and then maybe add similar error handling to the inner `exec()` call, too – pspi Aug 11 '16 at 12:00