How to connect several devices on a gatt server using BLE? - android

I made a connection between an Android device and a gatt server using bleno module from Nodejs in a RaspberryPi.
I'm sending some datas with my phone and in the meanwhile I want to connect an other device to the gatt server. However when I want to do this, I cannot see the RaspberryPi ie the gatt server with this second device. I'm new to ble so I was wondering if my phone has an issue or it's the technology that is actually like that. If not , is there a way to connect several devices to a same gatt server ?

Related

Android bluetooth connections issues

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?
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:-
The ultimate guide to Android BLE development
Bluetooth Low Energy: A primer
Android BLE examples
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.

Can an Android app discover a local BLE GATT server?

If Android app A sets up a BLE GATT server, can Android app B (on the same device) discover and connect to that GATT server as a client?
No this shouldn't be possible because Bluetooth doesn't allow a device to connect to itself. I can't find in the spec where it specifically states this, but I have tried to do this using different Bluetooth stacks in the past and I wasn't able to.
Some information is provided here:-
Loopback in Android Bluetooth

If I connect 2 android devices via WiFi-Direct - can one share its Internet connection with the other?

I am building an SDK for a client to connect 2 android devices for exchanging data (strings, commands...) via various channels, such as Bluetooth, USB cable, WiFi.
One of the devices is a standard android phone, with a SIM card and data, thus able to access the internet. The other has no SIM card.
Currently using WiFi I am opening a HotSpot on the phone device, and so the non-SIM device can access the internet via the HotSpot.
Now my client wants me to connect via WiFi-Direct, too.
So my question is - once I connect the two devices via WiFi-Direct, will I be able to access the internet on the non-SIM device, using the SIM/data on the "normal" phone?
Thx
Well, Wi-Fi direct can create hotspot independent of the legacy Wi-Fi hotspot BUT this hotspot doesn't share internet and any request to external ip will be dropped.
But for android you can use NetShare app to do that, you can download it from
here.
it works as follows:
• in the client side NetShare use the vpn service to catch all internet traffic of the device and send them to NetShare in the server device and wait for the response.
• in the server side NetShare run a server with specific port to receive the internet packets sent from the client side in
previous step, it send these packets to the internet, after receiving the reponse from the internet it will send these responses to the NetShare in the client side which in turn provide it to the back to the client device.
for more details see the official website

Create group using wifi p2p to connect multiple device

I want to create a connection where one device will be like server which will stream some data to connected and multiple device can connect to that device which
receive data.
So i have done some kind of research i got to know that we can do this using network service discovery and WiFi peer to peer, So i have made the connection where i can connect one device and stream data also but i want to create a group to connect multiple device ,So any help from any one would be appreciated.
Thanks!
WiFi-Direct or Wi-Fi Peer to Peer can do multiple device connection.
See this link to read more about P2P connections
-https://developer.android.com/training/connect-devices-wirelessly/wifi-direct.html
WiFi-Direct automatically select which device will be the Group Owner or the server base on which device is the most compatible to be the Group Owner or the server. But you can manually select which will be the Group Owner by setting WifiP2pConfig groupOwnerIntent = 15(the highest value).
If two devices are connected, when you connect another device this device will connect to the group owner(or server).
For you to able to send streams to client devices you can use java Sockets. When peer to peer connection is established, the group owner will be the one to handle the server socket and client socket for the client devices.
If you have multiple devices and you want to send a message to a specific client device you'll send it to the server and the server will send it to the specific client. see this link - WiFi Direct (Android 4.0) with multiple (3+) devices

Not able to connect to Bluetooth server and WiFi at same time

I have a Bluetooth device through which user can take photos. After taking the photos Bluetooth device hosts all the images on its own HTTP server (10.0.0.1), so that other devices can connect to server using Bluetooth and access photos from server using REST APIs which are exposed by server.
Steps to connect to Bluetooth device (Server)
Go to Setting, enable Bluetooth
Select Bluetooth device
Bluetooth device setting ("Paired Bluetooth device")
Select check box for Internet access.
Through this i am able to access Bluetooth server but my WiFi automatically gets disabled and I am not able to access internet.
If i uncheck "Internet access" check box in "Paired Bluetooth device setting" then I am able to connect to WiFi for internet access.
Is it possible to have both WiFi internet as well as Bluetooth internet at the same time? So that my app can connect to Bluetooth device to get the data (images) using REST APIs and post to remote server using WiFi.
I am using Nexus 7 tab for development which is running on Android 4.4.4.
1. ...so that other devices can connect to server using Bluetooth and access photos from server using REST APIs which are exposed by server
If the photos are on the server, devices can connect to it using wifi/internet also..right? To access the APIs and get the photos..
Why do you want other devices to connect to server using bluetooth to access photos from server using REST APIs
2. Is it possible to have both WiFi internet as well as Bluetooth internet at the same time?
Leave aside Bluetooth internet, there have been some issues related to Bluetooth and Wifi, even more with Bluetooth Low Energy and Wifi, many have been device specific.
Regarding what you are facing, there are issues on Android Open Source Project - Issue Tracker and other blogs also;
Issue 39995
Issue 41631
Nexus 5, Nexus 4 and Nexus 7 (2013) Android 4.4 Bluetooth Issues
[Although i haven't faced that issue in Nexus 5]
I have seen the same in MotoG also, turning on Bluetooth weakens the Wifi functionality.
In your case, considering nothing can be done with the device and its hardware,
you can check with the connections whether it happens intermittently, try to connect or send the request to server a couple of times.
3. ...app can connect to Bluetooth device to get the data (images) using REST APIs
If it can "connect" to the Bluetooth device, i suggest you try and get the images on the established connection rather than REST APIs. Simultaneous internet access through two different sources doesn't happen, even with the 3G and wifi :)
Just out of curiosity, when you are connected to the Bluetooth device, why do you want to add the necessity of internet to get the data?
Another approach, gets ugly but would work: Can you get the data that you need and ask the user to switch off the bluetooth so you can send the data..which you might need only on certain devices, if you separately get the data from the established bluetooth connection only

Categories

Resources