Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for multiple emotibits #749

Merged
merged 1 commit into from
Nov 24, 2024
Merged

Adding support for multiple emotibits #749

merged 1 commit into from
Nov 24, 2024

Conversation

Andrey1994
Copy link
Member

No description provided.

@Andrey1994
Copy link
Member Author

Andrey1994 commented Nov 23, 2024

It should support multiple emotibits now, but I am having a connection issue on the second one. It seems like second emotibit doesnt connect to tcp server control socket and I dont get why.

D:\workspace\brainflow>python python_package\examples\tests\two_emotibits.py --id1 MD-V5-0000063 --id2 MD-V5-0000543
[2, 1, 0]
[2024-11-23 02:34:28.988] [board_logger] [info] incoming json: {
    "file": "",
    "file_anc": "",
    "file_aux": "",
    "ip_address": "",
    "ip_address_anc": "",
    "ip_address_aux": "",
    "ip_port": 0,
    "ip_port_anc": 0,
    "ip_port_aux": 0,
    "ip_protocol": 0,
    "mac_address": "",
    "master_board": -100,
    "other_info": "",
    "serial_number": "MD-V5-0000063",
    "serial_port": "",
    "timeout": 0
}
[2024-11-23 02:34:28.988] [board_logger] [trace] Board object created 47
[2024-11-23 02:34:28.988] [board_logger] [warning] no ip_address provided, trying to discover network, it may take longer
[2024-11-23 02:34:28.996] [board_logger] [info] trying broadcast address: 127.255.255.255
[2024-11-23 02:34:28.996] [board_logger] [info] sending package: 0,0,0,HE,1,100

[2024-11-23 02:34:34.002] [board_logger] [error] no emotibit found
[2024-11-23 02:34:34.002] [board_logger] [info] trying broadcast address: 192.168.10.255
[2024-11-23 02:34:34.002] [board_logger] [info] sending package: 0,0,0,HE,1,100

[2024-11-23 02:34:34.964] [board_logger] [trace] package is 1594496,66,0,HH,1,100,DP,-1,DI,MD-V5-0000063
[2024-11-23 02:34:34.964] [board_logger] [info] received HH package
[2024-11-23 02:34:34.965] [board_logger] [info] Found emotibit: MD-V5-0000063
[2024-11-23 02:34:34.965] [board_logger] [info] use port 3133 for data
[2024-11-23 02:34:34.965] [board_logger] [info] local ip addr is 192.168.10.115
[2024-11-23 02:34:34.965] [board_logger] [info] use port 3132 for control
[2024-11-23 02:34:34.965] [board_logger] [info] sending connect package: 0,0,4,EC,1,100,CP,3132,DP,3133

[2024-11-23 02:34:34.965] [board_logger] [trace] waiting for accept 0/20
[2024-11-23 02:34:35.277] [board_logger] [trace] waiting for accept 1/20
[2024-11-23 02:34:35.589] [board_logger] [trace] waiting for accept 2/20
[2024-11-23 02:34:35.898] [board_logger] [trace] waiting for accept 3/20
[2024-11-23 02:34:36.210] [board_logger] [trace] waiting for accept 4/20
[2024-11-23 02:34:36.210] [board_logger] [trace] emotibit connected
[2024-11-23 02:34:36.210] [board_logger] [info] Message: ML sent
[2024-11-23 02:34:36.210] [board_logger] [info] incoming json: {
    "file": "",
    "file_anc": "",
    "file_aux": "",
    "ip_address": "",
    "ip_address_anc": "",
    "ip_address_aux": "",
    "ip_port": 0,
    "ip_port_anc": 0,
    "ip_port_aux": 0,
    "ip_protocol": 0,
    "mac_address": "",
    "master_board": -100,
    "other_info": "",
    "serial_number": "MD-V5-0000543",
    "serial_port": "",
    "timeout": 0
}
[2024-11-23 02:34:36.210] [board_logger] [trace] Board object created 47
[2024-11-23 02:34:36.211] [board_logger] [warning] no ip_address provided, trying to discover network, it may take longer
[2024-11-23 02:34:36.215] [board_logger] [info] trying broadcast address: 127.255.255.255
[2024-11-23 02:34:36.215] [board_logger] [info] sending package: 0,0,0,HE,1,100

[2024-11-23 02:34:41.220] [board_logger] [error] no emotibit found
[2024-11-23 02:34:41.220] [board_logger] [info] trying broadcast address: 192.168.10.255
[2024-11-23 02:34:41.220] [board_logger] [info] sending package: 0,0,0,HE,1,100

