Android Question BLE2 writedata error

Marco Maria Vilucchi

Active Member
Licensed User
Hi all,
I have an error writing data to bluetooth

My device is connected and I have this code to write:
B4X:
    Dim strmsg As String = BytesToString(msg, 0, msg.Length, "utf8")
    LogColor("Dentro SendMessage Blestate:"&BLEState&" Messaggio "&strmsg,Colors.red)
    messagesToSend.Add(TrimMessage(msg))
    If messagesToSend.Size = 1 Then
        Do While messagesToSend.Size > 0
            Try
                manager.WriteData(ServiceId, C300_comando, messagesToSend.Get(0))
            Catch
                FailedToSend
                Return
            End Try
            Wait For Manager_WriteComplete (Characteristic As String, Status As Int)
            If Status <> 0 Then
                LogColor("Dentro SendMessage FailedToSend Status:"&Status,Colors.red)

'                FailedToSend
            End If
            If connected = False Or messagesToSend.Size = 0 Then Return
            messagesToSend.RemoveAt(0)
        Loop
    End If
but sometimes (first a little then more often) write fail
This is the log
B4X:
Dentro SendMessage Blestate:4 Messaggio E
retries: 4
retries: 3
retries: 2
retries: 1
Failed to send message. Disconnecting.
Someone can help me?
Thanks Marcom
 

Marco Maria Vilucchi

Active Member
Licensed User
1) Here the unfiltred logs:
B4X:
Dentro SendMessage Blestate:4 Messaggio E
StartRead
initGoToTop
initGoToTop
Input channel constructed: fd=87
setView = DecorView@b05e25c[misurazionialtezza] TM=true MM=false
accendipallini altezza
ExecuteMemoryTable: SELECT * FROM clienti where clirec=4
query SELECT * FROM misurazioni where miscodcliente=4 and miscontrollo='m' order by misrec DESC
ExecuteMemoryTable: SELECT * FROM misurazioni where miscodcliente=4 and miscontrollo='m' order by misrec DESC
MSG_RESIZED_REPORT: frame=Rect(0, 0 - 1920, 1200) ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=2
MSG_WINDOW_FOCUS_CHANGED 1
Starting input: tba=android.view.inputmethod.EditorInfo@67a20f4 nm : com.mamavi.slimup ic=null
startInputInner - Id : 0
startInputInner - mService.startInputOrWindowGainedFocus
Input channel constructed: fd=93
Input channel destroyed: fd=89
Relayout returned: old=[0,0][1920,1200] new=[0,0][1920,1200] result=0x3 surface={valid=true 3293913088} changed=false
dispatchAttachedToWindow
sf_framedrop debug : 0x4f4c, game : false, logging : 0
Relayout returned: old=[0,0][0,0] new=[528,513][1392,687] result=0x27 surface={valid=true 3271548928} changed=true
EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, egl_color_buffer_format *, EGLBoolean) returns 0x3000,  [960x270]-format:1
eglCreateWindowSurface = 0xbed36838, 0xc2ffe008
ReadTimer_Tick BleState 4 DateTime.Now 1567516722299 LastReadTime 0
manager.ReadData 0000a002-0000-1000-8000-00805f9b34fb
MSG_WINDOW_FOCUS_CHANGED 1
MSG_RESIZED_REPORT: frame=Rect(528, 513 - 1392, 687) ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=2
eglDestroySurface = 0xc40440e8, 0xc3fae000
Relayout returned: old=[0,0][1920,1200] new=[0,0][1920,1200] result=0x5 surface={valid=false 0} changed=true
MSG_WINDOW_FOCUS_CHANGED 0
retries: 4
retries: 3
retries: 2
retries: 1
Failed to send message. Disconnecting.
cancelOpen() - device: C4:4F:33:17:02:1B
onClientConnectionState() - status=0 clientIf=7 device=C4:4F:33:17:02:1B
close()
unregisterApp() - mClientIf=7
Disconnesso
2) Blestate: 4 is an application field. I use it in the hereinafter of the program

3) This is first message after connection (the message is just a letter: E)
 

Marco Maria Vilucchi

Active Member
Licensed User
I have tick timer already active.
It's possible that it is wrong and it disorders writedata?

the connection is closed after the writing problem
 
Top