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

Connecting to multiple UART Servers #30

Open
twonius opened this issue Mar 11, 2022 · 1 comment
Open

Connecting to multiple UART Servers #30

twonius opened this issue Mar 11, 2022 · 1 comment
Labels
question Further information is requested solution proposed

Comments

@twonius
Copy link

twonius commented Mar 11, 2022

I'm trying to extend this so I can connect to multiple UART servers simultaneously.

I've already got the scan filtering for UART devices only and am passing the list of device labels to the TerminalFragement

But it looks like I'm overwriting the socket connection when I loop through the devices and create them in the service.

If i send a message I only get a reply from one of the devices. Is there an elegant way of doing this without just creating an array of services?

for(String d:deviceList) {
try {
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
BluetoothDevice device = bluetoothAdapter.getRemoteDevice(d);
status("connecting..." + device);
connected = Connected.Pending;
SerialSocket socket = new SerialSocket(getActivity().getApplicationContext(), device); // need to make multiple connectons and retrieve address
service.connect(socket);
} catch (Exception e) {
onSerialConnectError(e);
}
}

@kai-morich
Copy link
Owner

I recommend to create distinct service instances. Else you would have to enhance the service class to manage multiple sockets

@kai-morich kai-morich added the question Further information is requested label Mar 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested solution proposed
Projects
None yet
Development

No branches or pull requests

2 participants