#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if !defined(_WIN32)
#include <unistd.h>
#else
#include <windows.h>
#endif
#if defined(_WRS_KERNEL)
#include <OsWrapper.h>
#endif
#define ADDRESS "tcp://mqtt.eclipseprojects.io:1883"
#define CLIENTID "ExampleClientPub"
#define TOPIC "MQTT Examples"
#define PAYLOAD "Hello World!"
#define QOS 1
#define TIMEOUT 10000L
int finished = 0;
void connlost(void *context, char *cause)
{
int rc;
printf("\nConnection lost\n");
printf(" cause: %s\n", cause);
printf("Reconnecting\n");
{
printf("Failed to start connect, return code %d\n", rc);
finished = 1;
}
}
{
printf("Disconnect failed\n");
finished = 1;
}
{
printf("Successful disconnection\n");
finished = 1;
}
{
int rc;
printf(
"Message send failed token %d error code %d\n", response->
token, response->
code);
{
printf("Failed to start disconnect, return code %d\n", rc);
exit(EXIT_FAILURE);
}
}
{
int rc;
printf(
"Message with token value %d delivery confirmed\n", response->
token);
{
printf("Failed to start disconnect, return code %d\n", rc);
exit(EXIT_FAILURE);
}
}
{
printf(
"Connect failed, rc %d\n", response ? response->
code : 0);
finished = 1;
}
{
int rc;
printf("Successful connection\n");
{
printf("Failed to start sendMessage, return code %d\n", rc);
exit(EXIT_FAILURE);
}
}
int messageArrived(
void* context,
char* topicName,
int topicLen,
MQTTAsync_message* m)
{
return 1;
}
int main(int argc, char* argv[])
{
int rc;
{
printf("Failed to create client object, return code %d\n", rc);
exit(EXIT_FAILURE);
}
{
printf("Failed to set callback, return code %d\n", rc);
exit(EXIT_FAILURE);
}
{
printf("Failed to start connect, return code %d\n", rc);
exit(EXIT_FAILURE);
}
printf("Waiting for publication of %s\n"
"on topic %s for client with ClientID: %s\n",
PAYLOAD, TOPIC, CLIENTID);
while (!finished)
#if defined(_WIN32)
Sleep(100);
#else
usleep(10000L);
#endif
return rc;
}