B4i Library BLE (Bluetooth Low Energy) library

D

Deleted member 103

Guest
Hi,

I can connect this keyboard with the iPhone and it works with the installed apps.
With this BLE-example, but does not work, why?
The keyboard is not found.
 

andreahaku

Member
Licensed User
Longtime User
BLE is not Bluetooth. It is based on Bluetooth and it's part of Bluetooth 4.0 but it's a different things. BLE devices are different than Bluetooth ones and vice versa. So a bluetooth keyboard can't be connected using BLE.
 

vincentehsu

Member
Licensed User
Longtime User
Dear Sir:
is there any sample code with wirtedata? i don't know how to get the response from bt device
 

vincentehsu

Member
Licensed User
Longtime User
the second parameter characteristic is the bt mac address?I always receive error as below

B4X:
Dim TriggerPayment() As Byte=Array As Byte(0, 2, 242, 242)
    manager.WriteData(AStream_NewData,TerminalID,TriggerPayment)

Sub AStream_NewData ()
    If AStreamType=1 Then
        Dim TagData As String=""
        Dim i As Int
'        For i=0 To Buffer.Length-1
'            TagData=TagData & IIF(Len(Bit.ToHexString((Bit.AND(Buffer(i),0xFF))))=1,"0" & Bit.ToHexString((Bit.AND(Buffer(i),0xFF))),Bit.ToHexString((Bit.AND(Buffer(i),0xFF))))
'        Next
        lbl_Parameter1.Text=Mid(TagData,135,2)
        lbl_Parameter2.Text=Mid(TagData,137,2)
    Else If AStreamType=2 Then
        Dim TagData As String=""
        Dim i As Int
'        For i=0 To Buffer.Length-1
'            TagData=TagData & IIF(Len(Bit.ToHexString((Bit.AND(Buffer(i),0xFF))))=1,"0" & Bit.ToHexString((Bit.AND(Buffer(i),0xFF))),Bit.ToHexString((Bit.AND(Buffer(i),0xFF))))
'        Next
        If TagData="0003000000" Then
           
        Else
            Msgbox("Update Fail...","TMS")
        End If
    End If
End Sub

B4X:
Error occurred on line: 515 (main)
Service not found
Stack Trace: (
  CoreFoundation       <redacted> + 150
  libobjc.A.dylib      objc_exception_throw + 38
  CoreFoundation       <redacted> + 0
  Apple test           -[BleManager getService:] + 532
  Apple test           -[BleManager WriteData:::] + 190
  Apple test           -[b4i_main _getparameter] + 1304
  CoreFoundation       <redacted> + 68
  CoreFoundation       <redacted> + 300
  Apple test           +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1928
  Apple test           -[B4IShell runMethod:] + 496
Apple test           -[B4IShell raiseEventImpl:method:args::] + 2060
Apple test           -[B4IShellBI raiseEvent:event:params:] + 1316
Apple test           __33-[B4I raiseUIEvent:event:params:]_block_invoke + 74
libdispatch.dylib    <redacted> + 10
libdispatch.dylib    <redacted> + 22
libdispatch.dylib    _dispatch_main_queue_callback_4CF + 718
CoreFoundation       <redacted> + 8
CoreFoundation       <redacted> + 1512
CoreFoundation       CFRunLoopRunSpecific + 476
CoreFoundation       CFRunLoopRunInMode + 106
GraphicsServices     GSEventRunModal + 136
UIKit                UIApplicationMain + 1440
Apple test           main + 116
libdyld.dylib        <redacted> + 2
)
when i writedata to my bt device i need get the response data from it,there is no other way to get response?
 
D

Deleted member 103

Guest
Hi,

I should send and receive asynchronous single character, but I do not understand how it should work.
Can someone give me an example?
 
D

Deleted member 103

Guest
Start with reading. Run the example in the first post.
Should I done the reading into a timer? I can not always have to press the button.
I beg your pardon, but I do not understand.
 
D

Deleted member 103

Guest
I still need help, because I do not understand this "Characteristics".
This is part of my code:
B4X:
Private Sub btManager_Connected (services As List)
'   lblDeviceStatus.Text = "Connected - " & connectedDevice.Name
   ConnectedServices = services
   SetState(True)
   timerSpeed.Enabled = IsBtConnected
End Sub

Private Sub btManager_DataAvailable (Service As String, Characteristics As Map)
   Dim bc As ByteConverter
   Dim KeyCode As String

   For Each id As String In Characteristics.Keys
     KeyCode = Characteristics.Get(id)
     Log("KeyCode=" & KeyCode)
     Log( bc.HexFromBytes( Characteristics.Get(id) ) )
   Next
End Sub
   
Sub timerSpeed_Tick   
   btManager.ReadData(ConnectedServices.Get(0))
     
   'Led blinken lassen solange eine BT-Verbindung vorhanden ist.
   ledBlinkTime = ledBlinkTime + timerSpeed.Interval
   If ledBlinkTime > 200 Then
     If IsBtConnected Then btManager.WriteData(ConnectedServices.Get(0), 0x00, "1".GetBytes("UTF8")) 'Led ON
     ledBlinkTime = 0
'     Log("Led ON")
   End If
End Sub

and these are the logs:
 
Last edited by a moderator:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…