MQTT Library

Top  Previous  Next

MQTT library implements the minimal functionality required to for a Tibbo BASIC/C device to act as an MQTT client. The library implements both the publisher and the subscriber roles.

Explaining the use and inner workings of the MQTT protocol is beyond the scope of this manual. A very large amount of MQTT-related information is available on the Internet. In particular, we like the tutorials (and the server software!) created by HiveMQ:

hivemq.com/blog/mqtt-essentials/.

 

Library Info

Supported platforms:

Any platform with at least the Ethernet (net.), Wi-Fi (wln.), or GPRS (ppp.) interface.

Files to include:

mqtt.tbs, mqtt.tbh (from current_library_set\mqtt\trunk\).

Dependencies:

SOCK library

API procedures:

Use API procedures to interact with the library.

mqtt_start() —starts the MQTT library.

matt_connect() — instructs the library to connect to the MQTT server (broker).

mqtt_reconnect() — instructs the library to reconnect to the MQTT server (broker).

mqtt_disconnect() — disconnects the device from the MQTT server (broker).

mqtt_publish() — publishes a topic and its data to the MQTT server (broker).

mqtt_sub() — subscribes the device to the specified topic on the MQTT server (broker).

mqtt_unsub() — unsubscribes the device from the specified topic.

Event procedures:

Call event procedures from corresponding event handlers, as described here.

mqtt_proc_timer() — call this from the on_sys_timer() event handler.

mqtt_proc_data() — call this from the on_sock_data_arrival() event handler.

Callback procedures:

Implement the bodies of callback procedures elsewhere in your project.

callback_mqtt_connect_ok() — called when the device successfully connects to the MQTT server.

callback_mqtt_connect_lost() — called when connection to the MQTT server is lost.

callback_mqtt_notif() — called when the subscriber receives a message from the MQTT server.

callback_mqtt_sub_ok() — called on the subscriber when the MQTT server confirms the requested subscription.

Required buffer space:

2 buffer pages. More may be needed depending on the nature of MQTT topics used.