Android Question Buffer help


New Member
Licensed User
Longtime User
i all
i have a problem with buffer , i work with two device connect with bluetooth mode, that are send a simple json string.
i explain the problem.
the device sends to the buffer pieces of string in json, as sequentially '{"node": 1,' the next piece of string will be '' device 'd3', until complete the entire string json {"node1" : 1, "device": "d350", "temperature": 20, "humidity": 70}
the problem exists when control the formation of the string json with the log of B4A, it happens sometimes that in forming the string, the buffer does not send anything more and starts returning a new string adding it to the previous example:
{"node1": 1, "device": "d350", "tem {" node1 ": 1," device ":" d350 "," temperature ": 20," humidity ": 70}.
when I have to parse the json, the program goes in error because it is not a string json correct.

this is the part of program for create the entire string json.


Sub Astreams1_NewData (Buffer() As Byte)
    Dim u As String
    Dim lpos As Long
    Dim rpos As Long
    u=(u&BytesToString(Buffer, 0, Buffer.Length, "UTF8"))   
    str_ = str_ & u
    Log ("stringa lunghezza" & str_.Length)
    Log ("string base " & str_)
    If str_.Length > 160 Then
        If lpos < 0 Then
            Log("lpos negativo ----------------------------------------------")
            str_=" "
        End If       
        If lpos>=0 Then
            If rpos > lpos Then
                If str_.Length >170 Then
                    str_ = "" ' for delete the string'
                    s = sf.Mid(str_,lpos+1,(rpos+lpos)+1) 'change -1'
                    json_interpreter1(s)    'change the buffer'
                    Log ("json string" &s)
                    Log("Lenght" & S.Length)
                End If 
            End If
        End If
    End If
End Sub