Android Question MQTT problem

marcel

Active Member
Licensed User
Longtime User
Hi,

I am trying to use MQTT for a project. I am playing arround a little bit. I am using on the Windows side:
https://m2mqtt.wordpress.com/
using vb.net.

I implemented the broker and a client. This works all ok. Now I try to connect the client for android. I use the sample of post https://www.b4x.com/android/forum/threads/b4x-mqtt-chat-room.61568/

Connection goes well. But when I post a message to a subject I get an error in the Andriod app:

B4X:
Private Sub client_MessageArrived (Topic As String, Payload() As Byte)
    Dim receivedObject As Object = serializator.ConvertBytesToObject(Payload)

add ConvertBytes

B4X:
Connected: true
Error occurred on line: 60 (Starter)
java.io.IOException
    at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:177)
    at libcore.io.Streams.readSingleByte(Streams.java:41)
    at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:130)
    at java.io.DataInputStream.readByte(DataInputStream.java:75)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readByte(B4XSerializator.java:131)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readObject(B4XSerializator.java:299)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ReadObject(B4XSerializator.java:110)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ConvertBytesToObject(B4XSerializator.java:81)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:702)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:336)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at anywheresoftware.b4a.BA$2.run(BA.java:328)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:5832)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.util.zip.DataFormatException: incorrect header check
    at java.util.zip.Inflater.inflateImpl(Native Method)
    at java.util.zip.Inflater.inflate(Inflater.java:237)
    at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158)
    ... 24 more

In vb dotnet I post the message using:

B4X:
 pclient.Publish("/all/1", Encoding.UTF8.GetBytes(strValue), Messages.MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, False)

Does this mean:
1) Is MQTT not compatible, which I do not think so
2) Is the problem converting to bytes? Do I need to convert differently on the dotnet side? Or is the conversion on the android site wrong?

I am kind of lost here.
 

rboeck

Well-Known Member
Licensed User
Longtime User
Upvote 0

marcel

Active Member
Licensed User
Longtime User
Why are you using VB.Net instead of B4J?

Client would like to have the server site in dotnet and no java. They would also prefer some back office clients in native window. Basically it should be compatible...
Does this mean the conversion from the byte array goes wrong?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Does this mean the conversion from the byte array goes wrong?
You can use MQTT. However you cannot use B4XSerializator. Check the code and you will see that it uses B4XSerializator.

Note that Java doesn't need to be installed on the server. You can include the files together with your server files.
 
Upvote 0

marcel

Active Member
Licensed User
Longtime User
You can use MQTT. However you cannot use B4XSerializator. Check the code and you will see that it uses B4XSerializator.
Yes, I saw. is there another way to make this compatible? It is just a byte array I think.
 
Upvote 0
Top