Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting multiple devices to bluetooth in Android

So far what I know that its possible to communicate to multiple devices from your android phone. But my case is that I want to connect two 'similar' devices.

My understanding is that, I need to use different UUID if I need to connect 2 devices, the bluetooth chat application suggest to hardcoding the UUID.

Now scenario is that, I m programing for a game, where physical gun will be connected to phone via bluetooth (to track shots etc). Ok here I can ask gun vendor to hard-code a UUID for all guns and phone can connect to 1 gun at a time.. its easy.

The requirement is that, user may have more then 1 gun! Can somebody tell me how to manage this, if I m hardcoding a single UUID for all guns then I m not sure how to connect multiple guns. And if I m not hardcoding the UUID in gun chip, how I can find the UUID to connect?

like image 267
Umair Avatar asked Mar 24 '23 03:03

Umair


1 Answers

A UUID is not a unique device identifier; UUIDs are unique identifiers used by the Bluetooth Service Discover Protocol to identify the protocol a Bluetooth device is using. Bluetooth.org has a list of common UUIDs.

Assuming you know or can control the UUID in the guns (it sounds like you can), then you can set up the phone as the Bluetooth server (using the same UUID that the guns use). The guns would then connect as the clients using the same UUID (I know the guns are probably not using Android, but there's some example code there that might be helpful).

Of course, you may need to flip the client/server model around to fit your specific needs. You should be able to make as many of those server and client threads as you need (within the limits of the number of connected devices that your hardware imposes).

like image 169
Bryan Herbst Avatar answered Apr 13 '23 21:04

Bryan Herbst