[SOLVED] MQTTClient_create function fails when using paho MQTT in eclipse

Hi,

I am using eclipse IDE to write a sample application to connect and send data to ubidots cloud. I am using paho MQTT protocol. My code is exiting after MQTTClient_create function with error code

Following is my code snippet

#include "mraa.hpp"
extern "C" {
#include "MQTTClient.h"
}

#include "stdlib.h"
#include <iostream>
MQTTClient client;
#define MESSAGE_TOPIC "/v1.6/devices/dummy_db"
#define HOST_PROTO "mqtt://"
#define HOST_SUFFIX "things.ubidots.com:"
#define HOST_PORT "1883"
const char * ubidots_username = "MY_TOKEN_FROM_DASHBOARD";
const char * ubidots_password = "";
int main()
{
	char host[256];
       snprintf(host, sizeof host, "%s%s%s", HOST_PROTO ,HOST_SUFFIX, HOST_PORT);
       int rc = 0;
        rc = MQTTClient_create(&client, const_cast<char *>(host), NULL, MQTTCLIENT_PERSISTENCE_NONE, NULL);
	if (rc != MQTTCLIENT_SUCCESS) {
		std::cerr << "Failed to create MQTT client, exiting" << std::endl;
		exit(rc);
	}
MQTTClient_setCallbacks(client, NULL,
			&connection_lost, NULL, &delivery_complete);
data.username = const_cast<char *>(ubidots_username);
	data.password = const_cast<char *>(ubidots_password);
rc = MQTTClient_connect(client, &data);
	if (rc != MQTTCLIENT_SUCCESS) {
		std::cerr << "Failed to connect MQTT client, exiting" << std::endl;
		exit(rc);
	}

My code is failing at client_create itself.

I solved the above issue. Error was client ID being passed as NULL. I created a dummy client ID and passed that as a parameter in MQTTClient_create function. Also the password field has to be set as NULL instead of “”. Now I can publish my data and I can see the variable set in my source getting updated.

I now need help in simulating an actuation. I created an Event that if my dummy value is 50, it sets another variable buzzer as 1. But I need to send this updated buzzer data back to my device. I have implemented the MQTTClient_messageArrived callback function, but this function was not invoked when the buzzer value was changed to 1.

Do I need to subscribe to the buzzer variable for invoking the message arrived callback function? Also, how do I co-related the TOPIC field specified in Paho MQTT to the fields in dashboard (it it source or variables? )

Any help will be appreciated.