QT-mosquittopp use tls method



  • I want to use raspberrypi qt mqtt client, in the process I have joined tls. But I can not connect to mosquitto. I use the command was successfully transferred.
    This is my mosquitto.conf
    //
    listener 8883
    log_dest file /var/log/mosquitto/mosquitto.log
    cafile /etc/mosquitto/ca_certificates/ca.crt
    certfile /etc/mosquitto/certs/raspberrypi.crt
    keyfile /etc/mosquitto/certs/raspberrypi.key
    require_certificate false
    tls_version tlsv1
    include_dir /etc/mosquitto/conf.d
    //
    Here is the code
    //
    ui->lineIP->setText(QString("0.0.0.0"));
    ui->linePort->setText(QString("8883"));
    QByteArray host = ui->lineIP->text().toLocal8Bit();
    QByteArray id = ui->lineID->text().toLocal8Bit();
    QByteArray pwd = ui->lineEdit->text().toLocal8Bit();
    QByteArray pws = ui->lineEdit_2->text().toLocal8Bit();
    port = ui->linePort->text().toInt();
    if (!port)
    {
    ui->linePort->clear();
    return ;
    }
    ui->connect->setDisabled(true);
    mosq = new qtmosq(id, false);
    mosq->tls_opts_set(1,"tlsv1",NULL);
    mosq->tls_set("/etc/mosquitto/ca_certificate/ca.crt",NULL,"/etc/mosquitto/certs/raspberrypi.crt","/etc/mosquitto/certs/raspberrypi.key",NULL);
    mosq->connect_async(host.data(), port);
    mosq->username_pw_set(pwd.data(),pws.data());
    mosq->loop_start();
    connect (mosq, SIGNAL(connectEnable()), this, SLOT(connectEnabled()));
    connect (mosq, SIGNAL(subscribed()), this ,SLOT(subscribed()));
    connect (mosq, SIGNAL(connected()), this, SLOT(connected()));
    connect (mosq, SIGNAL(messageSent(bool)), this, SLOT(setMessageStatus(bool)));
    connect (mosq, SIGNAL(messageReceived(QString)), this, SLOT(showMessage(QString)));
    //
    How can I use tls through mosquittopp.h?Is there anything I made wrong?I need your recommendations to solve this issue.Thank you


  • Lifetime Qt Champion

    Hi,

    That's a question you should ask the author of that library.

    Or maybe consider using the official QtMqtt module.



  • @SGaist Thank you a lot,I will try to found method in your link.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.