Hi,
I am using the Bluetooth Low Energy (BLE) library and trying to read values from the device I am connected to.
I have been able to connect to the device and was able to read the devices name but can't work out how to read the rest of the values.
When I connected to the device I have made it log each key like..
It then logs the following in the IDE:
00002a00-0000-1000-8000-00805f9b34fb
00002a01-0000-1000-8000-00805f9b34fb
00002a04-0000-1000-8000-00805f9b34fb
00002a07-0000-1000-8000-00805f9b34fb
00002a06-0000-1000-8000-00805f9b34fb
00002a06-0000-1000-8000-00805f9b34fb
00002a19-0000-1000-8000-00805f9b34fb
CR: true: 00002a00-0000-1000-8000-00805f9b34fb
cr: Alert_Device
I then changed the connected Sub to be:
and it now logs the following:
CR: true: 00002a00-0000-1000-8000-00805f9b34fb
cr: Alert_Device
I then changed the connected sub to be:
(this should get the battery status)
However when I run the app, it now logs the following in the IDE:
I can't seem to get the other values.
If I use the 'nRF Master Control' app (the app that come with the SDK board I am using) then it allows me to get this value from the device.
From what I understand it should get the battery status.
I can't work out how to get the values. Have I done something wrong ?
I am using the Bluetooth Low Energy (BLE) library and trying to read values from the device I am connected to.
I have been able to connect to the device and was able to read the devices name but can't work out how to read the rest of the values.
When I connected to the device I have made it log each key like..
B4X:
Sub BLE_Connected (Services As Map)
For Each s As BleService In Services.Values
For Each key As String In s.GetCharacteristics.Keys
Log(key)
Dim c As BleCharacteristic = s.GetCharacteristics.Get(key)
manager.ReadCharacteristic(c)
Next
Next
End Sub
Sub BLE_CharacteristicRead (Success As Boolean, Characteristic As BleCharacteristic)
Log("CR: " & Success & ": " & Characteristic.Uuid)
If Success Then Log("cr: " & Characteristic.GetStringValue(0))
End Sub
It then logs the following in the IDE:
00002a00-0000-1000-8000-00805f9b34fb
00002a01-0000-1000-8000-00805f9b34fb
00002a04-0000-1000-8000-00805f9b34fb
00002a07-0000-1000-8000-00805f9b34fb
00002a06-0000-1000-8000-00805f9b34fb
00002a06-0000-1000-8000-00805f9b34fb
00002a19-0000-1000-8000-00805f9b34fb
CR: true: 00002a00-0000-1000-8000-00805f9b34fb
cr: Alert_Device
I then changed the connected Sub to be:
B4X:
Sub BLE_Connected (Services As Map)
cs.Initialize
Dim s As BleService = Services.GetValueAt(0)
'Read the manufacturer characteristic
Dim c As BleCharacteristic = s.GetCharacteristics.Get("00002a00-0000-1000-8000-00805f9b34fb")
manager.ReadCharacteristic(c)
End Sub
and it now logs the following:
CR: true: 00002a00-0000-1000-8000-00805f9b34fb
cr: Alert_Device
I then changed the connected sub to be:
(this should get the battery status)
B4X:
Sub BLE_Connected (Services As Map)
cs.Initialize
Dim s As BleService = Services.GetValueAt(0)
'Read the battery staus
Dim c As BleCharacteristic = s.GetCharacteristics.Get("00002a19-0000-1000-8000-00805f9b34fb")
manager.ReadCharacteristic(c)
End Sub
However when I run the app, it now logs the following in the IDE:
B4X:
bluetoothservice_ble_connected (B4A line: 63)
manager.ReadCharacteristic(c)
java.lang.RuntimeException: Object should first be initialized (BleCharacteristic).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.BleManager.ReadCharacteristic(BleManager.java:142)
at b4a.example.bluetoothservice._ble_connected(bluetoothservice.java:170)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at anywheresoftware.b4a.BA$3.run(BA.java:334)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
I can't seem to get the other values.
If I use the 'nRF Master Control' app (the app that come with the SDK board I am using) then it allows me to get this value from the device.
From what I understand it should get the battery status.
I can't work out how to get the values. Have I done something wrong ?