Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <MQTTAsync.h>
- #include <stdio.h>
- int connection = 0;
- void connlost(void *context, char *cause)
- {
- connection = 0;
- printf("Connection lost! (%s)\n", cause);
- }
- void connsuccess(void *context, MQTTAsync_successData *response)
- {
- connection = 1;
- printf("Connection success!\n");
- }
- void connfailure(void *context, MQTTAsync_failureData *response)
- {
- connection = 0;
- printf("Connection failure!\n");
- }
- int main()
- {
- MQTTAsync client;
- MQTTAsync_connectOptions conn_opts = MQTTAsync_connectOptions_initializer;
- conn_opts.keepAliveInterval = 3;
- conn_opts.connectTimeout = 10;
- conn_opts.retryInterval = 5;
- conn_opts.cleansession = 1;
- conn_opts.onSuccess = connsuccess;
- conn_opts.onFailure = connfailure;
- conn_opts.context = NULL;
- MQTTAsync_create(&client, "localhost", "idddd", MQTTCLIENT_PERSISTENCE_NONE, NULL);
- MQTTAsync_setCallbacks(client, 0, connlost, NULL, NULL);
- for (;;) {
- if (!connection) {
- MQTTAsync_connect(client, &conn_opts);
- }
- sleep(1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement