Hi,
I'm trying to communicate (both read & write) with a BLE device that we have created using the Nordic Semiconductor nrf51822 BLE chip. It works perfectly fine using the Nordic's sample java app. I can read as well as write to the BLE device. However, I'm not a java person so I'm trying to use the B4A to develop an app.
I saw that there is a BLE library which doesn't support write. So I tried using the BLEextended library. I'm using the library from post#17 and example from post#13. I'm able to read the data from BLE device as expected. However, I'm unable to write any data back to the device. The BLE device has multiple characteristics & one is used for reading and another for writing. The Log(s.GetCharacteristics) returns the following info:
(MyMap) {6e400003-b5a3-f393-e0a9-e50e24dcca9e=android.bluetooth.BluetoothGattCharacteristic@42beee90, 6e400002-b5a3-f393-e0a9-e50e24dcca9e=android.bluetooth.BluetoothGattCharacteristic@42bef460}
The 6e400002-b5a3-f393-e0a9-e50e24dcca9e is the UUID for the read characteristics (which works fine) & 6e400003-b5a3-f393-e0a9-e50e24dcca9e is the UUID for write characteristic which I'm not able to get it working still.
I've modified the ble_Connected & Button3_Click subs in post#13 as follows:
Sub ble_Connected (Services As Map)
Dim n As Int
Log("Connected")
Button1.Enabled = True
Button2.Enabled = False
n = 2 'Service 0000ffe0-0000-1000-8000-00805f9b34fb (serial data transfer on HM-10 module)
s = Services.GetValueAt(n) ' Change index to access other Services
Log("Service[" & n & "]: " & Services.GetKeyAt(n)) ' Log the UUID of the selected Service
' Read the manufacturer characteristic
c = s.GetCharacteristics.GetValueAt(0) 'this returns the UUID for read characteristic
d = s.GetCharacteristics.GetValueAt(1) '<----- added - this returns the UUID for write characteristic
Log(s.GetCharacteristics)
Log("Charact[0]: " & c.Uuid)
Log("Charact[1]: " & d.Uuid) '<----- added
manager.ReadCharacteristic(c)
manager.SetCharacteristicNotification(c, True) 'Define a Notification to get data from HM-10 via Changed event
End Sub
Sub Button3_Click 'Send data to HM-10
Log("Message " & x)
manager.WriteCharacteristic(d) '<--- changed argument to d (from c)
End Sub
When writing data, the app crashes with a message "Unfortunately Bluetooth Share has stopped".
Can someone more knowledgeable than me please help?