Skip to content

Conversation

@Technickel-Dev
Copy link

Here are the changes that would resolve #42, adding in support for multiple Bluetooth connections. I have been unable to fully test the functionality yet, but will be able to do so in the next week as I will be around the hardware then. If you have any suggestions or ideas for additional changes, let me know!

private BluetoothCallback bluetoothCallback;

private ReceiveThread receiveThread;
private ArrayList<ReceiveThread> receiveThreads = new ArrayList<>();
Copy link
Owner

@omaraflak omaraflak Aug 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer the use of List here :

List<ReceiveThread> receiveThreads;

and initialize it with the other variables in the initialize() method :

receiveThreads = new ArrayList<>();

* Disconnect from all bluetooth devices.
*/
public void disconnect() {
for (ReceiveThread receiveThread: receiveThreads) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to able to control each socket separately. We should not disconnect every socket.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you should rename the method disconnectAll()

* @param msg String message.
* @param charset Charset used to encode the String. Default charset is UTF-8.
*/
public void send(String msg, String charset){
Copy link
Owner

@omaraflak omaraflak Aug 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, can you rename it to sendToAll() ?

socket.connect();
connected = true;
receiveThread = new ReceiveThread(socket, device);
ReceiveThread receiveThread = new ReceiveThread(socket, device);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, we should be able to differentiate messages from callbacks. We should know which socket triggered which callback.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need it. Do you have update for this?

bluetooth.setDeviceCallback(new DeviceCallback() {
    @Override
    public void onMessage(BluetoothDevice device, byte[] message) {
    }
}

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.

Multiple Bluetooth Client Connections

3 participants