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.