36 #if defined(_WRS_KERNEL) 44 1, 0, 0, 0,
"\n", 100,
46 MQTTVERSION_DEFAULT, NULL,
"paho-c-pub", 0, 0, NULL, NULL,
"localhost",
"1883", NULL, 10,
48 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
99 fprintf(stderr,
"Connect failed, rc %s reason code %s\n",
122 printf(
"Connected\n");
131 char* buffer =
readfile(&data_len, &opts);
137 rc =
mypublish(client, data_len, buffer);
151 printf(
"Connected\n");
160 char* buffer =
readfile(&data_len, &opts);
166 rc =
mypublish(client, data_len, buffer);
180 fprintf(stderr,
"Publish failed, rc %s reason code %s\n",
197 printf(
"Publish succeeded, reason code %s\n",
210 printf(
"Publish succeeded\n");
222 return fprintf(stderr,
"SSL error: %s\n", str);
227 unsigned int max_identity_len,
229 unsigned int max_psk_len,
248 psk_len = (int)strlen(opts->
psk) / 2;
249 if (psk_len > max_psk_len)
251 fprintf(stderr,
"PSK too long\n");
254 for (k=0, n=0; k < psk_len; k++, n += 2)
256 sscanf(&opts->
psk[n],
"%2hhx", &psk[k]);
260 strncpy(identity, opts->
psk_identity, max_identity_len);
261 if (identity[max_identity_len - 1] !=
'\0')
263 fprintf(stderr,
"Identity too long\n");
282 printf(
"Connecting\n");
286 conn_opts = conn_opts5;
310 conn_opts.
will = &will_opts;
330 conn_opts.
ssl = &ssl_opts;
347 printf(
"Publishing data of length %d\n", datalen);
359 fprintf(stderr,
"Trace : %d, %s\n", level, message);
363 int main(
int argc,
char** argv)
370 int url_allocated = 0;
373 const char* program_name =
"paho_c_pub";
382 if (
getopts(argc, argv, &opts) != 0)
391 sprintf(url,
"%s:%s", opts.
host, opts.
port);
394 printf(
"URL is %s\n", url);
409 fprintf(stderr,
"Failed to create client, return code: %s\n",
MQTTAsync_strerror(rc));
417 memset(&sa, 0,
sizeof(
struct sigaction));
421 sigaction(SIGINT, &sa, NULL);
422 sigaction(SIGTERM, &sa, NULL);
429 fprintf(stderr,
"Failed to set callbacks, return code: %s\n",
MQTTAsync_strerror(rc));
475 buffer[data_len++] = getchar();
476 if (data_len > delim_len)
478 if (strncmp(opts.
delimiter, &buffer[data_len - delim_len], delim_len) == 0)
483 rc =
mypublish(client, data_len, buffer);
499 fprintf(stderr,
"Failed to start disconnect, return code: %s\n",
MQTTAsync_strerror(rc));
MQTTAsync_onFailure * onFailure
int MQTTAsync_createWithOptions(MQTTAsync *handle, const char *serverURI, const char *clientId, int persistence_type, void *persistence_context, MQTTAsync_createOptions *options)
MQTTAsync_onFailure5 * onFailure5
int sendWhileDisconnected
void onConnectFailure5(void *context, MQTTAsync_failureData5 *response)
#define MQTTAsync_responseOptions_initializer
char * readfile(int *data_len, struct pubsub_opts *opts)
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)
void trace_callback(enum MQTTASYNC_TRACE_LEVELS level, char *message)
int mypublish(MQTTAsync client, int datalen, char *data)
const char * MQTTReasonCode_toString(enum MQTTReasonCodes value)
void usage(struct pubsub_opts *opts, pubsub_opts_nameValue *name_values, const char *program_name)
int MQTTProperties_add(MQTTProperties *props, const MQTTProperty *prop)
MQTTAsync_nameValue * MQTTAsync_getVersionInfo(void)
MQTTAsync_responseOptions pub_opts
enum MQTTReasonCodes reasonCode
MQTTAsync_onSuccess5 * onSuccess5
void MQTTAsync_setTraceCallback(MQTTAsync_traceCallback *callback)
int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions *options)
MQTTAsync_connectOptions conn_opts
static unsigned int onPSKAuth(const char *hint, char *identity, unsigned int max_identity_len, unsigned char *psk, unsigned int max_psk_len, void *context)
#define MQTTAsync_willOptions_initializer
#define MQTTAsync_connectOptions_initializer5
void onPublishFailure5(void *context, MQTTAsync_failureData5 *response)
#define MQTTAsync_disconnectOptions_initializer
MQTTAsync_onFailure * onFailure
MQTTAsync_onFailure5 * onFailure5
void onDisconnect(void *context, MQTTAsync_successData *response)
void onPublish5(void *context, MQTTAsync_successData5 *response)
int main(int argc, char **argv)
unsigned int(* ssl_psk_cb)(const char *hint, char *identity, unsigned int max_identity_len, unsigned char *psk, unsigned int max_psk_len, void *u)
void onDisconnect5(void *context, MQTTAsync_successData5 *response)
void onPublish(void *context, MQTTAsync_successData *response)
void onConnectFailure(void *context, MQTTAsync_failureData *response)
#define MQTTAsync_createOptions_initializer
MQTTAsync_SSLOptions * ssl
#define MQTTAsync_connectOptions_initializer
MQTTAsync_onSuccess * onSuccess
void onConnect5(void *context, MQTTAsync_successData5 *response)
MQTTAsync_willOptions * will
const char * privateKeyPassword
const char * enabledCipherSuites
int MQTTAsync_send(MQTTAsync handle, const char *destinationName, int payloadlen, const void *payload, int qos, int retained, MQTTAsync_responseOptions *response)
MQTTProperties properties
void MQTTAsync_destroy(MQTTAsync *handle)
#define MQTTASYNC_SUCCESS
void MQTTAsync_setTraceLevel(enum MQTTASYNC_TRACE_LEVELS level)
#define MQTTCLIENT_PERSISTENCE_NONE
enum MQTTReasonCodes reasonCode
const char * MQTTAsync_strerror(int code)
static int onSSLError(const char *str, size_t len, void *context)
#define MQTTAsync_SSLOptions_initializer
MQTTAsync_onSuccess5 * onSuccess5
void onPublishFailure(void *context, MQTTAsync_failureData *response)
int getopts(int argc, char **argv, struct pubsub_opts *opts)
void myconnect(MQTTAsync client)
MQTTAsync_onSuccess * onSuccess
#define MQTTVERSION_DEFAULT
MQTTAsync_onSuccess5 * onSuccess5
void onConnect(void *context, MQTTAsync_successData *response)
int messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *m)
MQTTAsync_onSuccess * onSuccess
int(* ssl_error_cb)(const char *str, size_t len, void *u)
struct pubsub_opts::@69 user_property
#define MQTTProperties_initializer