Android Question Bluetooth admin - Connect3 Port setting?

Arf

Well-Known Member
Licensed User
Longtime User
"
Method_636.png
Connect3 (MacAddress As String, Port As Int)

This method is a workaround for hardware devices that do not connect with Connect or Connect2.
See this issue for more information."

I think I've encountered such a device, a phone that refuses connection with the Connect(MAC) function.
I would like to try Connect3(), but I have no idea what to put in for the Port field?
I can't seem to find any examples anywhere.

Thanks
 

Arf

Well-Known Member
Licensed User
Longtime User
OK, just tried a strategy like this:
B4X:
Sub Serial1_Connected (Success As Boolean)
   Log("connected: " & Success)
   If Success = False Then
     Log(LastException.Message)
     Timer1.Enabled = False
     UNIT_CONNECTED = False
     TryNextPort
   Else
     CallSub(Settings,"Connected")
     'we're connected, now start a timer and if ever we go 200ms with no data, disconnect and re-initiate BT listening
      AStream.Initialize(serial1.InputStream, serial1.OutputStream, "AStream")
   End If
End Sub

Sub Connect(mac As String)
    serial1.Connect3(mac, port)
    savedmac = mac
End Sub

Sub TryNextPort
    port = port+1
    Connect(savedmac)
End Sub

I started with port = 1 as calling with port set to 0 causes an exception. Here's what came back from the Log:
connected: false
java.io.IOException: Permission denied
connected: false
java.io.IOException: Permission denied
connected: false
java.io.IOException: Software caused connection abort
connected: false
java.io.IOException: Permission denied
connected: false
java.io.IOException: Software caused connection abort
connected: false
java.io.IOException: Permission denied
connected: false
java.io.IOException: Software caused connection abort
connected: false
java.io.IOException: Permission denied
connected: false
java.io.IOException: Software caused connection abort
connected: false
java.io.IOException: Permission denied
connected: false
java.io.IOException: Software caused connection abort
connected: false
java.io.IOException: Too many symbolic links encountered
connected: false
java.io.IOException: Software caused connection abort
connected: false
java.io.IOException: Too many symbolic links encountered
connected: false
java.io.IOException: Too many symbolic links encountered
connected: false
java.io.IOException: Too many symbolic links encountered
connected: false
java.io.IOException: Too many symbolic links encountered
connected: false
java.io.IOException: Too many symbolic links encountered
connected: false
java.io.IOException: Too many symbolic links encountered
connected: false
java.io.IOException: Too many symbolic links encountered
connected: false
java.io.IOException: Too many symbolic links encountered
connected: false
java.io.IOException: Too many symbolic links encountered
connected: false
java.io.IOException: Too many symbolic links encountered
connected: false
java.io.IOException: Too many symbolic links encountered
 
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime User
Connection Refused. Used to get similar with a galaxy s3 until an update came out for it, so maybe a problem on the phone side - I've found Samsung bad for Bluetooth and usb interfacing.
 
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime User
Is there any other method for determining the port, before I attempt to connect?
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Just a thought, have you paired the device before hand? I had a similar problem with a Samsung device. I could not connect via B4J until I had paired before.
 
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime User
Usually the Connect call invokes the OS pairing confirmation box, but perhaps not in that older android OS device. I shall give it a try when done with my current debugging session.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Usually the Connect call invokes the OS pairing confirmation box

You are correct and it does but I still could not connect with my Samsung Galaxy Tab. I had to pair it manually before, then it worked.
 
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime User
Ah, I paired it manually first and no luck. It does actually pair when I do the ConnectInsecure too, just refuses to take a connection from anything external.

I'm giving that phone to the kids to destroy as I don't want to spend a lot of time on a problem I am sure is specific to that phone.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Shame that you are giving up and letting the kids destroy your phone but as you did not find a solution, could you at least tell the forum which phone was causing the problem. This could also help other users.

Thanks.

ps. Another quick thought. Did you do a discover before trying to connect?
 
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime User
Hi, it's a Samsung DUOS GT-S7562, android 4.0.4.

I have had Samsung S-III's on older android versions which would not connect via bluetooth or via usb to a VCOM devices in the past and research showed that they used a bluetooth implementation that was known to be troublesome, and Samsung had locked out SPP and USB interfacing access on some phones.

That S-III (both phone and tablet) suddenly started working perfectly when upgraded to 4.1.2 (I think that was the upgraded version anyway). So that's why I am not inclinced to spend lots of time trying to solve problems with older Samsung devices.

Yes I can discover the phone, and can create a connecion from the phone to my device using ConnectInsecure. What I cannot do, is to connect to the phone on an incoming connection request from my product - that is what the problem is.
 
Upvote 0
Top