Multiple Sensors with Node
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).
MetaWear.discoverByAddress(address, function (device)}
or other commands
Hey have you been able to get this working?
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.
Ok I'll look into it over the holidays. Nice workaround!