Private Sub AppStart
Serial1.Initialize(115200)
Dim text() As Byte = "{""Battery"" : 255, ""RSSI"" : 6,""description"" : """", ""dtype"" : ""Lighting 4"", ""id"" : ""5C0703"", ""idx"" : 58, ""name"" : ""FrontDoor"", ""nvalue"" : 1, ""stype"" : ""PT2262"", ""svalue1"" : ""512"", ""switchType"" : ""Contact"", ""unit"" : 0}"
Dim i1 = -1, i2 = -1, i3 = -1, i4 = -1 As Int
Dim q() As Byte = QUOTE
Dim colon() As Byte = ":"
Dim comma() As Byte = ","
Do While True
i1 = bc.IndexOf2(text, q, i4 + 1)
If i1 = -1 Then Exit
i2 = bc.IndexOf2(text, q, i1 + 1)
If i2 = -1 Then Exit
i3 = bc.IndexOf2(text, colon, i2 + 1)
i4 = bc.IndexOf2(text, comma, i3 + 1)
If i4 = -1 Then i4 = text.Length - 1
HandleKeyAndValue(text, i1, i2, i3, i4)
'Log(StackBufferUsage) no impact on the stack buffer
Loop
Log("After")
End Sub
Sub HandleKeyAndValue(text() As Byte, i1 As Int, i2 As Int, i3 As Int, i4 As Int)
Dim key() As Byte = bc.SubString2(text, i1 + 1, i2)
Dim value() As Byte = bc.SubString2(text, i3 + 1, i4)
value = bc.Trim(value)
If value(0) = 34 Then
value = bc.SubString2(value, 1, value.Length - 1)
End If
Log(key, ": ", value) 'get the values here
End Sub