Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] Cannot connect to Azure IoTHub in SSL with C paho library

Good news!  That explains it - the tracing output routine flushes stdout.

Thanks.


On 11/04/2018 16:12, Francesco Viggiano wrote:
I've solved the problem by simply adding a fflush() in each callback. It was this simple, but in my previous tests, i.e. connecting to a public broker without tls/ssl, there was no need of fflush().

>> To be clear, with tracing off, you just see the message from connect failure callback.  
Correct.

>> With tracing on, you see onConnectFailure as well as onConnect?  Or just onConnect and onMessage?
with tracing on (and with tracing off and fflush()) I see everything.

Thanks again for you help, very precious.



On Wed, Apr 11, 2018 at 2:50 PM Ian Craggs <icraggs@xxxxxxxxxxxxxxxxxxxxxxx> wrote:

I'm struggling to find a logical explanation for that, apart from the old "the bug disappears when I turn tracing on" scenario.

To be clear, with tracing off, you just see the message from connect failure callback. 

With tracing on, you see onConnectFailure as well as onConnect?  Or just onConnect and onMessage?

Ian


On 11/04/2018 11:52, Francesco Viggiano wrote:
Hi Ian, 

Your advice is actually quite helpful. I can see in the trace that my client is connecting succesfully and it's also receiving messages.
I have some printf  in the onConnect(), onConnectFailure(), onMessageReceive() that I can see if the trace is on, but I don't see them with the trace off.

How is that possibile?

Many thanks.

On Wed, Apr 11, 2018 at 11:45 AM Ian Craggs <icraggs@xxxxxxxxxxxxxxxxxxxxxxx> wrote:

Francesco,

it could help to take a client trace.   Set the environment variable:

MQTT_C_CLIENT_TRACE=ON (or a filename)

Also, it's probably easier to manage the discussion in a Github issue.  Thanks,

Ian


On 11/04/2018 10:19, Francesco Viggiano wrote:

Hello everyone and thanks in advance for your support.

 

I cannot connect to Azure IoTHub via the C paho library (on linux). I’m using the latest release, v1.2.1.

I’m following the official Microsoft documentation here (https://docs.microsoft.com/it-it/azure/iot-hub/iot-hub-mqtt-support).

I have managed to successfully connect with both the python library (un Ubuntu) and the Java GUI client (on Windows) and to exchange messages, so I guess the credentials I’m using are correct.

 

I'm compiling the C paho library, altough my application is in C++, I don't know if this can be a problem.

What happens after I try to Connect is connectFailure with a null response pointer.


This is a snippet of my MQTT_connect() function, linked against the mqtt3as library:



#define MQTT_BROKER_ADDRESS "ssl://xxx:8883"                              

                                                                                                                

void onConnectFailure(void* context, MQTTAsync_failureData* response)                                                                                                                                               

{                                                                                                                                                                                                                   

  printf("Connect failed, rc %d %s\n", response ? response->code : 0, response->message);                                                                                                                              }  


 int main() {}

  char clientID[] = "xxxx";                                                                                                                                                                                 

  MQTTAsync_connectOptions conn_opts = MQTTAsync_connectOptions_initializer;                                                                                                                                       

  MQTTAsync_SSLOptions ssl_opts = MQTTAsync_SSLOptions_initializer;                                                                                                                                                

                                                                                                                                                                                                                    

  //MQTTAsync_willOptions will_opts = MQTTAsync_willOptions_initializer;                                                                                                                                            

                                                                                                                                                                                                                    

  MQTTAsync_create(&client, MQTT_BROKER_ADDRESS, clientID,                                                                                                                                                         

                   MQTTCLIENT_PERSISTENCE_NONE, NULL);                                                                                                                                                             

                                                                                                                                                                                                                   

  MQTTAsync_setCallbacks(client, client, NULL, OnMessageArrived, NULL);                                                                                                                                            

                                                                                                                                                                                                                                                       

  string username = "xxxx";                                                                                                                                                   

  string password = "xxxx ";                                           

                                                                                                                                                                                                                    

  //ssl_opts.struct_version = 2;                                                                                                                                                                                   

  ssl_opts.enableServerCertAuth = 1;                                                                                                                                                                               

  ssl_opts.sslVersion = MQTT_SSL_VERSION_TLS_1_2;                                                                                                                                                                  

  ssl_opts.trustStore = "/etc/ssl/certs/Baltimore_CyberTrust_Root.pem";                                                                                                                                            

  //ssl_opts.keyStore ="/etc/ssl/certs/ca-certificates.crt";                                                                                                                                                        

  //ssl_opts.CApath = "/etc/ssl/certs";                                                                                                                                                                             

  //ssl_opts.enabledCipherSuites="TLSv1";                                                                                                                                                                           

                                                                                                                                                                                                                   

  //conn_opts.keepAliveInterval = MQTT_KEEPALIVE;                                                                                                                                                                  

  //conn_opts.cleansession = MQTT_CLEAN_SESSION;                                                                                                                                                                    

  //conn_opts.will = &will_opts;                                                                                                                                                                                   

                                                                                                                                                                                                                    

  conn_opts.username = username.c_str();                                                                                                                                                                           

  conn_opts.password = password.c_str();                                                                                                                                                                           

                                                                                                                                                                                                                    

  //conn_opts.connectTimeout = MQTT_TIMEOUT;                                                                                                                                                                        

  conn_opts._onSuccess_ = onConnect;                                                                                                                                                                                  

  conn_opts._onFailure_ = onConnectFailure;                                                                                                                                                                           

  conn_opts.context = client;                                                                                                                                                                                      

  //conn_opts.automaticReconnect = 0;                                                                                                                                                                               

  conn_opts.ssl = &ssl_opts;                                                                                                                                                                                        

  conn_opts.MQTTVersion = 4;                                                                                                                                                                                       

                                                                                                                                                                                                                    

//  gAppLog.PrintLog(LOG_DEBUG_WS, "MQTT connecting to: %s", MQTT_BROKER_ADDRESS);                                                                                                                                 

  printf("host: %s \nclientID: %s \nusername: %s \npassword: %s \n", MQTT_BROKER_ADDRESS,clientID,username.c_str(), password.c_str());                                                                             

                                                                                                                                                                                                                    

  int rc;                                                                                                                                                                                                          

  rc = MQTTAsync_connect(client, &conn_opts);

 }

--
Francesco


_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/paho-dev

-- 
Ian Craggs
icraggs@xxxxxxxxxx                 IBM United Kingdom
Eclipse Paho Project Lead & Mosquitto Committer
_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/paho-dev
--
Francesco


_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/paho-dev

-- 
Ian Craggs
icraggs@xxxxxxxxxx                 IBM United Kingdom
Eclipse Paho Project Lead & Mosquitto Committer
_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/paho-dev
--
Francesco


_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/paho-dev

-- 
Ian Craggs
icraggs@xxxxxxxxxx                 IBM United Kingdom
Eclipse Paho Project Lead & Mosquitto Committer

Back to the top