Android bluetooth connections issues

Viewed 169

I have confusion on bluetooth connections.

Preface: when connecting devices for android over bluetooth you can connect as server or as client

My understand: connecting as the server essentially means that your device will be hosting the connection. Connecting as client means that you are being hosted by another device - and/or the device you are connecting to is the host.

I am trying to build an app that can connect via bluetooth and control a device. My first use case is my TV. so I want to make my app that can connect to my TV and control it as a remote. My initial thought is that the TV would act as the server. If I am connecting to another phone then I would imagine that my device would need to be the server. In most cases, if I want my app to act as a controller to send control signals to the device it connects to - is it correct to assume that my device is client or server?

2 Answers

Assuming that you mean Bluetooth Low Energy (BLE), then there are two separate types of roles that dictate how communication happens in Android:-

Central vs Peripheral - This has to do with the connection establishment and maintenance as follows:-

  • Peripheral device is the one responsible for advertising its presence as well as accepting incoming connections. Sensors usually fall into this category.
  • Central device is the one responsible for scanning and establishing the connection with the remote peripheral device. Phones usually fall into this category.

GATT client vs GATT server - This dictates how communication is handled when that connection is made:-

  • GATT server is the device that hosts all the data. Again, sensors usually fall into this category.
  • GATT client is the device that reads the data from the GATT server. Again, phones and computers usually take the GATT client role.

The two types of roles are separate (i.e. a Central can be a GATT server or a GATT client, and vice versa), but in the majority of the cases, the central is the GATT client.

And to finally answer your question, I would make the remote controller to be both the central and the GATT client. This way your TV would always be advertising its presence and hosting the date, while the remote scans/connects and reads/writes to that data.

You can find more information in the links below:-

Client because when is server tv, you can connect from more clients (mobiles). When is server mobile you can controll more tvs, but tv can connect only to defined mobiles.

Related