Android Question Bluetooth 4.0 data exchange

red30

Active Member
Licensed User
I have a microcontroller to which the Bluetooth HC-08 (Bluetooth 4.0) module is connected. I want to exchange data, but I have not found a single example on the forum. I need to work exactly with Bluetooth 4.0. How can i do this?
I found the program Serial Bluetooth Terminal. Can I do the same with b4a?

I tried this example. I get the error: java.io.IOException: read failed, socket might closed or timeout, read ret: -1

I found the program from the official manufacturer, it works fine with this bluetooth module.
 

Attachments

Last edited:

red30

Active Member
Licensed User
My Bluetooth module works in slave mode. I tried BleCEntral_B4A, but there is eternal "trying to connect" on the screen. Whats wrong?
 

red30

Active Member
Licensed User
I tried this one BLE_Example. also. It finds my Bluetooth module but there is no example of exchange as in Android Bluetooth / BluetoothAdmin Tutorial. Moreover, it searches for the nearest module but if there are several of them? I d like to have a list as in Android Bluetooth / BluetoothAdmin Tutorial, so I could choose and then have a data exchange.
 

Erel

Administrator
Staff member
Licensed User
t finds my Bluetooth module but there is no example of exchange as in Android Bluetooth / BluetoothAdmin Tutorial
I will repeat: You need to learn a bit about BLE. BLE doesn't work like classic Bluetooth. You need to implement the specific protocol of your peripheral device.

I d like to have a list as in Android Bluetooth / BluetoothAdmin Tutorial
See the code in Manager_DeviceFound.
 

red30

Active Member
Licensed User
I can not understand when the data comes where they go? And how to send data from an android device?
Another question: I have a tablet (Bluetooth 4.0). I use program BLE_Example, but when I press Scan & Connect, the tablet does not find more than one device, although other programs on this tablet work fine and see 4.0 devices. What could it be?
 
Last edited:

red30

Active Member
Licensed User
When I use program BLE_Example, when I press button Read Data, I get this:
Screenshot_20190226-161808.png
Screenshot_20190226-161816.png
Screenshot_20190226-161830.png
Can someone explain how to transfer and receive data from the Bluetooth module? I could not find more than one topic where it was explained. Sorry if I do not understand something ...
 

emexes

Well-Known Member
Licensed User
I used the free app BLE UUID Explorer to identify and explore my test device. Once I knew that the device was working ok, and what its address, services and characteristics were, then reading it using the BLE2 library worked first go (except for reading a descriptor, but apparently not many people need to do that).

Get the data reading bit going first. This is much easier if you know what you're looking for, and that the device is alive and working and works with the BLE of your Android device. We discovered the hard way that just because a phone or tablet has "Bluetooth 4" or "4.0" or "4.2" etc, doesn't mean that it supports BLE. There is an app "BLE Checker" that will give you a 95% reliable indication of whether your Android Device properly supports BLE.

After your app is up and running for your particular test device, then you can add a selection screen to your app that identifies those devices more generally during the BLE scan process, using the name and the advertising data, and gives your app user a list of available compatible devices from which they can choose the one they want to use.
 

emexes

Well-Known Member
Licensed User
This is the nRF Connect doing a scan for BLE device advertisements. BLE UUID Explorer and BLE Analyser apps show similar lists but in different formats. On this list I can see one of the pressure sensors I've been testing with (name is 63472) and I tried connecting to it to show you what type of information you're looking for, but... it's out in the car in the driveway and apparently just out of radio reach, and I'll disturb too many people if I go get it right now. You'll be ok, though - grab those apps or similar, and start scanning, you might be surprised at how much BLE stuff is around you (at least, I was - eg, my teenage son is a walking Bluetooth cloud, what with his phone and watch and earbuds and tablet...)


upload_2019-2-27_3-58-47.png
 

red30

