B4i Library MQTT - MQ Telemetry Transport for B4i

MQttTopB4i.png



This library was made based on MQTT Protocol

Installation instructions:

- Copy the *.a and *.h files into the folder "Libs" in your MAC or in your MAC HOSTED by AnywhereSoftware, normally in "B4i-MacServer\Libs" folder

-Copy the iMQTT.xml to your custom libraries folder in B4i
- Select in your REFERENCED LIBRARIES

RefB4iMqtt.png


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


iMQTT

Author: Alberto Iglesias (alberto@visualnet.inf.br)
Version: 2



    • MQTT
      Events:
      • Received (Message As String)
      • onConnect (Status As Int)
      • onDisconnect (Status As Int)
      • onInitialized ( As )
      • onPublish (Status As Int)
      • onSubscribe (Topic as String As )
      Methods:
      • ClearWill
      • Connect (Broker As String, Username As String, Password As String, Port As String)
        Connect to Broker
      • Disconnect
        Disconnect from Broker
      • Initialize (EventName As String)
        Initializes the object.
      • IsConnected As BOOL
        Get status of connection
      • Publish: (Topic As String, Payload As String, qos As Int, Retained As BOOL)
        Publish a message to Topic
      • Reconnect
      • Subscribe2: (Topic As String, qos As int)
        Subscribe into a Topic with Quality of Service
      • Subscribe: (Topic As String)
        Subscribe into a Topic
      • Unsubscribe: (Topic As String)
        Unsubscribe a Topic
      Properties:
      • Author As String [read only]
        Author of this Library
      • ClientID As String
        Set/Get the Client ID for broker know who you are. Default = UUID from Device
      • DebugMode As BOOL
        Enable/Disable Debug mode from Library
      • QoS_AtLeastOnce As Int [read only]
        QoS1, At least once: The message is always delivered at least once. It might be delivered multiple times if there is a failure before an acknowledgment is received by the sender. The message must be stored locally at the sender, until the sender receives confirmation that the message has been published by the receiver. The message is stored in case the message must be sent again.
      • QoS_AtMostOnce As Int [read only]
        QoS0, At most once: The message is delivered at most once, or it may not be delivered at all. Its delivery across the network is not acknowledged. The message is not stored. The message could be lost if the client is disconnected, or if the server fails. QoS0 is the fastest mode of transfer. It is sometimes called "fire and forget".
      • QoS_ExactlyOnce As Int [read only]
        QoS2, Exactly once
      • Version As NSString* [read only]
        Library Version


MqttSample1.png



MqttRef2.png



How works the MQTT protocol
MqttScheme1.jpg



Communication Infrastructure

MqttScheme2.png



MqttScreen3.jpg


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

Already available in B4A too: look in https://www.b4x.com/android/forum/threads/mqtt-mq-telemetry-transport-for-b4a.48167/


 

Attachments

  • LibraryB4I.zip
    407.9 KB · Views: 85
  • Example1.zip
    51.6 KB · Views: 67
Last edited:

klarsys

Active Member
Licensed User
Longtime User
Thank you, @Alberto Iglesias. Now setWill() is working!

However, these issues still remain:
1. onConnect() gets called only on connection success. There is no callback for connection failure. e.g. when broker is not available or if it is mis-typed.
2. After a successful connection, there is no connectionLost() event.
3. Topic is missing in Received() callback.
4. [Minor] Need APIs to set connection timeout and keep alive period.

Above functionality is needed to make error resilient MQTT app.

Thanks again for your support.
 
Last edited:
Top