clausbroch / node-red-contrib-noble-bluetooth

A Node-RED module based on noble for interaction with Bluetooth Low Energy (BLE) devices.
MIT License
8 stars 15 forks source link

BLEInNode creating new message and not sending device id #14

Open nahakiole opened 2 years ago

nahakiole commented 2 years ago

The BLEInNode doesn't send the device ID of the device that has sent the data, and also removes any messages that were sent to the node.

https://github.com/clausbroch/node-red-contrib-noble-bluetooth/blob/master/bluetooth.js#L300

https://github.com/clausbroch/node-red-contrib-noble-bluetooth/blob/master/bluetooth.js#L329

For my use case I needed to connect multiple Bluetooth devices and then depending on the device send the output to a different device. (Heart rate tracker to Philips Hue lights)

By modifying the above-mentioned lines to not create a new message and also attaching the device ID I can distinguish between devices and accomplish my goal.

characteristic.on('data', function(data, isNotification) {
                    msg.characteristic = characteristic.uuid;
                    msg.payload = data;
                    msg.peripheral =  peripheral.id;
                    node.send(msg);
                });
 characteristic.read(function(error, data) {
                    if (error) {
                       node.error("Error reading from characteristic: " + error);
                       return;
                    }
                    msg.characteristic = characteristic.uuid;
                    msg.payload = data;
                    msg.peripheral =  peripheral.id;
                    node.send(msg);
                });

So my question is if the current behavior is by design or could be modified as mentioned. If it were ok to modify it like above, I could create a pull request to change it.