Step-by-step Usage Instructions
- Make sure you have the SOCK library in your project.
- Add mqtt.tbs and mqtt.tbh files to your project (they are in current_library_set\mqtt\trunk).
- 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!
- Add include "mqtt\trunk\mqtt.tbh" to the Includes section of the global.tbh file.
- Add mqtt_proc_timer() to the on_sys_timer() event handler code.
- Add mqtt_proc_data() to the on_sock_data_arrival() event handler code.
- Add the following into the on_sys_init() event handler:
- If your device is a publisher, implement the code that invokes [mqtt_publish()](mqtt_publish) at the appropriate times.
- 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_connect_lost() — at the very minimum, the body of this function should include a call to mqtt_reconnect();
- 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.