Multiple Sensors with Node
Hello there,
I had originally tried to code with python and after roughly 8 months I found that the python's Bluetooth library is just not stable at all and not applicable for my purposes (most sensors disconnect when I move 1 meter away from the reciever...even with full power and highest configuration). So, after searching through the forums and based on Laura's comments, I decided to transfer all of my code to javascript. So I have finished transferring most of my code to javascript but I am currently stuck in one problem.
Now as I have mentioned before in my previous posts that I have 7-8 MMC sensors and 4 dongles (3 usb and 1 internal) so I need a way to set which hci device will connect to which dongle within the code. From the node documentation and tutorials, one would usually specify the hci with an envirnment variable before running the code:
NOBLE_HCI_DEVICE_ID = 0
but that is outside the code and when you actually run the code from terminal. That is only applicable if you would want to connect to 1 sensor. However, that is not applicable if you want to use multiple dongles and multiple sensors for each. Especially because my code has multiple has multiple functions that don't always run at the same time.
Running the same code multiple times with specifying hci devices and senors as arguments to the code is not practical especially in my case where I have a set number of sensors that I only want to connect to and integrate into a whole application infrastructure. Please, I know that one can set the environment in the same command line that runs the code but that is NOT applicable for my application. I need it to be set inside the code not outside.
I have tried to use:
process.env['NOBLE_HCI_DEVICE_ID'] = 1;
which was suggested here but even though the system says that it has changed when I read the same variable afterwards it doesn't actually use the new set hci device as the device that it will use thereafter. It keeps on using the original hci device that it started with when the code was ran with. I have confirmed this finding by setting the environment variable to 1 (hci1) within code and only having hci0 (in other words there shouldn't be any hci1) and it still connects to the sensors and collects data (which means it is still using hci0).
So my specific and direct question is "How to set the hci device inside my javascript code so that I can change which Bluetooth dongle connect to which sensor when I run for example:
MetaWear.discoverByAddress(address, function (device)}
or other commands
Comments
Hey have you been able to get this working?
Hello there,
So, i didn't find a way to set the hci device correctly within the code. So my solution was to create a bash script that runs 8 different threads (because I have 8 sensors) and set the specific hci device (with NOBLE_HCI_DEVICE_ID = 0) when I run each thread.
Though a way to set the hci within the javascript environment would be much better for me if you do know a way to do so. But in my part, I haven't figured it out yet.
Ok I'll look into it over the holidays. Nice workaround!