Android Question BLE2 Library Sending Data

BarryW

Active Member
Licensed User
Longtime User
How to send data data using BLE2 Library. Can someone post a simple sample code. Tnx.
 

dagnabitboy

Active Member
Licensed User
Longtime User
This is where I started: https://www.b4x.com/android/forum/threads/ble-2-bluetooth-low-energy.59937/

I've also attached a development app I created while learning to communicate with an RN4020 BLE device. I'm using it's MLDP mode (a so called SPP equivalent) so it's a little different from communicating with standard BLE devices, but it should give you some ideas to start with. Also, BLE has a 20 byte max limit on write transfers. In my app I use the write complete event to send data in chunks of 20 bytes if necessary, so I can send more or less continuous streams if I need to. If you look at "Manager_Disconnected" you'll see I do retries. I was getting disconnect events without a connect. Doing a connect retry solved the problem. I don't know if it's something odd with BLE itself, or the RN4020 module. You may not have this issue.

Good luck!
 

Attachments

  • chat.zip
    178.6 KB · Views: 351
Upvote 0

BarryW

Active Member
Licensed User
Longtime User
Thanks so much for your reply sir. I will read your code later. I'am using bluno bettle as my BLE module.

I tried using their sample from here. Also i got getting disconnected without doing anything. For the data length i just need to pass 1 or 0 to trigger job of bluno bettle. Again sir thanks.
https://www.dfrobot.com/blog-283.html
 
Upvote 0

BarryW

Active Member
Licensed User
Longtime User
Sir where did you get this items:

B4X:
    'Private Service For Microchip MLDP
    Private MLDP_PRIVATE_SERVICE As String = "00035b03-58e6-07dd-021a-08123a000300"
    'Characteristic For MLDP Data, properties - notify, write
    Private MLDP_DATA_PRIVATE_CHAR As String = "00035b03-58e6-07dd-021a-08123a000301"
 
Upvote 0

dagnabitboy

Active Member
Licensed User
Longtime User
Originally I got those from another example that I started with I found here on this forum. Scroll down a bit to find a zip file from member ac9ts. https://www.b4x.com/android/forum/threads/ble-communication-problem.62461/#post-394784
https://www.b4x.com/android/forum/threads/ble-communication-problem.62461/#post-394784
In the case of the RN4020 MLDP mode they are available from Microchip as well. I also used another app: BLE Scanner that can read the public and private UUIDs of a device. I've attached a screen cap of the RN4020 characteristics from that app.
 

Attachments

  • Screenshot_20170920-100104.png
    Screenshot_20170920-100104.png
    189.5 KB · Views: 262
Upvote 0
Top