I have an Android app acting as a peripheral server sending accelerometer data via notifications to the central client (an RN4871 module).
Things work fine if I manually initiate the connection from the RN4871 using the phone's randomized MAC address, but I would like to pair the two to make connection easier so I can do it through software instead of manually.
I send the bonding request from the RN4871 on the phone and the phone allows me to accept it.
%INDI,0003,0100FFFF%%INDI,0003,0100FFFF%%SECURED%%BONDED%
There seem to be some handshake messages which are sent: %CONN_PARAM,0006,0000,01F4%%CONN_PARAM,0016,0000,0200%
I think maybe these are updating the connection parameters to the following:
2021-03-08 10:01:26.932 16804-17751/ece558.bthornhill.edu.jumprope D/BluetoothGattServer: onConnectionUpdated() - Device=D8:80:39:F8:B2:77 interval=6 latency=0 timeout=500 status=0
2021-03-08 10:01:27.599 16804-17751/ece558.bthornhill.edu.jumprope D/BluetoothGattServer: onConnectionUpdated() - Device=D8:80:39:F8:B2:77 interval=22 latency=0 timeout=512 status=0
But then the app seems to freeze. I can disconnect the connection on both sides by exiting the app, and running the connection kill command on the RN4871, but when I set the app in advertising mode again, and try to connect to the newly listed bonded device, the connection never happens and it just cycles.
I can get things working again only when I unpair the device from the phone, remove the phone as a bonded item from the RN4871, and restart the RN4871 and the app.
I can't seem to pinpoint what the exact issue is. Any help would be appreciated.
Related
I am developing an app in which the first thing i need is how to get devices that are connected to my wifi network or same wifi network .ie ip adress,device name etc.
I don't have any idea how to do that have searched alot but there are no examples available.
I have done one thing that i will ping 255 ips and whichever will respond will be the connected ips but the problem here is that there are virtual ips already assigned to some websites so i need to detect only the real device ip addresses.
I want to do the same thing as done in the app WifiTalkie
Follow Any one of the following:
Way1:
If you mean you want to see all the devices connected to your current WiFi connection (and you are not trying to do Ad Hoc networking), then you are essentially wanting to run a network scanner.
There are a bunch of these around. This one has the source available on github
http://rorist.github.com/android-network-discovery/
Way2:
Refer How to detect all the Devices connected in a WiFi network from Android App
The Problem:
The bluetooth connection between the android app(GATT client) and two TI boards(CC2640R2F, GATT server) is unstable. When the android app connects to the two boards, the bluetooth connection state of the two boards toggle rapidly between connected and disconnected states. As a result the service discovery process is affected and sometimes there are no GATT characteristics discovered(The GATT service is just empty). The problem occurs with only android devices running marshmallow(6.0+) and above.
This issue also occurs on other third-party apps available in the play store such as BLE scanner, sensorTag and nrf connect running on those android devices.
Fixes attempted on Android side:
The following fixes were attempted on the Android side but these were unsuccessful.
a time delay(tried upto 2000ms) was set between connection successful event and gatt.discoverServices() request.
Have separate device.gattConnect(...) methods for devices below and above marshmallow(6.0). Devices above marshmallow require a TRANSPORT parameter.
Switch connection between the GATT servers to ensure that only one server is connected at a given time.
Created separate Gatt callbacks for the two servers and separate threads for all the operations that took place involving the two servers.
The only fix that was successful is connecting only one server to the client. To connect another server, the app needs to be reopened. If another device is connected at the same time, the issue still occurs.
Data Collected:
The bluetooth sniffer logs were collected from the android side and are attached.
The 'btsnoop_hci_success.log' file deals with the successful BLE connection between an android device(Samsung galaxy s7 edge) running marshmallow(6.0.1) and just one server(a purifier).
The 'btsnoop_hci_fail.log' file deals with the problematic BLE connection between the same android device and two servers(a sensor and a purifier).
How to detect if Android wear switched the connection from bluetooth to wifi or vice versa? And is there a way to force it to connect via bluetooth?
Being an Android framework, you can register a broadcast receiver to be notified when connectivity status changes. In general, when your watch is connected to a phone directly (which only happens via BT), wifi connection is dropped and when it is not connected, if your phone is wifi capable and if a wifi network is available, it gets connected to the cloud node. In that case, you cannot force it to connect through BT since, most likely, it is not possible (might be due to distance or many other reasons). What exactly are you trying to accomplish?
I have been running into an issue with my product that has a rooted tablet (iball 3G 7271,running on 4.1.2) which is trying to communicate with an RN42 Bluetooth module.As per my project requirement the android app, which initiates the BT connectivity to the RN42 must have capability to:
Be updated remotely
Should restart itself in case if it crashes.Both these functionality
have been coded and found working.
However as you know in both these cases the Bluetooth connectivity is disrupted and lost,and has to be re-established between the tablet and the RN42.
The problem I am facing is that,when the app which was connected via Bluetooth to RN42(is either updated/restarted as per case 1 or case2) leaves the bluetooth socket/port in the connected/open state itself,whilst the new app is re-installed/restarted respectively.Hence the newly re-installed/restarted app, when it initiates a bluetooth connection with the RN42, the device OS allocates it a new bluetooth socket/port(and not the older one since it is still occupied). But after a couple of re-installs/restarts(20 to be precise) the device runs out of any available socket port which it can allocate to the app and I get repeated exception stating 'Connection not created(failed or aborted)'.
Is there a way that I can close the bluetooth socket/port which was left open by an app prior to its reinstall/restart?
I had such issues with different BT chipset (mainly from lowcost tablet) and switching on/off the Bluetooth adapter did the job, through .enable() or .disabled().
Notice it is a bad idea, bad practice, but in the scope of my mockup it was usefull for debug :)
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mBluetoothAdapter.disable();
while(mBluetoothAdapter.isEnabled());
mBluetoothAdapter.enable();
while(!mBluetoothAdapter.isEnabled());
Sorry for kind of a dummy question, but I'm wondering how to work with WiFi connection via android. My application needs to transfer some data (both receiving and sending) with PC or with other android device using WiFi. How should I organize the process? I mean, how should I establish connection, then should I open a socket for data transfering, etc. Is there any way to do it without internet connection, smth like bluetooth, except wifi.p2p (which is only available for android 4.0)? Would be grateful for as detailed manual as possible.
Every network connection even if only in the local network or localhost reqieres the INTERNET permission.
Bluetooth and NFC might be an option, but I have no experiance with that.