Android Question Is JMQTT client compliant with 31.1 protocol version

Sergio83

Active Member
Licensed User
Longtime User
Hello everyone,

I encountered a problem using the JMQTT client (jmqtt version 1.0) in conjunction with other MQTT nodemcu client (ESP8266 Lua) and a MQTT MOSQUITTO broker.

The MQTT Nodemcu client is only compliant with protocol version 3.1.1, MOSQUITTO is compliant with protocol version 3.1 and 3.1.1.

When I publish from a Nodemcu client to a B4A subscriber client, the B4A client crashes.
When I publish from a B4A client to a B4A subcriber client it works.

Does this mean that the JMQTT B4a client is not compliant with protocol version 3.1.1?
If so, is there a workaround?

By the way, is JMQTTBROKER 3.1.1 compliant?

Thanks by advance for your help

Regards
 

Sergio83

Active Member
Licensed User
Longtime User
Hello Erel,

I've done what you asked me and the result is here after.

MOSQUITTO side:
B4X:
1488359888: New connection from 192.168.1.5 on port 1883.
1488359888: New client connected from 192.168.1.5 as Android012345678912345 (c1, k60).
1488360373: New connection from 192.168.1.229 on port 1883.
1488360373: New client connected from 192.168.1.229 as simulateur (c1, k60).
1488360461: New connection from 192.168.1.41 on port 1883.
1488360461: New client connected from 192.168.1.41 as RXHF (c1, k120).
1488360463: Socket error on client Android012345678912345, disconnecting.


You can see the connexion of the two B4a MQTT subscriber clients (two different devices), the connexion of the NodeMCU publisher client and then the socket error when the subscriber B4A crashes.

Now the B4A log:

B4X:
Error occurred on line: 164 (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 Domus.SeriSyvis.starter._mqtt_messagearrived(starter.java:278)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
   at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
   at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
   at anywheresoftware.b4a.BA$2.run(BA.java:328)
   at android.os.Handler.handleCallback(Handler.java:733)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:136)
   at android.app.ActivityThread.main(ActivityThread.java:5001)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:811)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:627)
   at dalvik.system.NativeStart.main(Native Method)
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:228)
   at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158)
   ... 26 more
** Activity (main) Resume **

Line 64 is part of the "mqtt_MessageArrived " subroutine:

B4X:
Dim obj As Object = serializator.ConvertBytesToObject(Payload)

"mqtt_MessageArrived " subroutine is:

B4X:
Private Sub mqtt_MessageArrived (topic As String, Payload() As Byte)
   Dim obj As Object = serializator.ConvertBytesToObject(Payload)
   
   mqtt_message=obj
   mqtt_topic=topic
   DOMUS.newtopic(mqtt_topic,mqtt_message)
   Service.StopForeground(1) 'Return the service to the "background" (also removes the ongoing notification)
End Sub

Hope this will help ...

Regards and thanks
 
Upvote 0

Sergio83

Active Member
Licensed User
Longtime User
Hello Erel,

Your answer is so obvious that I feel a little ashamed, this is proof of my shortcomings regarding B4A!

By using a byteconverter instead of a B4XSerializator it works much better!

Now all my MQTT clients publishers and/or subscribers, B4A and/or NodeMCU works fine with MOSQUITTO.

Thanks again for your help !!!

Regards
 
Last edited:
Upvote 0
Top