Giter VIP home page Giter VIP logo

qmqtt's Introduction

QMQTT

mqtt client for Qt

Please compile the library with Qt >= 5.3 version. On Windows you need to specify CONFIG += NO_UNIT_TESTS, since gtest is not supported.

SSL is enabled by default, if the version of OpenSSL < 1.0.2, SSL may not be supported.

Disable the SSL in CMakeLists.txt (cmake):

option( ${PROJECT_NAME}_SSL "Enable SSL support for MQTT" OFF )

Disable the SSL with src/mqtt/qmqtt.pro (qmake):

CONFIG+=QMQTT_NO_SSL

To add websocket support, compile the library with Qt >= 5.7, and specify 'CONFIG += QMQTT_WEBSOCKETS'. This also works when compiling qmqtt for WebAssembly.

Usage

In your QMake project, add:

QT += qmqtt

Connect using TCP:

#include "qmqtt.h"

QMQTT::Client *client = new QMQTT::Client(QHostAddress::LocalHost, 1883);
client->setClientId("clientId");
client->setUsername("user");
client->setPassword("password");
client->connectToHost();

Connect using SSL:

QSslConfiguration sslConfig = QSslConfiguration::defaultConfiguration();
// Add custom SSL options here (for example extra certificates)
QMQTT::Client *client = new QMQTT::Client("example.com", 8883, sslConfig);
client->setClientId("clientId");
client->setUsername("user");
client->setPassword("password");
// Optionally, set ssl errors you want to ignore. Be careful, because this may weaken security.
// See QSslSocket::ignoreSslErrors(const QList<QSslError> &) for more information.
client->ignoreSslErrors(<list of expected ssl errors>)
client->connectToHost();
// Here's another option to suppress SSL errors (again, be careful)
QObject::connect(client, &QMQTT::Client::sslErrors, [&](const QList<QSslError> &errors) {
    // Investigate the errors here, if you find no serious problems, call ignoreSslErrors()
    // to continue connecting.
    client->ignoreSslErrors();
});

Connect using WebSockets:

QMQTT::Client *client = new QMQTT::Client("ws://www.example.com/mqtt", "<origin>", QWebSocketProtocol::VersionLatest);
client->setClientId("clientId");
client->setUsername("user");
client->setPassword("password");
client->connectToHost();

Slots

void setHost(const QHostAddress& host);
void setPort(const quint16 port);
void setClientId(const QString& clientId);
void setUsername(const QString& username);
void setPassword(const QString& password);
void setKeepAlive(const int keepAlive);
void setCleanSession(const bool cleansess);
void setAutoReconnect(const bool value);
void setAutoReconnectInterval(const int autoReconnectInterval);
void setWillTopic(const QString& willTopic);
void setWillQos(const quint8 willQos);
void setWillRetain(const bool willRetain);
void setWillMessage(const QString& willMessage);

void connectToHost();
void disconnectFromHost();

quint16 subscribe(const QString& topic, const quint8 qos);
void unsubscribe(const QString& topic);

quint16 publish(const Message& message);

Signals

void connected();
void disconnected();
void error(const QMQTT::ClientError error);

void subscribed(const QString& topic, const quint8 qos);
void unsubscribed(const QString& topic);
void published(const quint16 msgid, const quint8 qos);
void pingresp();
void received(const QMQTT::Message& message);

License

New BSD License

Contributors

@avsdev-cw, @alex-spataru, Benjamin Schmitz, @bf-bryants, @bog-dan-ro, @chsterz, @cncap, @ejvr, @ehntoo, Erik Botö, Guillaume Bour, @halfgaar, @hxcan, @jpnurmi, Kai Dohmen, @Kampfgnom, @keytee, @kollix, @KonstantinRitt, @maggu2810, @mwallnoefer, @NicoWallmeier, Niklas Wulf, Niraj Desai, @Psy-Kai, @rafaeldelucena, @rokm, sgaoemq, @Vortex375, ybq

Authors

@emqplus Feng Lee [email protected]

@wguynes William Guynes [email protected]

@wuming123057 Xuan [email protected]

qmqtt's People

Contributors

mwallnoefer avatar ejvr avatar wguynes avatar wuming123057 avatar konstantinritt avatar alex-spataru avatar bf-bryants avatar avsdev-cw avatar rafaeldelucena avatar jpnurmi avatar bog-dan-ro avatar wanghaemq avatar sbradford26 avatar xinyi-xs avatar halfgaar avatar v1l3g0d avatar rokm avatar kampfgnom avatar nicowallmeier avatar ehntoo avatar kollix avatar maggu2810 avatar keytee avatar hxcan avatar h1msk avatar chsterz avatar cncap avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.