M Mike1970 Well-Known Member Licensed User Longtime User Jun 14, 2022 #1 Hi everyone i'm trying to use MQTT for the first time. I follwed this example. It connects succesfully but unfortuntely when I receive a message this error shows up Code: Copy Error occurred on line: 96 (B4XPage_Details) Error decompressing data Stack Trace: ( CoreFoundation 5198FB57-5645-3B34-A49F-F32B52256CF3 + 627356 libobjc.A.dylib objc_exception_throw + 60 CoreFoundation 5198FB57-5645-3B34-A49F-F32B52256CF3 + 983952 Potty -[B4ICompressedStreams DecompressBytes::] + 336 Potty -[B4ISerializator ReadObject::] + 96 CoreFoundation 5198FB57-5645-3B34-A49F-F32B52256CF3 + 138020 CoreFoundation 5198FB57-5645-3B34-A49F-F32B52256CF3 + 259600 Potty +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1300 Potty -[B4IShell runMethod:] + 416 Potty -[B4IShell raiseEventImpl:method:args::] + 1488 Potty -[B4IShellBI raiseEvent:event:params:] + 1580 Potty +[B4IObjectWrapper raiseEvent:::] + 268 Potty -[MQTTClient handleMessage:onTopic:retained:] + 232 Potty -[MQTTSessionManager newMessage:data:onTopic:qos:retained:mid:] + 144 Potty -[MQTTSession handlePublish:] + 996 Potty -[MQTTSession decoder:newMessage:] + 2204 Potty -[MQTTDecoder stream:handleEvent:] + 2260 CoreFoundation 5198FB57-5645-3B34-A49F-F32B52256CF3 + 1065248 CoreFoundation 5198FB57-5645-3B34-A49F-F32B52256CF3 + 1169356 CoreFoundation 5198FB57-5645-3B34-A49F-F32B52256CF3 + 1113748 The sub is B4X: Copy Private Sub mqtt_MessageArrived (Topic As String, Payload() As Byte) Log(Topic) Dim obj As Object = serializator.ConvertBytesToObject(Payload) 'Log(obj) End Sub The data sent is something like this: {"temperature":34.32,"moisture":100,"waterLevel":0,"lux":500,"uuid":"aadasdada-asdsad-asdasd-asdassd"} N.B. Assume that the problem is App-side because from terminal i receive data correctly... and also if a do something like: B4X: Copy Private Sub mqtt_MessageArrived (Topic As String, Payload() As Byte) Log(Topic) For Each b In Payload Log(Chr(b)) Next End Sub it print all correct characters Thanks in advance
Hi everyone i'm trying to use MQTT for the first time. I follwed this example. It connects succesfully but unfortuntely when I receive a message this error shows up Code: Copy Error occurred on line: 96 (B4XPage_Details) Error decompressing data Stack Trace: ( CoreFoundation 5198FB57-5645-3B34-A49F-F32B52256CF3 + 627356 libobjc.A.dylib objc_exception_throw + 60 CoreFoundation 5198FB57-5645-3B34-A49F-F32B52256CF3 + 983952 Potty -[B4ICompressedStreams DecompressBytes::] + 336 Potty -[B4ISerializator ReadObject::] + 96 CoreFoundation 5198FB57-5645-3B34-A49F-F32B52256CF3 + 138020 CoreFoundation 5198FB57-5645-3B34-A49F-F32B52256CF3 + 259600 Potty +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1300 Potty -[B4IShell runMethod:] + 416 Potty -[B4IShell raiseEventImpl:method:args::] + 1488 Potty -[B4IShellBI raiseEvent:event:params:] + 1580 Potty +[B4IObjectWrapper raiseEvent:::] + 268 Potty -[MQTTClient handleMessage:onTopic:retained:] + 232 Potty -[MQTTSessionManager newMessage:data:onTopic:qos:retained:mid:] + 144 Potty -[MQTTSession handlePublish:] + 996 Potty -[MQTTSession decoder:newMessage:] + 2204 Potty -[MQTTDecoder stream:handleEvent:] + 2260 CoreFoundation 5198FB57-5645-3B34-A49F-F32B52256CF3 + 1065248 CoreFoundation 5198FB57-5645-3B34-A49F-F32B52256CF3 + 1169356 CoreFoundation 5198FB57-5645-3B34-A49F-F32B52256CF3 + 1113748 The sub is B4X: Copy Private Sub mqtt_MessageArrived (Topic As String, Payload() As Byte) Log(Topic) Dim obj As Object = serializator.ConvertBytesToObject(Payload) 'Log(obj) End Sub The data sent is something like this: {"temperature":34.32,"moisture":100,"waterLevel":0,"lux":500,"uuid":"aadasdada-asdsad-asdasd-asdassd"} N.B. Assume that the problem is App-side because from terminal i receive data correctly... and also if a do something like: B4X: Copy Private Sub mqtt_MessageArrived (Topic As String, Payload() As Byte) Log(Topic) For Each b In Payload Log(Chr(b)) Next End Sub it print all correct characters Thanks in advance
Solution Erel Jun 15, 2022 The error is not related to MQTT. You can only deserialize a message with B4XSerializator if it was previously serialized with B4XSerializator. Code: Copy Dim s As String = BytesToString(Payload, 0, Payload.Length, "utf8") Dim obj As Map = s.As(JSON).ToMap 'json library Log(obj)
The error is not related to MQTT. You can only deserialize a message with B4XSerializator if it was previously serialized with B4XSerializator. Code: Copy Dim s As String = BytesToString(Payload, 0, Payload.Length, "utf8") Dim obj As Map = s.As(JSON).ToMap 'json library Log(obj)
Erel B4X founder Staff member Licensed User Longtime User Jun 15, 2022 #2 The error is not related to MQTT. You can only deserialize a message with B4XSerializator if it was previously serialized with B4XSerializator. Code: Copy Dim s As String = BytesToString(Payload, 0, Payload.Length, "utf8") Dim obj As Map = s.As(JSON).ToMap 'json library Log(obj) Upvote 0 Solution
The error is not related to MQTT. You can only deserialize a message with B4XSerializator if it was previously serialized with B4XSerializator. Code: Copy Dim s As String = BytesToString(Payload, 0, Payload.Length, "utf8") Dim obj As Map = s.As(JSON).ToMap 'json library Log(obj)
M Mike1970 Well-Known Member Licensed User Longtime User Jun 15, 2022 #3 Oh Erel said: You can only deserialize a message with B4XSerializator if it was previously serialized with B4XSerializator. Click to expand... Oh ok thanks Erel for the clarification Upvote 0
Oh Erel said: You can only deserialize a message with B4XSerializator if it was previously serialized with B4XSerializator. Click to expand... Oh ok thanks Erel for the clarification