iOS Question (Solved) BLE Write error

f0raster0

Well-Known Member
Licensed User
Longtime User
Hi Guys,

I'm getting an error when trying to write a data to the characteristic, I want to send: 1

manager.WriteDataWithResponse("00001523-1212-EFDE-1523-785FEABCD123", "00001525-1212-EFDE-1523-785FEABCD123", a)


Code:
B4X:
Sub Manager_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double)
    manager.StopScan
    If Name = "Nordic_Thingy" Or Name = "Nordic_Blinky" Then
            Log("Found: " & Name & ", " & Id & ", RSSI = " & RSSI & ", " & AdvertisingData) 'ignore
            ConnectedName = Name
            manager.Connect(Id)
            manager.StopScan
    End If
End Sub

Sub btnReadData_Click
    ActivityIndicator2.Visible = True
'    clv.Clear
    Log(" *** btnReadData ***")
    For Each s As String In ConnectedServices
        manager.ReadData(s)
    Next
End Sub

Sub Manager_DataAvailable (Service As String, Characteristics As Map)
    ActivityIndicator2.Visible = False
'    clv.Add(CreateServiceItem(Service), "")
'    For Each id As String In Characteristics.Keys
'        clv.Add(CreateCharacteristicItem(id, Characteristics.Get(id)), "")
'    Next
'
    Log("Service: " & Service)
    Log("Characteristics: " & Characteristics)

End Sub

Sub LabelAmp_Click
    Log(" *** LabelAmp ***")
    Dim ByteA As ByteConverter
    Dim a() As Byte
    a=ByteA.HexToBytes("1")
    'manager.WriteDataWithResponse("00001523-1212-efde-1523-785feabcd123", "00001525-1212-efde-1523-785feabcd123", a)
    manager.WriteDataWithResponse("00001523-1212-EFDE-1523-785FEABCD123", "00001525-1212-EFDE-1523-785FEABCD123", a)
End Sub

Logs/Error:
B4X:
Bluetooth StatusON
Found: Nordic_Blinky, 0D3C7FEE-FD3E-34A4-F4D2-CCCE83637E58, RSSI = -42, (read only map) {
    kCBAdvDataIsConnectable = 1;
    kCBAdvDataLocalName = "Nordic_Blinky";
    kCBAdvDataServiceUUIDs =     (
        "00001523-1212-EFDE-1523-785FEABCD123"
    );
}
Discovering services
Services discovery completed.
*** btnReadData ***
Service: 00001523-1212-EFDE-1523-785FEABCD123
Characteristics: NSMapTable {
[8] 00001524-1212-EFDE-1523-785FEABCD123 -> <B4IArray: 0x17df3510>
[13] 00001525-1212-EFDE-1523-785FEABCD123 -> <B4IArray: 0x17df3d90>
}
*** LabelAmp ***
Error occurred on line: 144 (Main)
-[__NSCFConstantString characterAtIndex:]: Range or index out of bounds
Stack Trace: (
  CoreFoundation       <redacted> + 152
  libobjc.A.dylib      objc_exception_throw + 38
  CoreFoundation       <redacted> + 0
  CoreFoundation       <redacted> + 96
  Test Remote      -[B4IByteConverter HexToBytes:] + 162
  CoreFoundation       <redacted> + 68
  CoreFoundation       <redacted> + 300
  Test Remote      +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1790
  Test Remote      -[B4IShell runMethod:] + 588
  Test Remote      -[B4IShell raiseEventImpl:method:args::] + 1908
Test Remote      -[B4IShellBI raiseEvent:event:params:] + 1328
Test Remote      __33-[B4I raiseUIEvent:event:params:]_block_invoke + 74
libdispatch.dylib    <redacted> + 10
libdispatch.dylib    <redacted> + 22
libdispatch.dylib    _dispatch_main_queue_callback_4CF + 902
CoreFoundation       <redacted> + 8
CoreFoundation       <redacted> + 848
CoreFoundation       CFRunLoopRunSpecific + 470
CoreFoundation       CFRunLoopRunInMode + 104
GraphicsServices     GSEventRunModal + 80
UIKit                UIApplicationMain + 150
Test Remote      main + 106
libdyld.dylib        <redacted> + 2
)


documentation:
My hardware work OK using the NordicSemiconductor iOS App

Thank you
 
Last edited:
Top