34 #include <Minwinbase.h> 37 #if defined(_WRS_KERNEL) 41 #if defined(_WIN32) || defined(_WIN64) 42 #define snprintf _snprintf 47 #define ADDRESS "tcp://localhost:1883" 49 #define CLIENTID "ExampleClientTimePub" 50 #define TOPIC "data/time" 52 #define TIMEOUT 10000L 53 #define SAMPLE_PERIOD 10L // in ms 64 printf(
"\nConnection lost\n");
65 printf(
" cause: %s\n", cause);
67 printf(
"Reconnecting\n");
72 printf(
"Failed to start connect, return code %d\n", rc);
79 printf(
"Disconnect failed\n");
85 printf(
"Successful disconnection\n");
95 printf(
"Message send failed token %d error code %d\n", response->
token, response->
code);
101 printf(
"Failed to start disconnect, return code %d\n", rc);
114 printf(
"Connect failed, rc %d\n", response ? response->
code : 0);
121 printf(
"Successful connection\n");
135 GetSystemTimeAsFileTime(&ft);
136 return ((((int64_t) ft.dwHighDateTime) << 8) + ft.dwLowDateTime) / 10000;
139 clock_gettime(CLOCK_REALTIME, &ts);
140 return ((int64_t) ts.tv_sec * 1000) + ((int64_t) ts.tv_nsec / 1000000);
144 int main(
int argc,
char* argv[])
156 printf(
"Failed to create client object, return code %d\n", rc);
162 printf(
"Failed to set callback, return code %d\n", rc);
173 printf(
"Failed to start connect, return code %d\n", rc);
189 int n = snprintf(buf,
sizeof(buf),
"%lld", (
long long) t);
203 printf(
"Failed to start sendMessage, return code %d\n", rc);
MQTTAsync_onFailure * onFailure
void onSend(void *context, MQTTAsync_successData *response)
#define MQTTAsync_responseOptions_initializer
int MQTTAsync_disconnect(MQTTAsync handle, const MQTTAsync_disconnectOptions *options)
int MQTTAsync_setCallbacks(MQTTAsync handle, void *context, MQTTAsync_connectionLost *cl, MQTTAsync_messageArrived *ma, MQTTAsync_deliveryComplete *dc)
int main(int argc, char *argv[])
MQTTAsync_responseOptions pub_opts
int messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *m)
int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions *options)
MQTTAsync_connectOptions conn_opts
int MQTTAsync_create(MQTTAsync *handle, const char *serverURI, const char *clientId, int persistence_type, void *persistence_context)
#define MQTTAsync_disconnectOptions_initializer
MQTTAsync_onFailure * onFailure
MQTTAsync_onFailure * onFailure
#define MQTTAsync_connectOptions_initializer
MQTTAsync_onSuccess * onSuccess
void connlost(void *context, char *cause)
void onConnect(void *context, MQTTAsync_successData *response)
void MQTTAsync_destroy(MQTTAsync *handle)
#define MQTTASYNC_SUCCESS
int MQTTAsync_sendMessage(MQTTAsync handle, const char *destinationName, const MQTTAsync_message *message, MQTTAsync_responseOptions *response)
#define MQTTCLIENT_PERSISTENCE_NONE
void onSendFailure(void *context, MQTTAsync_failureData *response)
void onDisconnectFailure(void *context, MQTTAsync_failureData *response)
void onDisconnect(void *context, MQTTAsync_successData *response)
#define MQTTAsync_message_initializer
void onConnectFailure(void *context, MQTTAsync_failureData *response)
MQTTAsync_onSuccess * onSuccess
MQTTAsync_onSuccess * onSuccess