Have a BLE module configured with a 128 bit Service UUID and a 128 bit write without reply characteristic, the unit has the name pump4. Using nRF connect I can reliably connect to it and write data to the characteristic.
To establish a connection with BLE2 I use Scan2
When Scan2 finds something it calls DeviceFound where I check to see if the device is pump4. If it is then I stop the scan and connect.
The logging then shows Connected... Discovering services. Then roughly half of the time immediately disconnects, I am not clear which end is disconnecting. On the occasions where it stays connected a request to read the RSSI is successfull suggesting the remote end is alive and talking.
What I then try to do is write to the remote characteristic using WriteData but I always get a Service not found error on the line containing the WriteData command.
From the device found sub I display the Name the Rssi and the ID, the reported ID is "E8 : EB : 1B : 9A : AF: DE" and I have to confess I have no idea where that number comes from . The real mystery however is having connected with the remote device why does it then report the service as not found ?
To establish a connection with BLE2 I use Scan2
B4X:
Public Sub StartScan
Dim serv As String
If manager.State <> manager.STATE_POWERED_ON Then
Log("Not powered on.")
Else
manager.Scan2(Null, False)
Log (serv)
End If
End Sub
When Scan2 finds something it calls DeviceFound where I check to see if the device is pump4. If it is then I stop the scan and connect.
B4X:
Sub Manager_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double)
Log(Name & ", " & Id &" " & RSSI)
ConnectedName = Name
remoterssi=RSSI
Labname.Text=Name
Labrssi.Text=remoterssi
LabRxdata.Text=Id
If Name="pump4" Then
manager.StopScan
manager.Connect(Id)
Else
StartScan
End If
End Sub
The logging then shows Connected... Discovering services. Then roughly half of the time immediately disconnects, I am not clear which end is disconnecting. On the occasions where it stays connected a request to read the RSSI is successfull suggesting the remote end is alive and talking.
What I then try to do is write to the remote characteristic using WriteData but I always get a Service not found error on the line containing the WriteData command.
B4X:
Private Sub ButSend_Click
Dim serveuuid As String = "f1abd2e4876c11eca8a30242ac120002 " 'UUID for Pump service
Dim txuuid As String = "f1abd4ce876c11eca8a30242ac120002" 'UUID for Pump Write characteristic
Dim dat As String = "7FFF"
manager.WriteData(serveuuid,txuuid,dat.GetBytes("utf8"))
End Sub
From the device found sub I display the Name the Rssi and the ID, the reported ID is "E8 : EB : 1B : 9A : AF: DE" and I have to confess I have no idea where that number comes from . The real mystery however is having connected with the remote device why does it then report the service as not found ?