[2024-11-23 02:34:42.131] [board_logger] [trace] package is 1601663,72,0,HH,1,100,DP,3133,DI,MD-V5-0000063
[2024-11-23 02:34:42.131] [board_logger] [info] received HH package
[2024-11-23 02:34:42.131] [board_logger] [info] Found emotibit: MD-V5-0000063
[2024-11-23 02:34:42.131] [board_logger] [trace] package is 2871118,72,0,HH,1,100,DP,3133,DI,MD-V5-0000543
[2024-11-23 02:34:42.131] [board_logger] [info] received HH package
[2024-11-23 02:34:42.131] [board_logger] [info] Found emotibit: MD-V5-0000543
[2024-11-23 02:34:42.132] [board_logger] [warning] failed to bind to 3133
[2024-11-23 02:34:42.132] [board_logger] [info] use port 3135 for data
[2024-11-23 02:34:42.132] [board_logger] [info] local ip addr is 192.168.10.115
[2024-11-23 02:34:42.132] [board_logger] [warning] failed to connect to 3132
[2024-11-23 02:34:42.135] [board_logger] [info] use port 3134 for control
[2024-11-23 02:34:42.135] [board_logger] [info] sending connect package: 0,0,4,EC,1,100,CP,3134,DP,3135

[2024-11-23 02:34:42.135] [board_logger] [trace] waiting for accept 0/20
[2024-11-23 02:34:42.446] [board_logger] [trace] waiting for accept 1/20
[2024-11-23 02:34:42.756] [board_logger] [trace] waiting for accept 2/20
[2024-11-23 02:34:43.068] [board_logger] [trace] waiting for accept 3/20
[2024-11-23 02:34:43.377] [board_logger] [trace] waiting for accept 4/20
[2024-11-23 02:34:43.689] [board_logger] [trace] waiting for accept 5/20
[2024-11-23 02:34:44.000] [board_logger] [trace] waiting for accept 6/20
[2024-11-23 02:34:44.311] [board_logger] [trace] waiting for accept 7/20
[2024-11-23 02:34:44.625] [board_logger] [trace] waiting for accept 8/20
[2024-11-23 02:34:44.936] [board_logger] [trace] waiting for accept 9/20
[2024-11-23 02:34:45.248] [board_logger] [trace] waiting for accept 10/20
[2024-11-23 02:34:45.559] [board_logger] [trace] waiting for accept 11/20
[2024-11-23 02:34:45.870] [board_logger] [trace] waiting for accept 12/20
[2024-11-23 02:34:46.181] [board_logger] [trace] waiting for accept 13/20
[2024-11-23 02:34:46.493] [board_logger] [trace] waiting for accept 14/20
[2024-11-23 02:34:46.803] [board_logger] [trace] waiting for accept 15/20
[2024-11-23 02:34:47.113] [board_logger] [trace] waiting for accept 16/20
[2024-11-23 02:34:47.424] [board_logger] [trace] waiting for accept 17/20
[2024-11-23 02:34:47.738] [board_logger] [trace] waiting for accept 18/20
[2024-11-23 02:34:48.048] [board_logger] [trace] waiting for accept 19/20
[2024-11-23 02:34:48.358] [board_logger] [trace] failed to establish connection
Traceback (most recent call last):
  File "D:\workspace\brainflow\python_package\examples\tests\two_emotibits.py", line 62, in <module>
    main()
  File "D:\workspace\brainflow\python_package\examples\tests\two_emotibits.py", line 29, in main
    board2.prepare_session()
  File "C:\Python311\Lib\site-packages\brainflow\board_shim.py", line 1191, in prepare_session
    raise BrainFlowError('unable to prepare streaming session', res)
brainflow.exit_codes.BrainFlowError: BOARD_NOT_READY_ERROR:7 unable to prepare streaming session

Will explain what is happenning here. First one connects just fine:

[2024-11-23 02:34:34.964] [board_logger] [trace] package is 1594496,66,0,HH,1,100,DP,-1,DI,MD-V5-0000063
[2024-11-23 02:34:34.964] [board_logger] [info] received HH package
[2024-11-23 02:34:34.965] [board_logger] [info] Found emotibit: MD-V5-0000063
[2024-11-23 02:34:34.965] [board_logger] [info] use port 3133 for data
[2024-11-23 02:34:34.965] [board_logger] [info] local ip addr is 192.168.10.115
[2024-11-23 02:34:34.965] [board_logger] [info] use port 3132 for control
[2024-11-23 02:34:34.965] [board_logger] [info] sending connect package: 0,0,4,EC,1,100,CP,3132,DP,3133

