B4A Library BleExtended

Hello,

I made some additions into Ble Library (write, notifications) and Erel asked me to post the extended library here. I made those additions to get my prototype working, so it is not necessarily of production quality but anayway works well for me just now.

I use this library exactly as the original one (+ additons of course) and I compile it with SimpleLibraryCompiler. It has same name and version number as the original.

The library source code is in the zip file.
 

Attachments

  • BleManager.zip
    3.5 KB · Views: 1,195

avalle

Active Member
Licensed User
Longtime User
Yes you can, but you need to put the HM-10 in either PIO Collection or Remote Control mode so that it can accept AT commands via Bluetooth to control the HM-10. PIO Collection is used to read from PIO 04 to 11 used as inputs and to write to PIO 2 and 3 used as outputs, while Remote Control is used to write to PIO 2 to 11 all used as outputs.

But... I think we're going out of thread...
 

alex yee

Member
Licensed User
Longtime User
HI , I am using Moto G with Ti CC2540, following the ble send data , still I need to press the button two times to send out the data, also I found the data must be 0 to 127 , chr(0) to chr(127). Can we use full range chr(0) to chr(255). I use ble extended library with API 19
Also I found if the BLE character is write only properties, it will fail and quit out without warning. Seems I must do ble_readcharacter before ble_writecharacteristic.
Any update ble library
 
Last edited:

wantlin

Member
Licensed User
Longtime User
HI Antti Mauranen
I have problem for BLE Library , please help me . For your share the Library , I need to read the RSSI value . Do you know how read the value ?
Please help me . Thank you !
 

alex yee

Member
Licensed User
Longtime User
HI , I am using Moto G with Ti CC2540, following the ble send data , still I need to press the button two times to send out the data, also I found the data must be 0 to 127 , chr(0) to chr(127). Can we use full range chr(0) to chr(255). I use ble extended library with API 19
Also I found if the BLE character is write only properties, it will fail and quit out without warning. Seems I must do ble_readcharacter before ble_writecharacteristic.
Any update ble library
I can manage to add characteristic.setintValue into the ext. lib instead of using setstringvalue. And everything works well. Still strange that I must do read before I write and also must write twice in initital so that CC2540 can receive the data.
I am using acelerometer , I can manage to set notification, but how do I get three notification data? The ble_CharacteristicChange only show back one notification data, I need to get back x, y, z axis notification data.
Thanks
 

alex yee

Member
Licensed User
Longtime User
I have fixed the notification and get back 3 notification data , just add three if .. then to detect the characteristic value change.To connect 4 devices, we need to scan and connect one by one, cannot scan by 4 ble manager at the same time.
 

ishangchao

Member
Licensed User
Longtime User
Hi, I have a problem,when I use the bleextend lib, why the write and read method do not work,but the change event do work . Anyone can help me.?
 

avalle

Active Member
Licensed User
Longtime User
Hi, I have a problem,when I use the bleextend lib, why the write and read method do not work,but the change event do work . Anyone can help me.?
Have you tried my example posted in msg #13 and using the library I posted in #17 ?
 

ishangchao

Member
Licensed User
Longtime User
[qaote="avalle, post: 269738, member: 18148"]Have you tried my example posted in msg #13 and using the library I posted in #17 ?[/quote]
Have you tried my example posted in msg #13 and using the library I posted in #17 ?
thanks avalle, yes , i use your bleextend and your send data example posted last page, but when i use the method read and write method,the ble read and write event can not be fired,but the change event can work,why? i need your help ... thanks
Have you tried my example posted in msg #13 and using the library I posted in #17 ?
 

ishangchao

Member
Licensed User
Longtime User
[qaote="avalle, post: 269738, me. mber: 18148"]Have you tried my example posted in msg #13 and using the library I posted in #17 ?

thanks avalle, yes , i use your bleextend and your send data example posted last page, but when i use the method read and write method,the ble read and write event can not be fired,but the change event can work,why? i need your help ... thanks[/quote]
yes,i think so, i use the#13 and #17 lib and example you posted.
 
Last edited:

ishangchao

Member
Licensed User
Longtime User
I think API 18+ is enough (Android 4.3) but linking the latest is definitely better.

I've attached the BLE library that I'm using, based on Antti's work and compiled with API 19 SDK.
Hope it helps go through my sample code.
Hello riccf, here is the full project that I am currently testing. I am using my Galaxy SIII running Cyanogen 11 (Android 4.4) as Central unit and a HM-10 BLE module as Peripheral.
To test this you have to connect the HM-10 to a serial port (either a microcontroller or a PC through a FTDI adaptor or similar to convert the serial port to USB) and a terminal emulator like Real Term or Tera Term.