Active Member
Licensed User
Thank you very much for such a comprehensive explanation, but I need to work with one of my devices. This is the bluetooth module HC-08, that is connected to my microcontroller. I know its name, its address, I understand how among all the devices to find him and connect to it using the library BLE2. I used the application that gives the manufacturer of this module (it is attached in post # 1), and it works great on any device with support for Bluetooth from version 4.0. I do not understand why one tablet does not see this device through an example for BLE2. Just do not see it and everything. At the same time, another tablet (which is practically the same) sees it and connects to it. I can read the data (listed in post # 8), but I do not understand what it is and how to work with it. I wanted to realize the transmission and reception of data from an android device as with a library of classic bluetooth, where everything was just to send data, I just turned to AStream.Write, and the resulting data fell into AStream_NewData. But I can not draw any analogy with BLE2. Can anyone explain how to do this simply and clearly? Any example can, I will be glad to any information!!
Sorry for my bad english.
 

emexes

Well-Known Member
Licensed User
We bought tablets that specs say are Bluetooth 4.0 and 4.2 compatible, and turns out they don't support BLE. Then I spent an hour with Samsung trying to pin down which of their tablets support BLE, and it was like trying to round up sheep ;-/

Perhaps "practically the same" is not as same as the specs might suggest.

Have you run the BLE Checker on both tablets? And if both tablets say yes, can nRF Connect see nearby BLE devices on both tablets?

Once we know if, or which of, your Android devices work with BLE, then we'll wade into the software.
 

emexes

Well-Known Member
Licensed User
The application from the manufacturer (attached in post #1) - does *that* work on *both* of your practically-the-same tablets? As in, can you see changing readings coming from your hardware?
 

red30

Active Member
Licensed User
Have you run the BLE Checker on both tablets? And if both tablets say yes, can nRF Connect see nearby BLE devices on both tablets?
I can only do this tomorrow. At 8 am Moscow time.
As soon as I check the devices using these programs, I will immediately write! Thank you for help!
 

red30

Active Member
Licensed User
The application from the manufacturer (attached in post #1) - does *that* work on *both* of your practically-the-same tablets? As in, can you see changing readings coming from your hardware?
Yes, using this program, I can receive and send messages on both tablets (this program works as a terminal).
 

emexes

Well-Known Member
Licensed User
Super, although the word "terminal" makes me wonder whether they are communicating with Bluetooth Low Energy or with Bluetooth Classic (BR/EDR). The two are not the same, nor compatible with each other. The B4A BLE2 library only works for Bluetooth Low Energy.

https://en.wikipedia.org/wiki/Bluetooth_Low_Energy#Compatibility

So, the next step is to use the BLE Checker app to confirm that the Android devices support BLE, and then to use nRF Connect or BLE UUID Explorer to scan and find and connect your hardware and read a value.

I do not understand why one tablet does not see this device through an example for BLE2. Just do not see it and everything. At the same time, another tablet (which is practically the same) sees it and connects to it.
I read this as: you've successfully communicated with your hardware using B4A+BLE2 from one of your Android devices ("sees it and connects to it") but not the other ("do not see it"). Have I understood this correctly, or are we talking about other software?
 

red30

Active Member
Licensed User
Have you run the BLE Checker on both tablets? And if both tablets say yes, can nRF Connect see nearby BLE devices on both tablets?
Both devices support BLE.
Screenshot_20190227-073459.png Screenshot_20190227-073637.png Screenshot_20190227-073715.png
I read this as: you've successfully communicated with your hardware using B4A+BLE2 from one of your Android devices ("sees it and connects to it") but not the other ("do not see it"). Have I understood this correctly, or are we talking about other software?
No, the application on both devices is the same, this is B4A + BLE2.
I did this:
B4X:
Sub Manager_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double)
    Log("Found: " & Name & ", " & Id & ", RSSI = " & RSSI & ", " & AdvertisingData) 'ignore   
    If Name="HC-08-TEST" Then
        ConnectedName = Name
        manager.StopScan
        manager.Connect2(Id, False) 'disabling auto connect can make the connection quicker
    End If
End Sub
One device finds it and connects, and the other one can't even find it.
 
Last edited:

red30

Active Member
Licensed User
I do not understand how this happened, but now the second one is also normally found and connected to the bluetooth HC-08!
Perhaps it was the lack of any permission...
But still, the question remains how do I transfer data? How to send and receive?
 
Last edited:

emexes

Well-Known Member
Licensed User
Yeah, stuff like that happens. If they are BLE, then usually a device can only handle one connection at a time, and so if you tested the two Android devices one-after-the-other, without closing the connection on the first one, then the second one might not see it for a couple of minutes.

So, the next step is to ... use nRF Connect or BLE UUID Explorer to scan and find and connect your hardware and read a value.
I know I'm sounding like a cracked record here, but I've already used up my going-down-the-wrong-track quota for the year. Once you're able to read your hardware over BLE using a known-working app, then I'll clean up my test code and send it to you.

:)
 
Top