B4A Library [B4X] BLE 2 - Bluetooth Low Energy

Status
Not open for further replies.

Turbo3

Active Member
Licensed User
Longtime User
The device that works report 0x1A for the property. The one that hangs waiting for a response reports 0x3A for the property. Could that make a difference?

Both these devices work fine with iBLE 1.31.
 

Turbo3

Active Member
Licensed User
Longtime User
Basically the same line of code for both B4i and B4A.
B4X:
B4i: manager.WriteDataWithResponse(CurService,CurCharWrite,ATCmdOut.GetBytes("UTF8"))
B4A: Starter.manager.WriteData(Starter.CurService,Starter.CurCharWrite,ATCmdOut.GetBytes("UTF8"))

Could you add the WriteDataWithResponse to B4A just to see if forcing it makes a difference?
 

Turbo3

Active Member
Licensed User
Longtime User
Erel, Can you please add two additional WriteData commands, one WithResponse and another WithoutResponse. That way I can test and see if either of those writes work. If not then the problem is somewhere else.
 

KY Leng

Active Member
Licensed User
Longtime User
Good evening Erel,

In the previous version of BleExtEx (version: 1.10), we can read/write data (serial data from/to BLE device) by using

'Read:
Sub Manager_CharacteristicChanged (Characteristic As BleCharacteristic)
Dim StrIn As String
StrIn = Characteristic.GetStringValue(0)
Log(" RxD <" & StrIn & ">")
End Sub

'Wite:
cwrite.SetStringValue(StrOutBT)
Manager.WriteCharacteristic(cwrite)

With this new BLE2 (version: 1.10), could you please tell us how to do it?
Note: The reason I move from BleExtEx to BLE2 is that BleExtEx could not allow Nexus Android Version 6.0.1 to find BLE device.
And it seem that all Android Version 6.0.1 could not find BLE device with EleExtEx library.

Looking forward to hearing from you soon...
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
@KY Leng see this tutorial: https://www.b4x.com/android/forum/threads/ble-bluetooth-low-energy-library.46099/#content
For further help please start a new thread.


@Turbo3 Replace the existing jar with the one attached (copy it to the internal libraries folder).
It allows getting the characteristics with JavaObject:
B4X:
Dim jo As JavaObject = BleManager1
Dim ser As JavaObject = jo.RunMethod("getService", Array(ServiceId))
Dim chrc As JavaObject = jo.RunMethod("getChar", Array (ser, CharacteristicId))
chrc.RunMethod("setWriteType", Array (2)) '2 = with response, 1 = no response
'... now  call the regular Write method.
 

Attachments

  • BLE2.jar
    11.6 KB · Views: 659

Turbo3

Active Member
Licensed User
Longtime User
By "internal libraries folder" I assume you mean the Libraries folder under Basic4android where the current BLE2.jar was located.

With the new BLE2.jar JavaObject is an unknown type.

==================

Never mind. I needed to enable the JavaObject library.

I will test in the morning.
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
By "internal libraries folder" I assume you mean the Libraries folder under Basic4android where the current BLE2.jar was located.
and where the core.jar are located, yes.

The INTERNAL is the Libraries folder in b4a program path
The Additional Libraries folder is the one you setup in b4a Paths.
 

Turbo3

Active Member
Licensed User
Longtime User
No luck. I can see the adapter light flash indicating it has received the command from the WriteData but I never get a response back.

If I switch back to the adapter that works it continues to work for both the 1 and 2 settings for SetWriteType. I expected it to fail with the 1 settings of no response. So that makes me think the 1 settings is not actually working.

Can you add a debug message when you execute the WriteData that says which type it is actually using?
 
Last edited:

Turbo3

Active Member
Licensed User
Longtime User
Then just a log message that the WriteType has been changed by this new "SetWriteType".

What else could be stopping the response from one adapter and not the other? Both adapters work fine in B4i.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Then just a log message that the WriteType has been changed by this new "SetWriteType".
B4X:
log(chrc.RunMethod("getWriteType", Null))


What else could be stopping the response from one adapter and not the other? Both adapters work fine in B4i.
Hard to say. The first step is to try to check it with a different Android device.
 

Turbo3

Active Member
Licensed User
Longtime User
Just checked with two different Android devices. Same problem. One running 4.4.2 the other Fire OS 4.5.5

One adapter (LELink) works for both Type 1 or Type 2.

The other (Vgate iCar 3) flashes when sent a command but I never get any data back. Both a Type 1 or 2 setting fails.

So the SetType makes no difference on Android but it does on iOS.
 
Last edited:

KY Leng

Active Member
Licensed User
Longtime User

Now I can solve my problem by using BLE2 instead of BluetoothAdmin to scan BLE device. And use BleExtEx to send/read data to/from BLE device (HM-10). Data that I mentioned here is the same serial data that we send using Serial library with Bluetooth 2 device (HC-05).

However, I want to know if BLE2 can do the same (send/read data to/from HM-10 with TxD/RxD pin) with BLE device as Serial do with BT2 device or not ? With BleExtEx, we can do but with limited byte per frame (maybe 20 byte max).
 
Last edited:

stari

Active Member
Licensed User
Longtime User
Hi,
i also work with HM-10 and i can send/receive data. On other side i have connected PIC P18F45K22 and also without any problem.
I'ts true, 24 bytes per frame is max.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…