Paho C library SSL connection to MQTT broker not working [message #1733266] |
Wed, 25 May 2016 21:32 |
Sanket Deshpande Messages: 9 Registered: August 2015 |
Junior Member |
|
|
Hello,
I have the following code to connect to a MQTT broker via SSL:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include "MQTTClient.h"
int msgarrvd(void *context, char *topicName, int topicLen, MQTTClient_message *message)
{
printf("Response auth: %s\n", (char *) message->payload);
MQTTClient_freeMessage(&message);
MQTTClient_free(topicName);
return 1;
}
int main(int argc, char* argv[]) {
MQTTClient mqttClient;
MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer;
MQTTClient_SSLOptions sslOptions = MQTTClient_SSLOptions_initializer;
sslOptions.trustStore = "/etc/ssl/certs/ca-certificates.crt";
int rc, ch;
MQTTClient_create(&mqttClient, "ssl://brokerAddress:8905", "test", MQTTCLIENT_PERSISTENCE_NONE, NULL);
conn_opts.keepAliveInterval = 20;
conn_opts.cleansession = 1;
conn_opts.username = "username";
conn_opts.password = "password";
conn_opts.ssl = &sslOptions;
MQTTClient_setCallbacks(mqttClient, NULL, NULL, msgarrvd, NULL);
if ((rc = MQTTClient_connect(mqttClient, &conn_opts)) != MQTTCLIENT_SUCCESS)
{
printf("Failed to connect, return code %d\n Error: %s\n", rc, strerror(errno));
exit(-1);
}
MQTTClient_subscribe(mqttClient, "testtopic", 0);
do
{
ch = getchar();
} while(ch!='Q' && ch != 'q');
MQTTClient_disconnect(mqttClient, 10000);
MQTTClient_destroy(&mqttClient);
return 0;
}
I have tried to connect via SSL using the Paho Java client and everything works great but I cannot connect using the C library.
Any help would be super cool!
Thanks!
[Updated on: Wed, 01 June 2016 14:54] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03711 seconds