I wanted to connect to the heart rate service of a watch , but with BLE2 library, it couldn't connect so I used the modified BLE library from here:
I was able to connect to the watch and I can see the Heart rate service in the log.
Please advice what can I do to get the heart rate service. Thank you
The relevant code is give below:
The relevant log is given below:
Is the error because of using modified BLE library? If so how to correct it? Thanks
I was able to connect to the watch and I can see the Heart rate service in the log.
However when I try to read the Heart Rate Service with(ArrayList) [00001801-0000-1000-8000-00805f9b34fb, 00001800-0000-1000-8000-00805f9b34fb, 6e400001-b5a3-f393-e0a9-e50e24dcca9e, 00001802-0000-1000-8000-00805f9b34fb, 0000d0ff-3c17-d293-8e48-14fe2e4da212, 0000180f-0000-1000-8000-00805f9b34fb, 0000180a-0000-1000-8000-00805f9b34fb, 0000180d-0000-1000-8000-00805f9b34fb, 00006287-3c17-d293-8e48-14fe2e4da212]
I am able to get the data in "nrfconnect" android App.manager.ReadData(HEART_RATE_SERVICE), I get error.
Please advice what can I do to get the heart rate service. Thank you
The relevant code is give below:
Heart rate service declared in Class_Globals:
Sub Class_Globals
Private Root As B4XView
................
Private HEART_RATE_SERVICE As String = "180D"
Private HEART_RATE_MEASUREMENT As String = "2A37"
Private firstRead As Boolean
Private bc As ByteConverter
End Sub
Device found code:
Sub Manager_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double)
Log("Found: " & Name & ", " & Id & ", RSSI = " & RSSI & ", " & AdvertisingData) 'ignore
'STYLE CALL is the internal name of the Watch
If Name.ToLowerCase.Contains("style") Then
ConnectedName = Name
manager.StopScan
Log("connecting")
#if B4A
manager.Connect3(Id,True,2)
#else if B4I
manager.Connect(Id)
#end if
End If
End Sub
This is the Error sub:
Sub Manager_Connected (services As List)
Log("Connected")
connected = True
ConnectedServices = services
StateChanged
firstRead = True
Log(services)
manager.ReadData(HEART_RATE_SERVICE)' Error java.lang.RuntimeException: Service not found
at anywheresoftware.b4a.objects.BleManager2.getService(BleManager2.java:418)
End Sub
The relevant log is given below:
discoverServices() - device: CB:56:00:0F:3E:99
onSearchComplete() = Device=CB:56:00:0F:3E:99 Status=0
Connected
(ArrayList) [00001801-0000-1000-8000-00805f9b34fb, 00001800-0000-1000-8000-00805f9b34fb, 6e400001-b5a3-f393-e0a9-e50e24dcca9e, 00001802-0000-1000-8000-00805f9b34fb, 0000d0ff-3c17-d293-8e48-14fe2e4da212, 0000180f-0000-1000-8000-00805f9b34fb, 0000180a-0000-1000-8000-00805f9b34fb, 0000180d-0000-1000-8000-00805f9b34fb, 00006287-3c17-d293-8e48-14fe2e4da212]
Error occurred on line: 207 (B4XMainPage)
java.lang.RuntimeException: Service not found
at anywheresoftware.b4a.objects.BleManager2.getService(BleManager2.java:418)
at anywheresoftware.b4a.objects.BleManager2.ReadData2(BleManager2.java:294)
at anywheresoftware.b4a.objects.BleManager2.ReadData(BleManager2.java:284)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA$2.run(BA.java:395)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6806)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
java.net.SocketException: Socket closed
at java.net.SocketInputStream.read(SocketInputStream.java:209)
at java.net.SocketInputStream.read(SocketInputStream.java:144)
Is the error because of using modified BLE library? If so how to correct it? Thanks