B4A Library JG MQTT Library

Hi all,

This is my very first library :)

It implements MQTT standard V3.1.1

MQTT is a lightweight publish/subscribe messaging protocol.

for further information see http://mqtt.org/.

MQTT_pubsub.jpg


Publish/Subscribe
The MQTT protocol is based on the principle of publishing messages and subscribing to topics, or "pub/sub". Multiple clients connect to a broker and subscribe to topics that they are interested in. Clients also connect to the broker and publish messages to topics. Many clients may subscribe to the same topics and do with the information as they please. The broker and MQTT act as a simple, common interface for everything to connect to.

Quality of Service
MQTT defines three levels of Quality of Service (QoS). The QoS defines how hard the broker/client will try to ensure that a message is received.

Implemented levels are :

  • 0: The broker/client will deliver the message once, with no confirmation.

  • 1: The broker/client will deliver the message at least once, with confirmation required.

  • 2: The broker/client will deliver the message exactly once by using a four step handshake.
Clean session / Durable connections
On connection, a client sets the "clean session" flag, which is sometimes also known as the "clean start" flag. If clean session is set to false, then the connection is treated as durable. This means that when the client disconnects, any subscriptions it has will remain and any subsequent QoS 1 or 2 messages will be stored until it connects again in the future. If clean session is true, then all subscriptions will be removed for the client when it disconnects.

Limitation : Persistency of sessions is not implemented yet on the client side (this library)

Retained Messages
All messages may be set to be retained. This means that the broker will keep the message even after sending it to all current subscribers.

Last Will Testament
When a client connects to a broker, it may inform the broker that it has a will. This is a message that it wishes the broker to send when the client disconnects unexpectedly.


Version 1.0

This is the first release. It is provided with a very basic sample test App.

The use is totally free, with no limitation.

Utilisation

Connect to a broker (here iot.eclipse.org)

B4X:
MyMQTT.Connect("iot.eclipse.org","1883", "test", "", "", "/android/", "dead", 0, False, True, 60)

Events :
MQTT_events.jpg



Methods :
MQTT_methods.jpg


test App :

MQTT_App.jpg

it is limited to :
  • connect/disconnect to broker and pinging to test connection
  • sending/receiving messages
  • subscribing/unsubscribing to topics
  • selecting QoS

Enjoy !
And give me your feedback
 

Attachments

  • JG_MQTT_V1.0.zip
    12.2 KB · Views: 629

freedom2000

Well-Known Member
Licensed User
Longtime User
Yes my advice now would be to use JMQTT as it is supported by Erel

I will probably stop supporting my own library and jump as well to JMQTT
 
Top