BlueTooth Problem

iCAB

Well-Known Member
Licensed User
Longtime User
Hi There

I am using an RS232 to BT dongle to connect an embedded system to android tablet.

When the connection is lost ( due to the tablet go to sleep mode or some other reason ), in some cases I cannot reconnect. Even though when I go to the tablet settings I can still see that the device is paired.

The problem also behaves differently on different type of tablets.
For example: on Nexus 7, with 4.2 , I do see the problem but not as much as on lenovo tab running an earlier version of the android os.

The discovery process, finds the device, at this point, I re-issue the Connect Method with the mac address, but the connect event doesn't get triggered.

If I reboot the tablet, I can reconnect no problem


Any help is greatly appreciated.

Thanks in advance.
 

iCAB

Well-Known Member
Licensed User
Longtime User
Hi Erel

Sorry I was away and didn't have a chance to log back in.

Thanks for your reply, I'll give it a try.
But I was wondering what is the proper way of closing the connection, when the tablet and the embedded system move away from each other ( meaning out of range )

Thank you
 
Upvote 0

iCAB

Well-Known Member
Licensed User
Longtime User
Hi Erel

I am actually not sure what is the problem any more. The program runs perfectly ok on Nexus 7. If I try it on Nexus 4 or Lenovo tablet, many times I run into problems connecting even after start up. If I go to settings, unpair the device, pair it again, 99% of times, it reconnects. I never have this issue with Nexus 7 at all.

Serial_Connected ( success = false )

Is there a way to get more info about the failure.
BTW as a quick check, I tried:
connect3 with port1
and I also tried ConnectInsecure with port 1
no luck.
Any help is greatly appreciated.

Also one thing I should mention in here, that once the proram connects, there are no issues whatsoever with any of the devices.

Thanks
 
Upvote 0

iCAB

Well-Known Member
Licensed User
Longtime User
Hi Erel

Here is what I got at the end of the log, please let me if you need more info, then I can e-mail you the full log

[1] 5.onFinished: Installation state replication succeeded.
DISCOVERY_COMP_EVT slot id:3, failed to find channle, status:1, scn:0
btm_sec_disconnected - Clearing Pending flag
invalid rfc slot id: 3
java.io.IOException: read failed, socket might closed or timeout, read ret: -1
at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:492)
at android.bluetooth.BluetoothSocket.readInt(BluetoothSocket.java:503)
at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:318)
at anywheresoftware.b4a.objects.Serial$1.run(Serial.java:152)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
GC_FOR_ALLOC freed 167K, 5% free 10502K/11028K, paused 49ms, total 49ms
GC_CONCURRENT freed 369K, 4% free 10686K/11088K, paused 3ms+11ms, total 42ms
connected: false
GC_CONCURRENT freed 679K, 7% free 10697K/11404K, paused 3ms+3ms, total 32ms
WAIT_FOR_CONCURRENT_GC blocked 18ms
unable to find stats for iface rmnet_usb0
GC_CONCURRENT freed 352K, 6% free 9264K/9788K, paused 28ms+2ms, total 58ms
Total arena pages for JIT: 18
GC_CONCURRENT freed 332K, 4% free 8916K/9276K, paused 2ms+2ms, total 16ms
NetTransition Wakelock for WifiStateMachine released by timeout
GC_CONCURRENT freed 378K, 6% free 9272K/9788K, paused 8ms+1ms, total 58ms
 
Upvote 0

iCAB

Well-Known Member
Licensed User
Longtime User
Hi Erel

The code is big to post all of it.
But here are the snippets that relate to the issue:

These are the declarations used:
Dim ICABBTAdmin As BluetoothAdmin
Dim ICABSerial As Serial
Dim foundDevices As List
Type NameAndMac (Name As String, Mac As String)
Dim connectedDevice As NameAndMac


First I do the following init.
ICABBTAdmin.Initialize( "ICABBTAdmin")
ICABSerial.Initialize( "ICABSerial")


then
foundDevices.Initialize
ICABBTAdmin.StartDiscovery


The discovery process always finds the device .

Sub ICABBTAdmin_DeviceFound (Name As String, MacAddress As String)
Dim strTemp As String
Log(Name & ":" & MacAddress)
Dim nm As NameAndMac
Dim strSettingMacAddress As String

nm.Name = Name
nm.Mac = MacAddress

Log("Name: "&Name )
Log("Mac Address: "&MacAddress )

foundDevices.Add(nm)

strTemp = "Searching for devices (~ found)...".Replace("~", foundDevices.Size)

strSettingMacAddress = SET_GetSetting(SET_BT_MAC)
strSettingMacAddress = strSettingMacAddress.Trim

If blnBTSetupMode = False Then
If MacAddress.CompareTo(strSettingMacAddress) = 0 Then
ICABBTAdmin.CancelDiscovery
DashBoard_LCDUpdateTextImmediately("Attempting to Connect to BT Adapter",3)
'In here I tried Insecure and Connect3, no difference at all
ICABSerial.Connect(MacAddress)

ICABBTSetCommunicationState( BTS_CONNECTING, False )
End If
End If

DashBoard_LCDUpdateTextImmediately(strTemp,3)

End Sub


'The function below always gets Called with Success = true on Nexus 7
'The function below never gets called with Success = true on Nexus 4 after a reboot. I must unpair the device, and pair it again. Then every thing starts working ok until the next reboot

Sub ICABSerial_Connected (Success As Boolean)
ProgressDialogHide
Log("connected: " & Success)


If Success = False Then
ICABBTSetCommunicationState( BTS_FAILED_TO_CONNECT ,False )
Else
ICABBTSetCommunicationState( BTS_CONNECTED, False )
AStreams.Initialize(ICABSerial.InputStream, ICABSerial.OutputStream, "AStreams")
End If

End Sub

Thanks for your help
 
Upvote 0
Top