Android Question Ble2, Receive Notify data but not Read or Read2 data

Steve-h

Member
If I configure the remote BLE device to Notify and SetNotify to true Data arrives in DataAvilable and I can successfully read it. If however I set the remote device to Read, remove the SetNotify and use either ReadData or ReadData2 nothing arrives in DataAvialable.

Using nRF Connect I can read the data as expected. Do I have to set or initialise something to enable ReadData ?

Presumably ReadData is as simple as :-

B4X:
Private Sub readvalue
    manager.ReadData2(serveuuid,flowuuid)
    Log("read flow")   
End Sub

And DataAvilable should work equally well for Notify and Read without any changes
B4X:
Sub Manager_DataAvailable (ServiceId As String, Characteristics As Map)
    Dim b() As Byte
If Characteristics.ContainsKey(flowuuid)Then    'seek value if flow
        b=Characteristics.Get(flowuuid)         'get value from map
        rxdata=(bc.HexFromBytes(b))                'convert to a string and put in rxdata variable
        Log ("rxdata "&rxdata)
    End If
    Log("DATA arrived")
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

Steve-h

Member
Thank you for your reply
If I insert the log line in data available it logs nothing, no data is arriving so it doesn't go there if I insert it just after the read instruction like this :-
B4X:
Private Sub readvalue
    manager.ReadData2(serveuuid,flowuuid)
    Log("read flow")   
    Log(manager.GetCharacteristicProperties(serveuuid, flowuuid))
End Sub

The log reports 2 at each attempt which presumably is the 2 I entered at the other end to define the characteristic as Read

Bizarrely while experimenting with the additional logging line it started reading the data correctly, It worked for about 4 seconds and disconnected, having reconnected 10 times after that that was just a one off but suggests to me that something is marginal.

One thing I am suspicious of is when connecting, the log shows Discovering Services twice and reports the RSSI twice
 
Upvote 0

Steve-h

Member
For Notify to work I have to change the BLE device Properties to 10 for Notify and change my code to call SetNotify. It is either one or the other, not both,

The odd thing is using nRF Connect and BLEscanner running on the same Android device I can reliably connect and read the data.

What seemed wrong to me is when connecting the logging showed :-
B4X:
Discovering services
Discovering services

Connected
Connected

I wonder if it was connecting twice, not certain if that can happen.

Using Connect2 with auto connect set to False results in the log only showing one Discovering services, one Connected and I now receive the data as expected so that seems to have resolved it but without completely understanding why.
 
Upvote 0
Top