Android Question [SOLVED - explained?] BLE - connecting fail 2 - NEW ISSUE

rabbitBUSH

Well-Known Member
Licensed User
SEE RELATED POST

Any suggestions / pointers / solutions to the following - welcomed . . . .

In the above related post I asked about connecting to a specific device - which was not working prior to proceeding with a project.

The above was resolved.

I am now proceeding with the project still starting with @Erel s example code for BLE.

Now, being able to connect to the device, and with Erel's code now "seeing/Finding" the device - the example App attempts to connect to the device however it then, after about 5 - 10 seconds simply says Disconnected.

The Sub at which it fails is here : the line manager.Connect2(Id, False) is performed and then it just goes to the Sub Manger_Disconnected

point where it drops the connection attempt:
Sub Manager_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double)
    Log("Found: " & Name & ", " & Id & ", RSSI = " & RSSI & ", " & AdvertisingData) 'ignore
'    If Id = "6D:D4:F2:0C:A4:74" Then
    ConnectedName = Name
    manager.StopScan
    Log("connecting")
        #if B4A
    manager.Connect2(Id, False) 'disabling auto connect can make the connection quicker

    #else if B4I
    manager.Connect(Id)
    #end if
'    End If
End Sub

The log for this is very short and is quoted below. I've stepped through the code and used several breakpoints to see where it stops the connection attempt, but it didn't really give anything useful. It seems obvious that this is some sort of time-out, but I haven't found anywhere to extend this - or in fact, that shows it exists as a changeable setting.

