Hi there.
I am using an ESP8266 board to transmit a message to my CloudMQTT account which is then viewed using B4J.
I have successfully transmitted the message and it is being received ok, but I am having problems decoding it:
I encode my message as follows on the ESP board in B4R.
Type MyMessage (messageInfo As String, messageTime As ULong)
The code that sends the message from the ESP8266 board is as follows: -
Dim myMessage As MyMessage
If wifi.IsConnected Then
myMessage.messageInfo = "Time here is:"
myMessage.messageTime = Millis
Log("Sending...Time here is: ", Millis)
mqttClient.Publish("esp", ser.ConvertArrayToBytes(Array(myMessage)))
End If
This all works fine.
The code in my B4J app that receives messages is as follows:
Type MyMessage (messageInfo As String, messageTime As Long)
Private Sub mqtt_MessageArrived (Topic As String, Payload() As Byte
Dim myMessage As MyMessage
Log("Message arrived")
Log(BytesToString(Payload, 0, Payload.Length, "utf8"))
'Show the message as it is raw
lblESPInfo.Text = BytesToString(Payload, 0, password.Length, "utf8")
Dim obj As Object = serializator.ConvertBytesToObject(Payload)
If obj Is MyMessage Then
myMessage = obj
Log(myMessage.messageInfo + myMessage.messageTime)
End If
End Sub
The program crashes at the line:
Dim obj As Object = serializator.ConvertBytesToObject(Payload)
with
java.util.zip.ZipException: incorrect header check
How can I convert the payload back to the type of variable that I know I sent?
Thanks for any help.
JMB