Code Monkey home page Code Monkey logo

qtmqtt's Introduction

THIS PROJECT IS DISCONTINUED! FEEL FREE TO FORK AND WORK ON ;)

About

This project provides the abilty to establish MQTT connections and to perform MQTT communication using Qt. This library consists of two parts:

  • Qt/C++ Library
  • QML Plugin

Credits

For the most part it's a "merge" of the work of the people mentioned below, marely refactored for the sake of readability and to fit particular needs.

Special thanks to the owners of the used repositories and contributors:

There are much more contributors which aren't less important! Please refer to the licence headers in each file and the repositories below for detailed information about authors.

Sourcecode taken from:

Compatibility

This library has been compiled and tested on:

  • Fedora 22 x64 - Qt 5.5.1
  • Android NDK r10e-rc4 (64-bit) - Qt 5.5.1
  • Windows 7 x64 - Qt 5.5.1

Build

git clone https://github.com/toni1991/QtMqtt.git && cd QtMqtt
mkdir build && cd build
qmake ..
make
make install

Caution: The installation with 'make install' is not fully tested but should work!

Mac

Tested make install on Mac library installed in /usr/local/lib and header files in /usr/local/include/qmqtt

Qt/C++

Example usage

#include "qmqtt.h"

[...]

QMQTT::Client client("localhost", 1883);
m_client->setClientId(m_clientId);
QObject::connect(client, &QMQTT::Client::received, this, &messageReceived);
m_client->connect();

[...]

void QmlQmqtt::messageReceived(const QMQTT::Message &message)
{
    qDebug() << "Topic: " << arg.topic();
    qDebug() << "Payload: " << arg.payload();
}

Signals

 - connected()
 - error(QAbstractSocket::SocketError)
 - connacked(quint8 ack)
 - published(QMQTT::Message &message)
 - pubacked(quint8 type, quint16 msgid)
 - received(const QMQTT::Message &message)
 - subscribed(const QString &topic)
 - subacked(quint16 mid, quint8 qos)
 - unsubscribed(const QString &topic)
 - unsubacked(quint16 mid)
 - pong()
 - disconnected()

Slots

- void onConnected()
- void onDisconnected()
- void onReceived(Frame & frame)
- void handlePublish(Message &message)
- void handleConnack(quint8 ack)
- void handlePuback(quint8 type, quint16 msgid)

QML Plugin

Example usage

import QmlQmqtt 1.0
QmlQmqtt{
    id: qmlqmqtt
    host: "localhost"
    port: 1883
    onConnected: qmlqmqtt.subscribe("#")
    onMessageReceived: {
        console.log("topic:",topic)
        console.log("payload:",payload)
    }
    Component.onCompleted: qmlqmqtt.connect()
}

Properties

- bool autoReconnect
- bool cleanSession
- int keepalive
- int port
- QString clientId
- QString host
- QString password
- QString username

Signals

- autoReconnectChanged(bool cleanSession)
- cleanSessionChanged(bool cleanSession)
- clientIdChanged(QString clientId)
- connacked(quint8 ack)
- connected()
- disconnected()
- error(QAbstractSocket::SocketError error)
- hostChanged(QString host)
- keepaliveChanged(int keepalive)
- messageReceived(QString topic, QString payload)
- passwordChanged(QString password)
- pong()
- portChanged(int port)
- pubacked(quint8 type, quint16 msgid)
- published(QMQTT::Message &message)
- received(const QMQTT::Message &message)
- subacked(quint16 mid, quint8 qos)
- subscribed(const QString &topic)
- unsubacked(quint16 mid)
- unsubscribed(const QString &topic)
- usernameChanged(QString username)

Methods (Q_INVOCABLE)

- bool isConnected()
- quint16 publish(const QString& topic, const QString& payload, quint8 qos = 0)
- quint16 publishMessageObject(QMQTT::Message &message)
- quint16 subscribe(const QString& topic, quint8 qos = 0)
- void connect()
- void disconnect()
- void ping()
- void puback(quint8 type, quint16 msgid)
- void unsubscribe(const QString& topic)

qtmqtt's People

Contributors

tipih 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.