VERSION-1.0 -> is the temporary name I have given the device.
Logger connected to: samsung SM-A307FN
--------- beginning of crash
--------- beginning of main
--------- beginning of system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
Found: VERSION-1.0, 50:65:83:6F:92:15, RSSI = -44, (MyMap) {1=[B@405125e, -1=[B@475a63f, 9=[B@2792b0c, 18=[B@ffd2c55, 10=[B@10bf66a, 2=[B@728675b, 0=[B@713ebf8}
connecting
Disconnected
** Activity (main) Pause event (activity is not paused). **
** Activity (main) Resume **
** Activity (main) Pause event (activity is not paused). **
** Service (starter) Destroy (ignored)**
 

wes58

Active Member
Licensed User
Longtime User
SEE RELATED POST

Any suggestions / pointers / solutions to the following - welcomed . . . .

In the above related post I asked about connecting to a specific device - which was not working prior to proceeding with a project.

The above was resolved.

I am now proceeding with the project still starting with @Erel s example code for BLE.

Now, being able to connect to the device, and with Erel's code now "seeing/Finding" the device - the example App attempts to connect to the device however it then, after about 5 - 10 seconds simply says Disconnected.
I saw that you looked at this thread https://www.b4x.com/android/forum/threads/ble2-library-additional-functions.133296/. There is also a link https://www.b4x.com/android/forum/threads/solved-ble-connection-problems.133142/ which described my problems with connecting to the BLE device.
What I found out I had to change the connection method:
The Erel's BLE2 library is using - public BluetoothGatt connectGatt (Context context, boolean autoConnect, BluetoothGattCallback callback)
Nordic nRFconnect is using this function - public BluetoothGatt connectGatt (Context context, boolean autoConnect, BluetoothGattCallback callback, int transport) ,
where transport = 2 (BLE) - and it is able to connect to the device
After adding this method to the BLE2 library - as described in https://www.b4x.com/android/forum/threads/ble2-library-additional-functions.133296/ (connect3 function) I was able to connect with my device
 
Upvote 0

rabbitBUSH

Well-Known Member
Licensed User
Worth checking the unfiltered logs.
Will have go.

Are you able to connect to the peripheral with a third party BLE app?
Yes. Nordic and - now - Bluno demo off github. The latter has send data button - same as your example - from which I can send-receive data.

Am in conversation with Wes58 about his solution. Will post as it goes along.
 
Upvote 0

rabbitBUSH

Well-Known Member
Licensed User
if the
transport issue is indeed the problem
We'll see that when I get to the workbench later on. Its a really subtle difference isn't it.
 
Upvote 0

rabbitBUSH

Well-Known Member
Licensed User
can't connect to the module
that looks like it. module/device is Found -> MAC/Id - RSSI and so in
Found: VERSION-1.0, 50:65:83:6F:92:15, RSSI = -50, (MyMap) {1=[B@fe98faa, -1=[B@7b4279b, 9=[B@8a84738, 18=[B@2a99311, 10=[B@d28fc76, 2=[B@a3a277, 0=[B@369ee4}
then log says connecting.... then disconnects when connection not achieved.

maybe its stuck on the bonding or service discovery part - - - - or - - - -

as before - other app installs do connect......nRF Connect.
can do AT through Arduino IDE.
 
Upvote 0

rabbitBUSH

Well-Known Member
Licensed User
the only thing I did is adding this:

Nope that's not it : but is now is surely about not discovering the services - if one compares this with your log.

Found: Version-1.0, 50:65:83:6F:92:15, RSSI = -52, (MyMap) {1=[B@728675b, -1=[B@713ebf8, 9=[B@f3138d1, 18=[B@9eb0f36, 10=[B@17c1e37, 2=[B@897cfa4, 0=[B@6bf910d}
connecting
Disconnected

so, googled "not discovering services" and this B4X from 2014 showed up.

doesn't seem to help though.

[[ Heh Heh I finally worked out how to do unfiltered logs - I know I know - those pesky little check boxes we all miss or over look or just - lets not go there.]]

going through that now.
 
Upvote 0

rabbitBUSH

Well-Known Member
Licensed User
Worth checking the unfiltered logs.
Attached the unfiltered log.

I don't know which part would be useful to you - so I just zipped the whole thing feeling sure that you would go straight to where you need to.

At this point the failure seems to be in discovering/ reading the services - given the above discussion and response postings.
 

Attachments

  • unfiltered.zip
    15.9 KB · Views: 124
Upvote 0

rabbitBUSH

Well-Known Member
Licensed User
I saw this in the extended log :
onClientConnectionState() - status=133 clientIf=12 device=50:65:83:6F:92:15

that -133 seems / might relate to GATT as in GATT error 133.

found a long [heated] discussion about this - is been an ongoing thing for a long time apparently - GATT error code -133 - whole bunch of suggestions most of which i don't have the skills to tackle.

EDIT -> as I thought in an earlier posting -133 relates to (among other things :
When a connection times out, you will receive a connection update with status code 133. This is not the official error code for a connection timeout though .

from in this thread over there - - -
 
Upvote 0

rabbitBUSH

Well-Known Member
Licensed User
Upvote 0

rabbitBUSH

Well-Known Member
Licensed User
LEAPING SKUNKS 🥵🥶

If the transport issue is indeed the problem then I'll add it to BLE2.
This is not the problem. Its a bit more "to-the-left" of that.

Firstly, thanks to all who responded here ESPECIALLY @wes58 .

That said : I guess this is either the time to admit great embarrassment, or, issue huge apologies, or, both. 😶 perhaps bury my head in the sand and think these things happen - probably not though.

This is why, and this is hopefully a reasonable explanation of the "hitting air" that this thread will appear to have been.

This may not be the entire solution and/or reason for things. But, it might be the reason for some embarrassment. .!. - or whatever.

I had a brain-bang. I decided to load the example in release mode.
what made me think that - who knows - probably ultimate frustration.
Soooooo - don't know about this -- but 😤 And, I'm not sure what THE HECK.

now the thing connects! Another one for the bottom left corner shelf marked - THE MYSTERIES OF LIFE.

Here's my take on it - incidentally its using the library @wes58 updated and Connect3 from therein, but also works with Connect2 in Erel's internal BLE2.

So here's the thing I discovered With this module [DF Robot Bluno Beetle] Can't obviously vouch for whether this might be a thing with other modules - but maybe bear it in mind.

1. Don't run/load the code in DEBUG mode from the IDE. It won't work.
2. Don't turn this on #BridgeLogger = true Just don't set it at all. Bit of a pity but . . . it stopped working when I did that.
3. It looks like ANY sort of thing-in-the-middle ( as in 1 and 2 ) will cause it not to operate fully. It looks like it will hang in a sort of wait state for the debug or the IDE to do something - perhaps to do with some part of the logging process (?).

I am hoping that this will move forward now - especially after wasting a BUNCH of the valuable time around the world.

At this point all I can say is - APOLOGIES for running you around the goose chase with me. On the positive side - I learned a LOT from your messages - having started with BLE from scratch, whenever that was.

I hope that the rest of this will go better - the arduino side is not the problem its going to be how to get the data back across the BLE divide and what the storage capabilities of the BEETLE are - a new voyage begins. 🥵
 
Upvote 0
Top