Possible bug with node.status method

I change node.status based on the emitted event as seen below:

const STOPSCAN = () => {
node.status( { fill: "red", shape: "dot", text: "Scan stopped." } );
node.log("ding ding")
};
noble.on('scanStop', STOPSCAN);

I am sure the event is emitted as I see "ding ding" in log, but the status of my node is staying same.
What might be the reason?

Try refreshing your browser.

Also, try a non arrow function.

Sadly none of them worked.

One lead might be that the event is emitted via another node. But, why should it matter, because 100%, the event is emitted as I confirm via log.

Is your repo public? Can you show me it?

What version of node-red are you using?

Have you tried other browser?

Is the node object in scope the one you are addressing (use temp flags & console.log or use debugger statement to halt inside STOPSCAN - inspect the node object, are you certain it is the one you think it is?

Lastly, try changing the text for the status (and the fill etc)

Hi @Steve-Mcl,

Yes it is public: GitHub - hkayann/node-red-contrib-ble-sense: Node-RED module for Bluetooth Low Energy (BLE) devices.

Node-RED version: v2.2.2

Yes, I am sure that it is that node object.

Another browser, and changing the status properties did not work either.

Maybe something is wrong with my code.

Out of pure interest, would you try changing all your arrow functions like this...


        function STARTSCAN () {
            console.log("scanStart", node, node.status);
            node.status( { fill: "green", shape: "ring", text: "Scanning." } )
        };
        function STOPSCAN () {
            console.log("scanStop", node, node.status);
            node.status( { fill: "red", shape: "dot", text: "Scan stopped." } );
        };

        noble.on('scanStop', function() {
            STOPSCAN();
        });
        noble.on('scanStart', function() {
            STARTSCAN();
        });

Restart node-red and browser & inspect the console for scanStart & scanStop messages. Expand the node props & inspect those.

The error persists. Here is the log:

scanStop BLEScanner {
  id: '9e287b57697e5114',
  type: 'BLE Scanner',
  z: 'e7ac228a8e11425a',
  g: undefined,
  _closeCallbacks: [],
  _inputCallback: [Function: INPUT],
  _inputCallbacks: null,
  name: 'BLE Scanner',
  wires: [ [ '27f5a4ee05adccbf' ] ],
  _wireCount: 1,
  send: [Function (anonymous)],
  _wire: '27f5a4ee05adccbf',
  searchFor: 'Feath',
  output: 'Peripheral'
} [Function (anonymous)]
scanStart BLEScanner {
  id: '9e287b57697e5114',
  type: 'BLE Scanner',
  z: 'e7ac228a8e11425a',
  g: undefined,
  _closeCallbacks: [],
  _inputCallback: [Function: INPUT],
  _inputCallbacks: null,
  name: 'BLE Scanner',
  wires: [ [ '27f5a4ee05adccbf' ] ],
  _wireCount: 1,
  send: [Function (anonymous)],
  _wire: '27f5a4ee05adccbf',
  searchFor: 'Feath',
  output: 'Peripheral'
}

I think we have another lead. For some reason, after the following line, It seems like scanStart event is emitted.

await noble.stopScanningAsync().catch(e => send(e));

I am pretty sure the Bluetooth adapter stops scanning as Bluetooth debugger shows no event. So, I feel like this might be bug of @abandonware/noble.

You have promises and async await syntax intermixed there.

surely that should be either

noble.stopScanningAsync()
 .then(e => {send(e);})
 .catch(err => {done(err)})

or

try {
  var e = await noble.stopScanningAsync()
  send(e)
} catch(err) {
  done(err)
}

Thank you. I fixed them all but sadly the error still persists. For some reason scanStart event is emitted even though the adapter is not scanning.

Sorry, I'm a bit lost off now.

What error?

Is the status update now working?

Can you clarify with a bit more details please?

Hi @Steve-Mcl,

The status update is working. The problem seems like with the @abandonware/noble package.

Here is my example setup.
setupNodeRED
After BLE device is connected, I expect BLE Scanner status to show Scan stopped.

function STOPSCAN () {
  console.log("scanStop", node, node.status);
  node.status( { fill: "red", shape: "dot", text: "Scan stopped." } );
};
noble.on('scanStop', function() {
  STOPSCAN();
});

But for some reason, the scanStart event is emitted as I can see it on log even though the adapter is not scanning.

Hence the status shows Scanning. I opened an issue on their GitHub as well.

ok, so we can safely say, the title "Possible bug with node.status" is now proven to be false yeah?

I guess you will have to wait for feedback on the noble package or start digging into it yourself.

Yes exactly. Thanks for the help.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.