Skip to content

Latest commit

 

History

History
34 lines (26 loc) · 735 Bytes

README.md

File metadata and controls

34 lines (26 loc) · 735 Bytes

libmqtthelper

This library is used to simplefy implementation of mqtt clients in C and C++ services.

#include "mqtthelper.h"

int hello_cb(void *notused, const char *topic, void *msg, int msg_len, void *user_data)
{
  return 0;
}

int main(int argc, char* argv[])
{
    int ret = 0;

    // Init the Mosquitto
    mqtt_helper_init();
    // Subscribe to topic
    ret = mqtt_helper_add("hello/world",      &hello_cb,       NULL, NULL);
    
    mqtt_helper_connection_monitor();
    
    // Send a message.
    const char* payload = "Let's make this greate";
    mqtt_helper_publish("hello/strange", payload, strlen(payload));
    
    while( true ) {
      // Do stuff.
    }
    mqtt_helper_cleanup();
    return 0;   
}