Connecting Ganglion Over Bluetooth Using Node.js

edited July 2020 in Ganglion

Hi there, I am very new to openBCI and I'm struggling with figuring out how to stream data from my ganglion using node.js. I'm trying to follow this tutorial: https://github.com/openbci-archive/OpenBCI_NodeJS_Ganglion however, I can't even connect to my board. The line: ganglion.once("ganglionFound", peripheral => {
doesn't seem to be finding my board because the blue light keeps blinking and nothing prints to the terminal. I am using the bluetooth usb adapter from the openBCI store on a Windows computer. When I try to connect to my board using the OpenBCI GUI, it connects just fine and the blue light stops blinking. Therefore, I don't know I am unable to connect when I try to use Node.js. Any advice would be appreciated, thank you.

Comments

  • Update: I did some debugging and now I think I'm a step closer, but now I'm getting the message "No compatible USB Bluetooth 4.0 device found!". In my device manager, Bluegiga Bluetooth Low Energy (COM3) is listed under "Ports" instead of "Bluetooth", could this be the issue or is that correct?

  • wjcroftwjcroft Mount Shasta, CA

    Ayau, hi.

    Notice that the OpenBCI_NodeJS_Ganglion repository is now classified as 'deprecated', and moved to the 'openbci-archive' folder. That repo was originally developed for the previous Bluetooth connection scheme. Which primarily used a 'CSR' Bluetooth dongle. With complicated configuration involving a 'Zadig' program.

    All new Ganglion connections are over a serial port with the BLED112 dongle.

    On Mac computers the NodeJS was able to connect with the native Bluetooth hardware / driver in macOS. However on Windows I'm pretty sure all work was done with the CSR dongle. It's remotely possible that you could get it to work with such a dongle. But may also depend on Zadig settings.

    https://www.google.com/search?as_q=nodejs+csr&as_sitesearch=openbci.com

    Are you aware of the Brainflow libraries and languages supported?

    https://brainflow.readthedocs.io/en/stable/

    A wide variety of languages are supported, but not NodeJS. This is because Brainflow at it's core, uses a C++ low layer.

    Regards, William

  • wjcroftwjcroft Mount Shasta, CA
  • wjcroftwjcroft Mount Shasta, CA

    Here is a long shot.

    While the OpenBCI_NodeJS_Ganglion repository was designed for the old CSR dongle, the OpenBCI_Hub (now obsolete) Ganglion code was designed for the current BLED112 dongle. So may be possible to transplant parts of the dongle code from Hub.

    https://github.com/openbci-archive/OpenBCI_Hub

    Ganglion code is primarily in this file:

    https://github.com/openbci-archive/OpenBCI_Hub/blob/master/src/background.js

    See sections with names containing 'BLE'.

  • retiututretiutut Louisiana, USA
    edited July 2020

    Hey @ayau3,

    This deprecation occurred in the last few months, as we are now using BrainFlow for back-end data acquisition. It's possible for anyone to begin working on a Javascript binding for BrainFlow, and the software team has discussed exploring this option.

    Since you are trying Windows(10?)+BLED112 dongle, you really should be able to connect using https://github.com/openbci-archive/OpenBCI_NodeJS_Ganglion. This was used in the last build of the Hub (2.1.0 w/ GUI 4.2.0), which worked for the most part for all boards. Though, all of the deprecations of dependencies and issues updating them made it a bit scary to try and build the Hub, even though no real changes were being made.

    Also, make sure you specify the correct COM port of the BLED112 dongle.

    Take Care,
    -RW

  • wjcroftwjcroft Mount Shasta, CA

    I see now that OpenBCI_NodeJS does indeed contain BLED112 ability. But all the user code examples in the README.md, neglects to mention how a BLED112 dongle is initialized. Examples are geared to the CSR dongle, which used the 'NoBLE' interface.

    How / where is the COM port set?

  • wjcroftwjcroft Mount Shasta, CA
    edited July 2020

    Apparently InitializationObject.bled112 should be set true. And .nobleAutoStart false.

    But that still leaves the question, where is the COM port set?

  • wjcroftwjcroft Mount Shasta, CA

    Question on the history and lineage of OpenBCI_NodeJS and OpenBCI_Hub. NodeJS came first, way before BLED112 was being used. Then BLED112 was added, first to NodeJS, and Hub was always kept in sync with NodeJS? So there are no tweeks or changes made in Hub that were not back ported to NodeJS?

    Or was Hub always built by first importing some source files from NodeJS? So always in sync? Sound like it would have been quite a pain to manage all of this, source control wise.

    So glad that Brainflow and the new GUI architecture evolved to replace the old scheme.

    Above Richard stated:

    It's possible for anyone to begin working on a Javascript binding for BrainFlow, and the software team has discussed exploring this option.

    But can Javascript running in a webpage, invoke the low layers of Brainflow, written in C++? Or are you suggesting such Node.js programs are based strictly in local filesystems? I assume Javascript can do the latter and somehow invoke libraries written in other languages.

  • wjcroftwjcroft Mount Shasta, CA

    https://www.google.com/search?q=can+javascript+invoke+c+++library

    So definitely possible. Though the pages reference in this search differ widely on details. There is something called WebAssembly that might be a portable solution. Radio packets are not that compute intensive, so likely low overhead.

    https://www.google.com/search?q=webassembly

  • retiututretiutut Louisiana, USA

    But can Javascript running in a webpage, invoke the low layers of Brainflow, written in C++? Or are you suggesting such Node.js programs are based strictly in local filesystems? I assume Javascript can do the latter and somehow invoke libraries written in other languages.

    Great questions. Might end up being strictly NodeJS.

  • retiututretiutut Louisiana, USA
    edited July 2020

    My first choice of doing OpenBCI+NodeJs is using Ganglion+WiFi, since this may end up working on mobile devices using a React Native app.

    Next, it would be great to add OpenBCI hardware to something like this (which has an MIT license). :smile: https://github.com/kylemath/EEGEdu
    https://eegedu.com

  • wjcroftwjcroft Mount Shasta, CA

    Richard, can you answer the above comment I left, regarding how to tell OpenBCI_NodeJS to (1) use BLED112 vs default NoBLE, (2) specify com port. An example of this must be in the Hub code. But was omitted from NodeJS doc.

  • @wjcroft and @retiutut, thank you both for all of your help, I greatly appreciate it! Given all the challenges you both posed, I think I will try out brainflow instead. Silly question, but how do you set the length of recordings in brainflow? I've been reading through the python API and I can't seem to figure it out.

  • Andrey1994Andrey1994 Moscow
    edited July 2020

    there is a ring buffer to store data, if this buffer gets more elements than specified size old values will be replaced by new values. Method get_board_data returns and removes data from this buffer. Size of this buffer can be specified using first argument in start_stream method.

  • @Andrey1994 Thank you for the quick reply! Sorry I'm very new to this and I'm unfamiliar with ring buffers, if I want to record 2 seconds of data, what should I set for the ring buffer size?

  • @ayau3 Take a look at the python example in the brainflow docs: https://brainflow.readthedocs.io/en/stable/Examples.html#python

    This example streams for 10 seconds (time.sleep (10)) and prints all the data collected in that time. You should be able to work this example into what you want.

    As andrey said, calling board.get_board_data () will returns all the data collected (and clears the internal buffer), while board.get_current_board_data() allows you to specify the last "x" amount of samples you want returned (and will not clear the internal buffer)

  • wjcroftwjcroft Mount Shasta, CA

    if I want to record 2 seconds of data, what should I set for the ring buffer size?

    Ganglion default sample rate is 200 Hz. 200 samples per second. 400 samples in 2 seconds. Any buffer you create should be somewhat larger to account for buffering delays, etc. And since RAM memory is so abundant, you could make it basically as large as you want.

  • Andrey1994Andrey1994 Moscow
    edited July 2020

    there is default value which is equal to 450000 its more than enough... and as William mentioned you can write smth like that

    num_samples = BoardShim.get_sampling_rate(BoardIds.GANGLION_BOARD.value)  * expected_time
    
  • I was also hoping to use NodeJS with my Ganglion. Has anyone tried to add BrainFlow as a native c++ module, to a nodejs app?

Sign In or Register to comment.