Please let me know if you're able to test and if you can learn something new.

-Andrea
thanks, i test this
Hello riccf, here is the full project that I am currently testing. I am using my Galaxy SIII running Cyanogen 11 (Android 4.4) as Central unit and a HM-10 BLE module as Peripheral.
To test this you have to connect the HM-10 to a serial port (either a microcontroller or a PC through a FTDI adaptor or similar to convert the serial port to USB) and a terminal emulator like Real Term or Tera Term.

Please let me know if you're able to test and if you can learn something new.

-Andrea
thanks, i test this example, but why the read and write event do be fired and work, but the change event can work?
 

ishangchao

Member
Licensed User
Longtime User
Helo avalle, I use your example posted in msg #13 and using the library I posted in #17, But Why the manager.WriteCharacteristic(c) and manager.ReadCharacteristic(c) function can not fire the event of ble_CharacteristicWrite and ble_CharacteristicRead, But the event of ble_CharacteristicChange can work, I am very confused, I need your help! thanks
 

avalle

Active Member
Licensed User
Longtime User
Helo avalle, I use your example posted in msg #13 and using the library I posted in #17, But Why the manager.WriteCharacteristic(c) and manager.ReadCharacteristic(c) function can not fire the event of ble_CharacteristicWrite and ble_CharacteristicRead, But the event of ble_CharacteristicChange can work, I am very confused, I need your help! thanks
You didn't mention what kind of BLE devices you're using (both smartphone and device).
Also are you sure that you're using the right characteristics?
Did you test your setup with any working BLE test app?
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
Hello,

I made some additions into Ble Library (write, notifications) and Erel asked me to post the extended library here. I made those additions to get my prototype working, so it is not necessarily of production quality but anayway works well for me just now.

I use this library exactly as the original one (+ additons of course) and I compile it with SimpleLibraryCompiler. It has same name and version number as the original.

The library source code is in the zip file.


Where do you put this java file?
 

DDL

Member
Licensed User
Longtime User
Hi. I just started using B4A. I want to connect a Samsung Galaxy S5 with a WICED Sense kit. I can connect using the demo WICED app from Broadcom. I can connect using either Erel's original library or avalle's extended library. However, when I try
c = s.GetCharacteristics.Get("00001801-0000-1000-8000-00805f9b34fb"), I get an error message "java.lang.RuntimeException: Object should first be initialized (BleCharacteristic)." Not sure which object is not initialized. I'm using the example code that Erel and avalle had so kindly provided. Thanks.
 
Last edited:

DDL

Member
Licensed User
Longtime User
Using the example code: "Dim s As BleService = Services.GetValueAt(0)"
Log(s.GetCharacteristics) outputs "(MyMap) {}".
If I get the value for what's supposed to be the battery service "Services.GetValueAt(4)"
Log(s.GetCharacteristics) outputs "(MyMap) {00002a19-0000-1000-8000-00805f9b34fb=android.bluetooth.BluetoothGattCharacteristic@434b8128}".
Setting c = s.GetCharacteristics.Get("00002a19-0000-1000-8000-00805f9b34fb")
Log(c.GetValue) outputs null
manager.ReadCharacteristic(c) generates java.lang.NullPointerException
I then set a delay before calling manager.ReadCharacteristic(c) and now I get expected values.

Thanks.
 
Last edited:

Denny Hopp

Member
Licensed User
Longtime User
Hello. I have the ReadCharacteristic in BLE working fine. However, whenever I try to write with writeCharacteristic I get the following error:
Fatal Signal 11 (SIGSEGV) at 0x00000008 (code=1), thread 16391 (Binder_2).

I am using the BLEExtended library that was posted in January 2014. Any ideas? Does anyone have a writeCharacteristic example? Thanks for the help!
 

avalle

Active Member
Licensed User
Longtime User
I am using the BLEExtended library that was posted in January 2014. Any ideas? Does anyone have a writeCharacteristic example? Thanks for the help!

Did you also try my sample posted in msg #13 in this thread? It shows how to use writeCharacteristics.
 

Denny Hopp

Member
Licensed User
Longtime User
Hi avalle -- I did try it a few minutes ago and it is working great. I owe you a beer! The only thing I am finding is that if I read right after writing, the value is not updated. It seems like it takes two writes to get the value through.
 
Top