B4A Library MQTT - MQ Telemetry Transport for B4A

Alberto Iglesias

Well-Known Member
Licensed User


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






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








How works the MQTT protocol



Communication Infrastructure




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:
http://www.b4x.com/android/forum/threads/mqtt-mq-telemetry-transport-for-b4j.48184/

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


 

Attachments

Last edited:

Alberto Iglesias

Well-Known Member
Licensed User
Hi..

The MQTT protocol says:

" The length is limited to 64k but within that there are no limits to the number of levels in a topic tree.
  • There can be any number of root nodes; that is, there can be any number of topic trees."
But the MQTT was constructed to be lightweight, to be fast!


I think works, but you can try...



And for B4i, YES, I think in construct a library in January, because in this holydays I can´t :-( Sorry.....


Thanks!
 

bluedude

Well-Known Member
Licensed User
Interesting and works like a breeze. I have a broker running on CentOS VPS and it was only a few minutes work.

The B4A sample seems to have some threading problems, I cannot intercept the message and bind it to a view. Any suggestions?

Should I put the sample in a service?
 

bluedude

Well-Known Member
Licensed User
In objMqtt_messageArrived(Topic As String, Message As String)

i'm trying to put the received Message in an edittext on the layout, this is not allowed and i'm getting an error about main threads. Logging it works fine but for the rest I cannot do anything.

I'm not using any other libraries just your stuff.
 

bluedude

Well-Known Member
Licensed User
Works great but what i'm missing is a Quality of Service flag in the subscribe method. I see you have it in publish but not in subscribe.
 

bluedude

Well-Known Member
Licensed User
Great, I will make a donation a.s.a.p. MQTT is a huge benefit over Google Cloud Messaging which sucks in my opinion. JSON over MQTT is perfect for many scenario's, instead of polling for new data a server can update clients through topics which is much better.
 

Aidan Ruff

Member
Licensed User
Hola Alberto
I just sent you 10 euros - nice work, thanks. If you get a chance to send me the full version without the added text, I'd appreciate it!
 
Top