I have an application that needs to keep the bluetooth discovery process in a loop to always discover new bluetooth devices (when the BroadcastReceiver gets a BluetoothAdapter.ACTION_DISCOVERY_FINISHED, I just call the startDiscovery() again). I've recently added some socket communication to the app, that basically opens a Socket to a server, sends data and then closes the socket.
When I'm using 3G, everything works fine and a sniffer shows no TCP Retransmissions, the socket is cleanly opened and closed. Using Wifi, however, shows lots of TCP Retransmissions and sometimes even failures to connect the socket (with java.net.SocketException timeout).
I'm using a Samsung Galaxy S with Android 2.2.1. Is there something I'm overlooking?
Can you try to configure and move WiFi to a different channel ? If you are using WiFi also in the 2.4 GHz band interference is expected specially during initial discovery / connection, after connection it should become better as Bluetooth should frequency hop to avoid interference (unless WiFi is clogging the complete spectrum)
Related
I have a setup with two Android devices: an android phone and a custom hardware running Android 10. The latter acts as a BLE Server, which is discoverable always with the same static MAC address. Also when that custom HW is paired with the phone it has access to phone's contacts and calls history. That HW can also play media (sound) streamed from the phone.
I use RxAndroidBle 1.11.0 library for BLE communication. As soon as I exchange some data via BLE Characteristic I unsubscribe from the RX observable so the library effectively calls: bluetoothGatt.disconnect() then blutetoohGatt.close()
(all those inside the DisconnectOperation class).
My problem is the fact that based on my observations, calling blutetoohGatt.disconnect() disconnects the classic BT profile (PBAP) as well.
Is it an expected behaviour?
I have investigated the code of generic Android P framework and it looks that calling bluetoothGatt.disconnect() -> bluetoothGatt.close() completely disconnects the device described by the given MAC Address:
BluteoothGatt#disconnect()
BlutetoothGatt#close()
BlutetoothGatt#unregisterApp()
I would risk a statement that I have quite unusual BLE use-case scenario where the phone (Central/Client) and the peripheral (custom Android HW/Server) are connected simultaneously via Classic BT profile and via BLE.
I suspect that disconnecting/closing device using its BT MAC address disconnect both profiles, hence the contacts sharing stops working.
Is it possible to disconnect BLE connection only, but not affect the classic BT (SPP/PBAP) connections between the two devices?
After further investigation described on that Github issue
I realised that my custom hardware is equipped with dual-mode BT adapter so it supports classic BT (BR/EDR) and the BLE one.
As soon as I pair an Android phone with the custom hardware via System Settings, classic BT profiles are bonded, but also my GATT Server advertises relevant services using the same MAC address which is used by the BR/EDR. Disconnecting BLE client connection disconnect BD/EDR as well.
What helps in my case is to not start pairing via System Settings, but let the GATT server advertise and let my BLE client app to connect (and trigger pairing) first. As a result I have a BLE connection with server available under "AA:AA:AA:AA:xx", while the classic BT profiles are connected to "BB:BB:BB:BB:yy" interface on the custom hardware.
Now, disconnecting BLE profile does not disconnect the classic one.
I am looking for a solution which would allow my GATT Server to be advertised with BLE only, but no luck so far.
Here are some interesting links I have found:
connectGatt creates connection over BT Classic instead of BLE
how to force BLE "just works" pairing in Android
BLE Dual-Mode
I'm developing an application that communicates with Arduino (Arduino Uno), I used two ways to communicate so far, via :
1. USB (I used the usb-serial-for-android and Physicaloid libraries) and
2. Bluetooth, sending and receiving data.
Via Bluetooth was a little slow and sometimes the information was simply not sent or received, the USB communication sending data was pretty fast, but still, sometimes the connection does not open, and it's very random, run the application and USB connection does not open, close the application, run again and the connection open, have not tried connecting via Wifi.
My question is this, what is the ideal and safest way to perform connection with Arduino?
Bluetooth connection is best, because HC05 adapters are dirt cheap and those use UART for communication (the same as com- port )
I am building an app that uses Socket IO to communicate with a server. I have been testing on an Xperia Z2 running Android 6.0.1. When I tested it today on a Motorola Moto x running 6.0 and the socket won't connect while still working fine on the Sony device. I have searched around and the only suggestion that keeps popping up is to ensure that the Internet permission is declared in the manifest, which it is.
The network is not connected to the internet but the server is running on the network so I don't think that should make a difference.
The Socket is being created using an IP-address and port number that it gets from a service found using Androids Network discovery.
The network configuration is one of two. The only one I can test at the moment is a micro controller device acting as an access point that is running a service and listens for socket IO requests.
What reasons might exist for a socket being able to connect on one device and not on another.
I am working on an application that connects to a device using a bluetooth socket. Everything is running smoothly on 2 different HTC handsets with Android 2.2 but I just tried a brand new Sony Xperia running on Android 2.3 and I am experiencing a really weird behavior.
When I start the application, it will scan for devices and initiate a pairing request with the device. The pairing request is received and accepted by the user, the connection is made and a socket is opened.
The problem is that as soon as the socket is closed, the pairing is "forgotten" by the phone. The device is listed as unpaired in the Bluetooth devices list, and the application must initiate a new pairing request each and every time it needs to open the connection.
Has anything changed in the way pairing is managed with android 2.3? Is there a new requirement to close the socket and avoid loosing the pairing?
Thx in advance,
Pierre
Iam connecting 3G phone for my Android device for internet connection and another Socket(SPP) for CAN signal receiving.Whenever I manually connect to the Bluetooth tethering via 3G phone, i can browse internet perfectly and speed is good.Whenever programmatically connect to the 3G connection, i couldn't browse internet.i checked in shell and observing that in my mobile 'device is connected' message displayed and E symbol appears.No problem for me to connect Socket.But I got problem to use 3G phone.For this iam using APN/DUN mode.I checked both but no use.Is there any performance issue here or anything wrong to connect different devices by using Bluetooth API in android.Why this happends while connecting Mobile programmatically.Please give me guidance.
Regards,
Rajendar
Yes, you can have several open connections at a time.
In fact, I've used my hands-free bluetooth on my phone, as it is connected to my ELM327 SPP device streaming at full speed. I didn't notice any hiccups.
As for losing connectivity when you are connected to multiple devices, it's most likely an issue with the DUN provider you're using.
Also it's worth stating that, on Verizon/3g phones, when you use the phone as a phone, it suspends all 3g data services until the call is terminated.
The way L2CAP defines the LT_ADDR allows connecting devices up to 7. Your connection problems is something else.