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,287

Antti Mauranen

Member
Licensed User
Longtime User
Hello can you share it as library and example?

Yes, but that can take some time because of the Christmas time.

You can very easily compile the library with SimpleLibraryCompiler and you can see the new methods easily and they are used very much in the same way as the old one's.
 

John Lin

New Member
Licensed User
Longtime User
Many thanks to Erel & Antti sharing this library. It does great help for me.
But I have a question. Can i disconnect the BLE in my code? or only I can do by closing my APP.
Thanks your reply!
 

John Lin

New Member
Licensed User
Longtime User
I'm sorry, but I have tried many times. There is no Disconnect method on bleManager. Only an event "Disconnected".
Do I have something wrong??
 

sdujolo

Member
Licensed User
Longtime User
I'm sorry, but I have tried many times. There is no Disconnect method on bleManager. Only an event "Disconnected".
Do I have something wrong??

I think you have orginal version of BLE. I compiled it wiht other library name so I know it´s the right version.
 

John Lin

New Member
Licensed User
Longtime User
Thanks, sdujolo . I used the old version of BleExtend, After I download again and everything goes well.
Thanks for your advice.
 

avalle

Active Member
Licensed User
Longtime User
@Antti, great job!
I'm trying to write some data to a BLE peripheral and get a notification, but I'm struggling without documentation or samples...
Could you share a small example of using the methods and events that you added to the extended library?

@Erel I know I'm boring you asking for an update to the official BLE library, but given the growing interest in this area with more and more BLE-enabled devices out there this is becoming a must have in B4A. Is it in the plan for the next release? If not when?

I'm also interested to know if the instability/immaturity that you noticed in the earlier Android implementation (API 18) have improved in API 19.
 

avalle

Active Member
Licensed User
Longtime User
Finally I was able to get rid of the additional features of the BLE extended library. I'm now able to write data to my peripheral and to to register for a notification of a Characteristic and read the value from the Change event. I can post the code if anyone is interested.

However I have a strange behavior when writing data out to the BLE peripheral. Let's start from the code:
B4X:
Sub Button3_Click
   Log("Message " & x)
   manager.WriteCharacteristic(c)
End Sub

Sub ble_CharacteristicWrite (Success As Boolean, Characteristic As BleCharacteristic)
  If Success Then
      Characteristic.SetStringValue("Message " & x)
      x = x + 1
  End If
End Sub

When Button3 is pressed the Write method is called and let's say "Message 0" is logged.
The ble_CharacteristicWrite event is immediately fired but I don't get the data immediately at the peripheral.
As Button3 is pressed again I get "Message 1" in the log and finally I also get the old "Message 0" at the peripheral.
In practice it seems like the written data is hold in the app until the next Write is fired.

Am I doing something wrong or what is the intended way to Write data to get it in sync at the peripheral?
Thanks for your suggestions/comments.
 

riccf

Member
Licensed User
Longtime User
Finally I was able to get rid of the additional features of the BLE extended library. I'm now able to write data to my peripheral and to to register for a notification of a Characteristic and read the value from the Change event. I can post the code if anyone is interested.

However I have a strange behavior when writing data out to the BLE peripheral. Let's start from the code:
B4X:
Sub Button3_Click
   Log("Message " & x)
   manager.WriteCharacteristic(c)
End Sub
 
Sub ble_CharacteristicWrite (Success As Boolean, Characteristic As BleCharacteristic)
  If Success Then
      Characteristic.SetStringValue("Message " & x)
      x = x + 1
  End If
End Sub

When Button3 is pressed the Write method is called and let's say "Message 0" is logged.
The ble_CharacteristicWrite event is immediately fired but I don't get the data immediately at the peripheral.
As Button3 is pressed again I get "Message 1" in the log and finally I also get the old "Message 0" at the peripheral.
In practice it seems like the written data is hold in the app until the next Write is fired.

Am I doing something wrong or what is the intended way to Write data to get it in sync at the peripheral?
Thanks for your suggestions/comments.


Hello avalle

I also think BLE will become more used I trying to figure out this GATT profile a little better and I could use any snippet or code you could share, I'm struggling so I would appreciate if you post the code to read from the server chip.....
 

avalle

Active Member
Licensed User
Longtime User
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
 

Attachments

  • BLE send data.zip
    7.7 KB · Views: 813

riccf

Member
Licensed User
Longtime User
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

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

Hello
I have exactly the same setup ,same phone with mod for 4.4 , same module HM-10 trying to update the HC-06 but I just realized there's no SPP in 4.0 , I really appreciate you sharing I'll keep you updated.
 

avalle

Active 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.
 

Attachments

  • BLE Manager extended.zip
    9.1 KB · Views: 824

riccf

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.

Works, thank you , the range is not what I expected .
 

avalle

Active Member
Licensed User
Longtime User
Are you talking about the Beacon functionality? If that's the case I also had a wrong result using the HM-10 module with firmware V519.
I just discovered that V520 is available and it fixed that. Go to the manufacturer website to get it.
 

riccf

Member
Licensed User
Longtime User
Are you talking about the Beacon functionality? If that's the case I also had a wrong result using the HM-10 module with firmware V519.
I just discovered that V520 is available and it fixed that. Go to the manufacturer website to get it.
The firmware stabilized the reading... Do you know if you can control io on the HM-10 trough Bluetooth connection?
 
Top