Step-by-step Usage Instructions
|Top Previous Next|
1. Make sure you have the SOCK library in your project.
2. Add mqtt.tbs and mqtt.tbh files to your project (they are in current_library_set\mqtt\trunk).
3. Add #define MQTT_DEBUG_PRINT 1 to the defines section of the global.tbh file of your project. This way you will "see what's going on". Don't forget to remove this later, after you've made sure that the library operates as expected. Debug printing really slows things down!
4. Add include "mqtt\trunk\mqtt.tbh" to the Includes section of the global.tbh file.
7. Add the following into the on_sys_init() event handler:
▪Add mqtt_start() to initialize the library;
▪Add mqtt_connect() with correct MQTT server (broker) parameters to initiate the connection to the server.
oIf your device is a publisher, implement the code that invokes mqtt_publish() at the appropriate times.
8. Create callback function bodies somewhere in your project (for example, in the device.tbs file):
▪Callback_mqtt_connect_ok() — you may leave this sub empty;
▪Callback_mqtt_notif() — if your device is a subscriber, then this is where you place the code that reacts to notification messages from the MQTT server.
▪Callback_mqtt_sub_ok() — you may leave this sub empty.