The same problem.
Only search.
But without connect and read charateristic
Dear Erel
I have a same problem, search, connect but can not read characteristic
The same problem.
Only search.
But without connect and read charateristic
What is the output of Log("Services = " & Services)?
Dim c As BleCharacteristicCall it before you call manager.ReadCharacteristic (which throws an error if I understand correctly).
Dear merlin2049erhmm, still. The characteristics property type are of type [notify]. I can't read them (that's why it's returning false).
Hi Erel, i just started playing around with Bluetooth BLE, and i'm having some issues trying to read some of the characteristics on this device I have. The device is a Glucose Monitor, the Model is GL50 Evo and is manufactured by Beurer Medical.Android 4.3 adds support for Bluetooth Low Energy. This library allows you to access the new API. It allows you to search for BLE devices, connect to a device and read its services and characteristics.
Writing is currently not supported though it should be simple to add this feature.
From my testings BLE is not yet ready for production
It is unreliable. I also tested it with Google example app and the results were the same.
Seems like others have encountered such issues as well:
http://code.google.com/p/android/issues/detail?id=58381
http://stackoverflow.com/questions/17870189/android-4-3-bluetooth-low-energy-unstable
In order to use this library you will need to download platform level 18 from Android SDK and configure the IDE (Tools - Configure Paths) to use it.
Simple code that starts searching when you click on the activity:
B4X:Sub Process_Globals Dim manager As BleManager Private cs As List End Sub Sub Globals 'These global variables will be redeclared each time the activity is created. 'These variables can only be accessed from this module. End Sub Sub Activity_Create(FirstTime As Boolean) If FirstTime Then manager.Initialize("ble") Log("Supported: " & manager.BleSupported) End If End Sub Sub Activity_Click Log("Searching for devices") manager.Scan(10000, Null) End Sub Sub ble_DeviceFound (Name As String, MacAddress As String) Log(Name & ", " & MacAddress) manager.Connect(MacAddress, True) End Sub 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 Sub BLE_CharacteristicRead (Success As Boolean, Characteristic As BleCharacteristic) Log("CR: " & Success & ": " & Characteristic.Uuid) If Success Then Log("cr: " & Characteristic.GetStringValue(0)) End Sub Sub ble_Disconnected Log("Disconnected") End Sub Sub ble_DiscoveryFinished Log("DiscoveryFinished") End Sub
** Activity (main) Create, isFirst = true **
Supported: true
** Activity (main) Resume **
Searching for devices
Beurer GL50EVO, F4:04:4C:0C6:58
Discovering services.
services map size: 5
00001800-0000-1000-8000-00805f9b34fb android.bluetooth.BluetoothGattService@3bcefae6
00001801-0000-1000-8000-00805f9b34fb android.bluetooth.BluetoothGattService@3b771827
0000180a-0000-1000-8000-00805f9b34fb android.bluetooth.BluetoothGattService@303b5ad4
00001808-0000-1000-8000-00805f9b34fb android.bluetooth.BluetoothGattService@32ea747d
0000fff0-0000-1000-8000-00805f9b34fb android.bluetooth.BluetoothGattService@32ffdf72
s: (BluetoothGattService) android.bluetooth.BluetoothGattService@3bcefae6
main_timer1_tick (B4A line: 109)
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 com.genesis.evo.main._timer1_tick(main.java:608)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5297)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
java.lang.RuntimeException: Object should first be initialized (BleCharacteristic).
manager.ReadCharacteristic(c)
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim manager As BleManager
Private cs As List
Dim timer1 As Timer
Dim map1 As Map
Dim c As BleCharacteristic
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
If FirstTime Then
manager.Initialize("ble")
Log("Supported: " & manager.BleSupported)
End If
timer1.Initialize("timer1", 1000)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Activity_Click
Log("Searching for devices")
manager.Scan(10000, Null)
End Sub
Sub ble_DeviceFound (Name As String, MacAddress As String)
Log(Name & ", " & MacAddress)
manager.Connect(MacAddress, True)
End Sub
Sub BLE_Connected (Services As Map)
cs.Initialize
Log("services map size: " & Services.Size)
map1 = Services
For i = 0 To Services.Size - 1
Log(Services.GetKeyAt(i) & " " & Services.GetValueAt(i))
Next
Dim s As BleService = Services.GetValueAt(0)
'get the glucose readings
c = s.GetCharacteristics.Get("00001800-0000-1000-8000-00805f9b34fb")
timer1.Enabled = True
End Sub
Sub BLE_CharacteristicRead (Success As Boolean, Characteristic As BleCharacteristic)
Log("CR: " & Success & ": " & Characteristic.Uuid)
If Success Then
Log("cr0: " & Characteristic.GetStringValue(0))
End If
End Sub
Sub ble_Disconnected
Log("Disconnected")
End Sub
Sub ble_DiscoveryFinished
Log("DiscoveryFinished")
End Sub
Sub timer1_Tick
manager.ReadCharacteristic(c)
timer1.Enabled = False
End Sub
Thanks Erel, I've started a new thread, hopefully i can get some answers.Start with this post: https://www.b4x.com/android/forum/threads/get-values-from-device-using-ble.57758/#post-363602
If it doesn't help then please start a new thread (and post the result of that code).