[2024-11-23 02:34:34.965] [board_logger] [trace] waiting for accept 0/20
[2024-11-23 02:34:35.277] [board_logger] [trace] waiting for accept 1/20
[2024-11-23 02:34:35.589] [board_logger] [trace] waiting for accept 2/20
[2024-11-23 02:34:35.898] [board_logger] [trace] waiting for accept 3/20
[2024-11-23 02:34:36.210] [board_logger] [trace] waiting for accept 4/20

And it takes ports 3132 and 3133

Second one tries to bind to these two ports(3132 and 3133) first, failed since they are busy and brainflow tries next two ports(3134 and 3135), they are free and should work just fine. It creates tcp socket server on this port, sends connection request to device and waits for connection from the board, it never happens:

[2024-11-23 02:34:42.131] [board_logger] [trace] package is 1601663,72,0,HH,1,100,DP,3133,DI,MD-V5-0000063
[2024-11-23 02:34:42.131] [board_logger] [info] received HH package
[2024-11-23 02:34:42.131] [board_logger] [info] Found emotibit: MD-V5-0000063
[2024-11-23 02:34:42.131] [board_logger] [trace] package is 2871118,72,0,HH,1,100,DP,3133,DI,MD-V5-0000543
[2024-11-23 02:34:42.131] [board_logger] [info] received HH package
[2024-11-23 02:34:42.131] [board_logger] [info] Found emotibit: MD-V5-0000543
[2024-11-23 02:34:42.132] [board_logger] [warning] failed to bind to 3133
[2024-11-23 02:34:42.132] [board_logger] [info] use port 3135 for data
[2024-11-23 02:34:42.132] [board_logger] [info] local ip addr is 192.168.10.115
[2024-11-23 02:34:42.132] [board_logger] [warning] failed to connect to 3132
[2024-11-23 02:34:42.135] [board_logger] [info] use port 3134 for control
[2024-11-23 02:34:42.135] [board_logger] [info] sending connect package: 0,0,4,EC,1,100,CP,3134,DP,3135

[2024-11-23 02:34:42.135] [board_logger] [trace] waiting for accept 0/20
[2024-11-23 02:34:42.446] [board_logger] [trace] waiting for accept 1/20
[2024-11-23 02:34:42.756] [board_logger] [trace] waiting for accept 2/20
[2024-11-23 02:34:43.068] [board_logger] [trace] waiting for accept 3/20
[2024-11-23 02:34:43.377] [board_logger] [trace] waiting for accept 4/20
[2024-11-23 02:34:43.689] [board_logger] [trace] waiting for accept 5/20
[2024-11-23 02:34:44.000] [board_logger] [trace] waiting for accept 6/20
[2024-11-23 02:34:44.311] [board_logger] [trace] waiting for accept 7/20
[2024-11-23 02:34:44.625] [board_logger] [trace] waiting for accept 8/20
[2024-11-23 02:34:44.936] [board_logger] [trace] waiting for accept 9/20
[2024-11-23 02:34:45.248] [board_logger] [trace] waiting for accept 10/20
[2024-11-23 02:34:45.559] [board_logger] [trace] waiting for accept 11/20
[2024-11-23 02:34:45.870] [board_logger] [trace] waiting for accept 12/20
[2024-11-23 02:34:46.181] [board_logger] [trace] waiting for accept 13/20
[2024-11-23 02:34:46.493] [board_logger] [trace] waiting for accept 14/20
[2024-11-23 02:34:46.803] [board_logger] [trace] waiting for accept 15/20
[2024-11-23 02:34:47.113] [board_logger] [trace] waiting for accept 16/20
[2024-11-23 02:34:47.424] [board_logger] [trace] waiting for accept 17/20
[2024-11-23 02:34:47.738] [board_logger] [trace] waiting for accept 18/20
[2024-11-23 02:34:48.048] [board_logger] [trace] waiting for accept 19/20
[2024-11-23 02:34:48.358] [board_logger] [trace] failed to establish connection

@Andrey1994
Copy link
Member Author

I've found the hack used by emotibit sw and its quite weird. It creates broadcast socket first and afte that converts broadcast socket to a notmal udp socket instead creating another one. We've not done it and used broadcast socket for further configuration and it didnt work for multiboard case.

Next commit here will solve it

Signed-off-by: Andrey Parfenov <a1994ndrey@gmail.com>
@Andrey1994 Andrey1994 marked this pull request as ready for review November 24, 2024 00:17
@Andrey1994 Andrey1994 changed the title WIP: adding support for multiple emotibits Adding support for multiple emotibits Nov 24, 2024
@Andrey1994 Andrey1994 merged commit 96b4179 into master Nov 24, 2024
34 checks passed
@Andrey1994 Andrey1994 deleted the two_emotibits branch November 24, 2024 01:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant