Networking Widget to Brainflow example?

DashBarkHussDashBarkHuss Chicago
edited September 30 in OpenBCI_GUI

The OpenBCI docs say to use the networking widget to send data to brainflow but doesn't go into details on how to do it. I also don't see anything in the brainflows docs.

Are there any examples of what params to pass to the BoardShim in order to properly network the openbci gui to brainflow?

I've tried a few different ways, but I'm really just guessing based on the limited docs.

from brainflow.board_shim import BoardShim, BrainFlowInputParams, BoardIds
import time
import json

def main():
    BoardShim.enable_dev_board_logger()

    params = BrainFlowInputParams()
    params.ip_port = 12345  # Make sure this matches the UDP port set in OpenBCI GUI
    params.ip_address = '127.0.0.1'  # Use localhost if GUI is on the same machine
    # params.ip_port = 6677
    # params.ip_address = '225.1.1.1'
    # params.mac_address = 'c3:60:56:3a:6c:d7'
    params.ip_protocol = 1
    params.timeout = 15  # Set a timeout for connection attempts
    # params.other_info = json.dumps({"use_udp_board_streaming": True})

    params.serial_port = '/dev/tty.usbmodem11'
    params.master_board = BoardIds.SYNTHETIC_BOARD

    # board = BoardShim(BoardIds.GANGLION_BOARD, params)
    board = BoardShim(BoardIds.STREAMING_BOARD, params)

Comments

  • wjcroftwjcroft Mount Shasta, CA
    edited October 1

    You can post Brainflow library questions on the Brainflow Slack. Sign up using the link below.

    https://brainflow.org/

    The Networking Widget OUTPUT formats are described in the docs below.

    https://docs.openbci.com/Software/OpenBCISoftware/GUIWidgets/#networking
    https://docs.google.com/document/d/e/2PACX-1vR_4DXPTh1nuiOwWKwIZN3NkGP3kRwpP4Hu6fQmy3jRAOaydOuEI1jket6V4V6PG4yIG15H1N7oFfdV/pub

    You may have misunderstood what the Networking Widget does. You can use it to stream OUT from the GUI in only these formats: LSL, OSC, UDP, Serial.

    If you want to write a Python program that receives the Ganglion data stream, use the examples shown in the Brainflow docs. One of these examples shows a realtime graphical stream plot. Which could take the place of the GUI Time Series monitoring.

    https://brainflow.readthedocs.io/en/stable/Examples.html#python-real-time-plot

  • I'm still unclear on when the Networking Widget is used.
    But I got the GUI to stream to python!
    I followed the instructions here on sending the GUI to an external process.
    And the Streaming Board brainflow docs

    The docs a re confusing because to me they imply you are supposed to use the networking widget to accomplish what I was trying to accomplish- to view the gui while also streaming data in you brainflow scripts.

    Furthermore, we recommend using the GUI's Networking Widget to stream data for proof-of-concept via UDP, LSL, OSC, or Serial. This allows you to visualize real-time and playback data in the GUI while modifying your application in a separate IDE.

    src
    It looks like the context is about using Brainflow. Maybe I'm misunderstanding this.

    GUI + Streaming example

    Video demo

    # To connect the OpenBCI GUI to the computer running this script
    # 1. System Control Panel -> Ganglion Live
    # 2. Select the following settings:
    # - Pick Transfer Protocol: BLED112 Dongle
    # - BLE Device: select your ganglion board
    # - Session Data: BDF+
    # - Brainflow Streamer: Network, ip address to 225.1.1.1, port to 6677
    # 3. Start Session 
    # 4. Start Data Stream
    # 5. Remove the filters if you want it to match the logs in this script
    # - Filters -> Click "All" to turn the channel icons black which means no filters are applied
    
    # In the terminal you'll see the samples ploted out in a vertical stream.
    
    from brainflow.board_shim import BoardShim, BrainFlowInputParams, BoardIds
    import time
    import numpy as np
    
    def get_most_recent_sample(board):
        data = board.get_current_board_data(10)
        eeg_channels = BoardShim.get_eeg_channels(board.get_board_id())
        first_channel = eeg_channels[0]
        return data[first_channel, -1]
    
    def create_horizontal_graph(value, width=50, min_value=-400, max_value=400):
        range_value = max_value - min_value
        position = int((value - min_value) / range_value * width)
        position = max(0, min(position, width - 1))  # Ensure position is within bounds
    
        graph = " " * position + "•" + " " * (width - position - 1)
        return graph
    
    def main():
        BoardShim.enable_dev_board_logger()
    
        params = BrainFlowInputParams()
        params.ip_port = 6677
        # params.ip_port_aux = 6678
        params.ip_address = "225.1.1.1"
        # params.ip_address_aux = "225.1.1.1"
        params.master_board = BoardIds.GANGLION_BOARD
    
    
        board = BoardShim(BoardIds.STREAMING_BOARD, params)
    
        try:
            print("Board session preparation")
            board.prepare_session()
            print("Board prepared session")
            board.start_stream()
              # Get information about the board
            sampling_rate = BoardShim.get_sampling_rate(BoardIds.GANGLION_BOARD)
            print(f"Sampling Rate: {sampling_rate}")
    
            eeg_channels = BoardShim.get_eeg_channels(BoardIds.GANGLION_BOARD)
            print(f"EEG Channels: {eeg_channels}")
    
            accel_channels = BoardShim.get_accel_channels(BoardIds.GANGLION_BOARD)
            print(f"Accelerometer Channels: {accel_channels}")
    
            timestamp_channel = BoardShim.get_timestamp_channel(BoardIds.GANGLION_BOARD)
            print(f"Timestamp Channel: {timestamp_channel}")
    
            time.sleep(1)  # Wait for the board to start streaming
            print("Board started streaming")
    
    
            # Get data for 10 seconds
            for _ in range(10000):
                data = board.get_current_board_data(10)
    
                # Get the EEG channels
                eeg_channels = BoardShim.get_eeg_channels(board.get_board_id())
    
                # The first EEG channel
                first_channel = eeg_channels[0]
    
                # Get the most recent sample from the first channel
                most_recent_sample = data[first_channel, -1]
    
                # print(f"Most recent sample from channel {first_channel}: {most_recent_sample}")
                sample = get_most_recent_sample(board)
                graph = create_horizontal_graph(sample)
                print(graph)
                # print Value
                # print(most_recent_sample) # if you want to see the value
    
                time.sleep(0.01)
    
        except Exception as e:
            print(f"Error occurred: {str(e)}")
    
        finally:
            if board.is_prepared():
                board.stop_stream()
                board.release_session()
    
    if __name__ == "__main__":
        main()
    
    
    
  • wjcroftwjcroft Mount Shasta, CA

    Great, glad you found that section. As you note, the 'GUI to External Process' feature is separate from and not connected to the services provided by the Networking Widget. Hope your application works. If the complexity is daunting, you can always drop back to just using the Brainflow sample programs and do whatever realtime signal plotting yourself. As in that 'Python real time plot' example.

Sign In or Register to comment.