Hello all,
In experimenting with MQTT, B4R- and B4Xserializator I encountered a problem with the ConvertBytesToArray member.
I send the type mb from B4A to NodeMCu B4R.
B4A side :
Sub Proces Globals
...
Dim Ser as B4xSerializator
Type MyButton(Which As String, State As String)
...
End Sub
...
Public Sub ToggleButtonChanged(mb As MyButton)
client.Publish("esp",Ser.ConvertObjectToBytes(mb))
End Sub
B4R (NodeMcu 12E) side:
Sub Proces Globals
.
Private ObjectsBuffer(500) As Object
Private Ser As B4RSerializator
..
End Sub
...
Sub Mqtt_MessageArrived (Topic As String, Payload() As Byte)
Log("Message arrived. Topic=", Topic, " payload: ", Payload)
If Topic = "esp" Then
Dim Objects() As Object =Ser.ConvertBytesToArray(Payload,ObjectsBuffer)
Log(Payload.Length)
Log(Objects.Length)
Log(ObjectsBuffer.Length)
End If
End Sub
....
The monitor says:
Connected to broker
Message arrived. Topic=esp payload: x??`?b``H2I?K?H?-?I??M??S??L*-)??c#?2?# ?b??????#vFFV?XpIbI*##?#RT?
#
??L?
The line:
Dim Objects() As Object =Ser.ConvertBytesToArray(Payload,ObjectsBuffer) creates the following error:
Out of bounds error. Array length = 500, Index = 65535
Blocking out =Ser.ConvertBytesToArray(Payload,ObjectsBuffer) gives the length of the arrays as 90, 0 and 500 respectively.
Question:
How to correct this error?
In experimenting with MQTT, B4R- and B4Xserializator I encountered a problem with the ConvertBytesToArray member.
I send the type mb from B4A to NodeMCu B4R.
B4A side :
Sub Proces Globals
...
Dim Ser as B4xSerializator
Type MyButton(Which As String, State As String)
...
End Sub
...
Public Sub ToggleButtonChanged(mb As MyButton)
client.Publish("esp",Ser.ConvertObjectToBytes(mb))
End Sub
B4R (NodeMcu 12E) side:
Sub Proces Globals
.
Private ObjectsBuffer(500) As Object
Private Ser As B4RSerializator
..
End Sub
...
Sub Mqtt_MessageArrived (Topic As String, Payload() As Byte)
Log("Message arrived. Topic=", Topic, " payload: ", Payload)
If Topic = "esp" Then
Dim Objects() As Object =Ser.ConvertBytesToArray(Payload,ObjectsBuffer)
Log(Payload.Length)
Log(Objects.Length)
Log(ObjectsBuffer.Length)
End If
End Sub
....
The monitor says:
Connected to broker
Message arrived. Topic=esp payload: x??`?b``H2I?K?H?-?I??M??S??L*-)??c#?2?# ?b??????#vFFV?XpIbI*##?#RT?
#
??L?
The line:
Dim Objects() As Object =Ser.ConvertBytesToArray(Payload,ObjectsBuffer) creates the following error:
Out of bounds error. Array length = 500, Index = 65535
Blocking out =Ser.ConvertBytesToArray(Payload,ObjectsBuffer) gives the length of the arrays as 90, 0 and 500 respectively.
Question:
How to correct this error?