Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » Paho C library SSL connection to MQTT broker not working
Paho C library SSL connection to MQTT broker not working [message #1733266] Wed, 25 May 2016 21:32 Go to next message
Sanket Deshpande is currently offline Sanket DeshpandeFriend
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

Re: Paho C library SSL connection to MQTT broker not working [message #1733766 is a reply to message #1733266] Tue, 31 May 2016 14:30 Go to previous messageGo to next message
Sanket Deshpande is currently offline Sanket DeshpandeFriend
Messages: 9
Registered: August 2015
Junior Member
So does nobody have an idea about the C library?
Re: Paho C library SSL connection to MQTT broker not working [message #1751085 is a reply to message #1733266] Wed, 04 January 2017 11:26 Go to previous messageGo to next message
alice alex is currently offline alice alexFriend
Messages: 5
Registered: January 2017
Junior Member
Hi ,
I also have similar issue.If you got the solution please post
Re: Paho C library SSL connection to MQTT broker not working [message #1751577 is a reply to message #1733266] Wed, 11 January 2017 16:05 Go to previous message
paulo balbino is currently offline paulo balbinoFriend
Messages: 2
Registered: January 2017
Junior Member
I am having the same problem, the SSL does not work at all, the samples provided test5.cpp fails, and on the wireshark I cant see SSL traffic.
Previous Topic:How to enable SSL over ActiveMQ using C client
Next Topic:Publishing the Mqtt messages
Goto Forum:
  


Current Time: Thu Apr 25 19:53:37 GMT 2024

Powered by FUDForum. Page generated in 0.03480 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top