B4A Library MQTT - MQ Telemetry Transport for B4A

MqttTop.jpg


This library was made based on MQTT Protocol


Installation instructions:
- Copy the .xml and .jar(s) files to your custom libraries folder
- Select in your REFERENCED LIBRARIES


MqttRef.png




Version history:
V1.0.0 (First public release - Donationware):
- Initial version

V1.0.2 (Release - Donationware):
- Implement method to get independence of threads

V1.0.4 (Release - Donationware):
- Implement method to subscribe a topic with QoS

V1.0.5 (Release - Donationware):
- Now can be used isConnected method "BEFORE" the first connection

V1.0.6
(Release - Donationware):
- not published

V1.0.7 (Release - Donationware):
- New methods: Publish2, Subscribe3, Subscribe4
This new methods return the token, then after when arrived or publish the messages, you can compare

MQTT
Author:
Alberto Iglesias - alberto@visualnet.inf.br
Version: 1.07
  • MQTT
    Events:
    • connectionlost ( )
    • deliverycomplete (Token As String)
    • messageArrived (Topic As String, Message As String)
    • onConnect (Status as boolean As )
    • onDisconnect (Status as boolean As )
    • onInitialized ( )
    Fields:
    • CleanSession As Boolean
    • JavaDebug As Boolean
    • KeepAliveInterval As Int
    • QoS_AtLeastOnce As Int
    • QoS_AtMostOnce As Int
    • QoS_ExactlyOnce As Int
    • generatedClientId As String
    Methods:
    • About As String
    • Connect (broker As String, ClientID As String, Username As String, Password As String) As Boolean
    • Disconnect As Boolean
    • Initialize (eventname As String)
    • Publish (Topic As String, Message As String, Qos As Int, Retained As Boolean)
    • Publish2 (Topic AsString, Message AsString, Qos AsInt, Retained AsBoolean)
    • Subscribe (Topic As String)
    • Subscribe2 (Topic As String, QoS as int)
    • Subscribe3 (Topic As String)
    • Subscribe4 (Topic As String, QoS as int))
    • Unsubscribe (Topic As String)
    • Version As String
    • isConnected As Boolean
    Permissions:
    • android.permission.ACCESS_WIFI_STATE
    • android.permission.INTERNET


MqttSample1.png



MqttRef2.png



How works the MQTT protocol
MqttScheme1.jpg



Communication Infrastructure

MqttScheme2.png



References:
http://mqtt.org/
http://public.dhe.ibm.com/software/dw/webservices/ws-mqtt/mqtt-v3r1.html
Mosquitto Broker: http://mosquitto.org/



* This version is fully functional, the only one difference is when publishing a message the text "Donationware" is delivery with your message.
Please consider a simple €10 donation and I send to you the Library without "Donationware" text in a publish method.

Already available in B4J too:
https://www.b4x.com/android/forum/threads/mqtt-mq-telemetry-transport-for-b4j.48184/

Already available in B4i too:
https://www.b4x.com/android/forum/threads/mqtt-mq-telemetry-transport-for-b4i.50036/


 

Attachments

  • MQTTB4ASample.zip
    7.8 KB · Views: 690
  • MQTT Library1.0.2.zip
    162 KB · Views: 379
  • MQTTSampleActivity.zip
    8.2 KB · Views: 508
  • SampleSubscribe2.zip
    8.3 KB · Views: 479
  • MQTT Library1.0.4.zip
    154.6 KB · Views: 325
  • MQTT Library1.0.5.zip
    154.9 KB · Views: 380
  • SampleIsConnected.zip
    8.3 KB · Views: 542
  • SampleWithToken.zip
    8.2 KB · Views: 363
  • MQTT Library1.0.7.zip
    155.6 KB · Views: 707
Last edited:

coslad

Well-Known Member
Licensed User
Longtime User
So, have you written a mtqq broker? Wonderful ! If you in the future will share the code with us should be more useful
 

jndaniels1

Member
Licensed User
Longtime User
HI Alberto.
I was referred to your post here by another user - I am (was, is) looking at rabbitMQ. And was actively trying to integrate it. But alas you have created a B4A lib to save my day.

I have a particular sensitive project that message queueing is going to be an absolute necessary --- what i am curious about is a few things.
speed ? 10s, 100s, millions per sec?
clusterable?
what if my broker crashes or reboots, will it kill the cluster or requeue messages (if set so) ?
and what about the client (app, b4a or other) keeps disconnecting - does it handle reconnects and picks up where it left off?

Thank you for your time in advance!
Kind Regards
JEFFD
 

JakeBullet70

Well-Known Member
Licensed User
Longtime User
HI Alberto.

I just donated. Do I need to donate 2 times as I need the lib for b4a and b4j.

Thanks
 

woniol

Active Member
Licensed User
Longtime User
Does the B4J version follow B4A version?
Is there B4J 1.05 available?
 

jndaniels1

Member
Licensed User
Longtime User
Hi Alberto or Erel
Ran into a bit of an error I dont know how to get around.

I am using both your libraries MQTT and XMPP --- Using the example from the MQTT zip and just adding the XMPP library produces the error below.

I simply added in the process_globals
Dim oXmpp as XMPP

Without the line the MQTT example works perfectly, installs and runs.
Any help would be super great!
Thanks!


B4X:
Convert byte code - optimized dex.      Error
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/visualnet/mqtt;
    at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
    at com.android.dx.dex.file.DexFile.add(DexFile.java:161)
    at com.android.dx.command.dexer.Main.processClass(Main.java:732)
    at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
    at com.android.dx.command.dexer.Main.access$300(Main.java:83)
    at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
    at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
    at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
    at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
    at com.android.dx.command.dexer.Main.processOne(Main.java:632)
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
    at com.android.dx.command.dexer.Main.run(Main.java:246)
    at com.android.dx.command.dexer.Main.main(Main.java:215)
    at com.android.dx.command.Main.main(Main.java:106)
warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence$2) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
1 error; aborting
    Optimized dexer failed. Switching to Standard dexer.


Update:

I found in the xmpp.jar is a mqtt.class - removing the mqtt.class resolves the error. Just remember to backup your original xmpp.jar.

Cheers!
 
Last edited:

coslad

Well-Known Member
Licensed User
Longtime User
Hi Alberto, do you know if is there a way to connect a vb6 application over mqtt ?
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
@Alberto Iglesias : referring from your message from Friday. How will you manage the updating to your registered users please ?
 

klarsys

Active Member
Licensed User
Longtime User
It seems to be working!

Is this a usable version or will you upload another library?
 
Top