Serial Studio 1.1.6
A dashboard software for your embedded projects
MQTT::Client Class Reference

The Client class. More...

#include <Client.h>

Inheritance diagram for MQTT::Client:
Inheritance graph
Collaboration diagram for MQTT::Client:
Collaboration graph

Public Slots

void loadCaFile ()
 
void connectToHost ()
 
void toggleConnection ()
 
void disconnectFromHost ()
 
void setQos (const quint8 qos)
 
void lookup (const QString &host)
 
void setPort (const quint16 port)
 
void setHost (const QString &host)
 
void setRetain (const bool retain)
 
void setClientMode (const int mode)
 
void setTopic (const QString &topic)
 
void loadCaFile (const QString &path)
 
void setSslProtocol (const int index)
 
void setSslEnabled (const bool enabled)
 
void setUsername (const QString &username)
 
void setPassword (const QString &password)
 
void setKeepAlive (const quint16 keepAlive)
 
void setMqttVersion (const int versionIndex)
 

Signals

void qosChanged ()
 
void portChanged ()
 
void hostChanged ()
 
void topicChanged ()
 
void retainChanged ()
 
void usernameChanged ()
 
void passwordChanged ()
 
void keepAliveChanged ()
 
void connectedChanged ()
 
void caFilePathChanged ()
 
void clientModeChanged ()
 
void sslEnabledChanged ()
 
void sslProtocolChanged ()
 
void mqttVersionChanged ()
 
void lookupActiveChanged ()
 

Public Member Functions

quint8 qos () const
 
bool retain () const
 
quint16 port () const
 
QString host () const
 
QString topic () const
 
int clientMode () const
 
int sslProtocol () const
 
int mqttVersion () const
 
bool sslEnabled () const
 
QString username () const
 
QString password () const
 
quint16 keepAlive () const
 
bool lookupActive () const
 
bool isSubscribed () const
 
bool isConnectedToHost () const
 
StringList qosLevels () const
 
StringList clientModes () const
 
StringList mqttVersions () const
 
StringList sslProtocols () const
 
QString caFilePath () const
 
quint16 defaultPort () const
 
QString defaultHost () const
 

Static Public Member Functions

static Clientinstance ()
 

Properties

quint16 port
 
quint8 qos
 
QString host
 
bool retain
 
quint16 keepAlive
 
QString topic
 
int mqttVersion
 
int clientMode
 
QString username
 
QString password
 
bool sslEnabled
 
int sslProtocol
 
bool isConnectedToHost
 
bool lookupActive
 
StringList mqttVersions
 
StringList clientModes
 
StringList qosLevels
 
StringList sslProtocols
 
quint16 defaultPort
 
QString defaultHost
 
QString caFilePath
 

Private Slots

void sendData ()
 
void resetStatistics ()
 
void onConnectedChanged ()
 
void lookupFinished (const QHostInfo &info)
 
void onError (const QMQTT::ClientError error)
 
void onFrameReceived (const QByteArray &frame)
 
void onSslErrors (const QList< QSslError > &errors)
 
void onMessageReceived (const QMQTT::Message &message)
 

Private Member Functions

 Client ()
 
 Client (Client &&)=delete
 
 Client (const Client &)=delete
 
Clientoperator= (Client &&)=delete
 
Clientoperator= (const Client &)=delete
 
 ~Client ()
 
void regenerateClient ()
 

Private Attributes

QString m_topic
 
bool m_sslEnabled
 
int m_sslProtocol
 
bool m_lookupActive
 
QString m_caFilePath
 
quint16 m_sentMessages
 
MQTTClientMode m_clientMode
 
QVector< QByteArray > m_frames
 
QPointer< QMQTT::Client > m_client
 
QSslConfiguration m_sslConfiguration
 

Detailed Description

The Client class.

Implements a simple MQTT client, which allows Serial Studio to upload received frames to a MQTT broker so that other devices and/or services can make use of that information. By acting as a MQTT subscriber, Serial Studio can display & process frames from a remote Serial Studio instance that is setup as a MQTT publisher. As you might notice, this has a lot of interesting applications.

For example, you can receive frames from a CanSat mission and display them almost in real-time in another location, such as the "ground control" centre or by the media team which streams the GCS display on the internet as the mission is developing.

Constructor & Destructor Documentation

◆ Client() [1/3]

MQTT::Client::Client ( )
explicitprivate

Constructor function

◆ Client() [2/3]

MQTT::Client::Client ( Client &&  )
privatedelete

◆ Client() [3/3]

MQTT::Client::Client ( const Client )
privatedelete

◆ ~Client()

MQTT::Client::~Client ( )
private

Destructor function

Member Function Documentation

◆ caFilePath()

QString MQTT::Client::caFilePath ( ) const

Returns the path of the currently loaded *.ca file

◆ caFilePathChanged

void MQTT::Client::caFilePathChanged ( )
signal

◆ clientMode()

int MQTT::Client::clientMode ( ) const

Returns the client mode, which can have the following values:

  • Publisher
  • Subscriber

◆ clientModeChanged

void MQTT::Client::clientModeChanged ( )
signal

◆ clientModes()

StringList MQTT::Client::clientModes ( ) const

Returns a list with the available client operation modes.

◆ connectedChanged

void MQTT::Client::connectedChanged ( )
signal

◆ connectToHost

void MQTT::Client::connectToHost ( )
slot

Tries to establish a TCP connection with the MQTT broker/server.

◆ defaultHost()

QString MQTT::Client::defaultHost ( ) const
inline

◆ defaultPort()

quint16 MQTT::Client::defaultPort ( ) const
inline

◆ disconnectFromHost

void MQTT::Client::disconnectFromHost ( )
slot

Disconnects from the MQTT broker/server

◆ host()

QString MQTT::Client::host ( ) const

Returns the IP address of the MQTT broker/server

◆ hostChanged

void MQTT::Client::hostChanged ( )
signal

◆ instance()

MQTT::Client & MQTT::Client::instance ( )
static

Returns a pointer to the only instance of this class

◆ isConnectedToHost()

bool MQTT::Client::isConnectedToHost ( ) const

Returns true if the MQTT module is connected to a MQTT broker/server.

◆ isSubscribed()

bool MQTT::Client::isSubscribed ( ) const

Returns true if the MQTT module is connected to the broker, the topic is not empty and the client is configured to act as an MQTT subscriber.

◆ keepAlive()

quint16 MQTT::Client::keepAlive ( ) const

Returns the keep-alive timeout interval used by the MQTT client.

◆ keepAliveChanged

void MQTT::Client::keepAliveChanged ( )
signal

◆ loadCaFile [1/2]

void MQTT::Client::loadCaFile ( )
slot

Prompts the user to select a *.ca file and loads the certificate into the SSL configuration.

◆ loadCaFile [2/2]

void MQTT::Client::loadCaFile ( const QString &  path)
slot

Reads the CA file in the given path and loads it into the SSL configuration handler for the MQTT connection.

◆ lookup

void MQTT::Client::lookup ( const QString &  host)
slot

Performs a DNS lookup for the given host name

◆ lookupActive()

bool MQTT::Client::lookupActive ( ) const

Returns true if the MQTT module is currently performing a DNS lookup of the MQTT broker/server domain.

◆ lookupActiveChanged

void MQTT::Client::lookupActiveChanged ( )
signal

◆ lookupFinished

void MQTT::Client::lookupFinished ( const QHostInfo &  info)
privateslot

Sets the host IP address when the lookup finishes. If the lookup fails, the error code/string shall be shown to the user in a messagebox.

◆ mqttVersion()

int MQTT::Client::mqttVersion ( ) const

Returns the index of the MQTT version, corresponding to the list returned by the mqttVersions() function.

◆ mqttVersionChanged

void MQTT::Client::mqttVersionChanged ( )
signal

◆ mqttVersions()

StringList MQTT::Client::mqttVersions ( ) const

Returns a list with the supported MQTT versions

◆ onConnectedChanged

void MQTT::Client::onConnectedChanged ( )
privateslot

Subscribe/unsubscripe to the set MQTT topic when the connection state is changed.

◆ onError

void MQTT::Client::onError ( const QMQTT::ClientError  error)
privateslot

Displays any MQTT-related error with a GUI message-box

◆ onFrameReceived

void MQTT::Client::onFrameReceived ( const QByteArray &  frame)
privateslot

Registers the given frame data to the list of frames that shall be published to the MQTT broker/server

◆ onMessageReceived

void MQTT::Client::onMessageReceived ( const QMQTT::Message &  message)
privateslot

Reads the given MQTT message and instructs the IO::Manager module to process received data directly.

◆ onSslErrors

void MQTT::Client::onSslErrors ( const QList< QSslError > &  errors)
privateslot

Displays the SSL errors that occur and allows the user to decide if he/she wants to ignore those errors.

◆ operator=() [1/2]

Client & MQTT::Client::operator= ( Client &&  )
privatedelete

◆ operator=() [2/2]

Client & MQTT::Client::operator= ( const Client )
privatedelete

◆ password()

QString MQTT::Client::password ( ) const

Returns the MQTT password

◆ passwordChanged

void MQTT::Client::passwordChanged ( )
signal

◆ port()

quint16 MQTT::Client::port ( ) const

Returns the TCP port number used for the MQTT connection

◆ portChanged

void MQTT::Client::portChanged ( )
signal

◆ qos()

quint8 MQTT::Client::qos ( ) const

Returns the quality-of-service option, available values:

  • 0: at most once
  • 1: at least once
  • 2: exactly once

◆ qosChanged

void MQTT::Client::qosChanged ( )
signal

◆ qosLevels()

StringList MQTT::Client::qosLevels ( ) const

Returns a list with the available quality-of-service modes.

◆ regenerateClient()

void MQTT::Client::regenerateClient ( )
private

Creates a new MQTT client instance, this approach is required in order to allow the MQTT module to support both non-encrypted and TLS connections.

◆ resetStatistics

void MQTT::Client::resetStatistics ( )
privateslot

Clears the JSON frames & sets the sent messages to 0

◆ retain()

bool MQTT::Client::retain ( ) const

Returns true if the retain flag is enabled

◆ retainChanged

void MQTT::Client::retainChanged ( )
signal

◆ sendData

void MQTT::Client::sendData ( )
privateslot

Publishes all the received data to the MQTT broker

◆ setClientMode

void MQTT::Client::setClientMode ( const int  mode)
slot

Changes the operation mode of the MQTT client. Possible values are:

  • Publisher
  • Subscriber

◆ setHost

void MQTT::Client::setHost ( const QString &  host)
slot

Changes the IP address of the MQTT broker/host

◆ setKeepAlive

void MQTT::Client::setKeepAlive ( const quint16  keepAlive)
slot

Sets the maximum time interval that is permitted to elapse between the point at which the Client finishes transmitting one Control Packet and the point it starts sending the next packet.

◆ setMqttVersion

void MQTT::Client::setMqttVersion ( const int  versionIndex)
slot

Changes the MQTT version used to connect to the MQTT broker/server

◆ setPassword

void MQTT::Client::setPassword ( const QString &  password)
slot

Changes the password used to connect to the MQTT broker/server

◆ setPort

void MQTT::Client::setPort ( const quint16  port)
slot

Changes the TCP port number used for the MQTT communications.

◆ setQos

void MQTT::Client::setQos ( const quint8  qos)
slot

Changes the quality of service level of the MQTT client.

◆ setRetain

void MQTT::Client::setRetain ( const bool  retain)
slot

If set to true, the retain flag shall be appended to the MQTT message so that new clients connecting to the broker will immediately receive the last "good" message.

◆ setSslEnabled

void MQTT::Client::setSslEnabled ( const bool  enabled)
slot

Enables/disables SSL/TLS communications with the MQTT broker

◆ setSslProtocol

void MQTT::Client::setSslProtocol ( const int  index)
slot

Changes the SSL protocol version to use for the MQTT connection.

◆ setTopic

void MQTT::Client::setTopic ( const QString &  topic)
slot

Changes the MQTT topic used by the client.

◆ setUsername

void MQTT::Client::setUsername ( const QString &  username)
slot

Changes the username used to connect to the MQTT broker/server

◆ sslEnabled()

bool MQTT::Client::sslEnabled ( ) const

Returns true if SSL/TLS is enabled

◆ sslEnabledChanged

void MQTT::Client::sslEnabledChanged ( )
signal

◆ sslProtocol()

int MQTT::Client::sslProtocol ( ) const

Returns the selected SSL/TLS protocol index

◆ sslProtocolChanged

void MQTT::Client::sslProtocolChanged ( )
signal

◆ sslProtocols()

StringList MQTT::Client::sslProtocols ( ) const

Returns a list with the supported SSL/TLS protocols

◆ toggleConnection

void MQTT::Client::toggleConnection ( )
slot

Connects/disconnects the application from the current MQTT broker. This function is used as a convenience for the connect/disconnect button.

◆ topic()

QString MQTT::Client::topic ( ) const

Returns the MQTT topic used

◆ topicChanged

void MQTT::Client::topicChanged ( )
signal

◆ username()

QString MQTT::Client::username ( ) const

Returns the MQTT username

◆ usernameChanged

void MQTT::Client::usernameChanged ( )
signal

Member Data Documentation

◆ m_caFilePath

QString MQTT::Client::m_caFilePath
private

◆ m_client

QPointer<QMQTT::Client> MQTT::Client::m_client
private

◆ m_clientMode

MQTTClientMode MQTT::Client::m_clientMode
private

◆ m_frames

QVector<QByteArray> MQTT::Client::m_frames
private

◆ m_lookupActive

bool MQTT::Client::m_lookupActive
private

◆ m_sentMessages

quint16 MQTT::Client::m_sentMessages
private

◆ m_sslConfiguration

QSslConfiguration MQTT::Client::m_sslConfiguration
private

◆ m_sslEnabled

bool MQTT::Client::m_sslEnabled
private

◆ m_sslProtocol

int MQTT::Client::m_sslProtocol
private

◆ m_topic

QString MQTT::Client::m_topic
private

Property Documentation

◆ caFilePath

QString MQTT::Client::caFilePath
read

◆ clientMode

int MQTT::Client::clientMode
readwrite

◆ clientModes

StringList MQTT::Client::clientModes
read

◆ defaultHost

QString MQTT::Client::defaultHost
read

◆ defaultPort

quint16 MQTT::Client::defaultPort
read

◆ host

QString MQTT::Client::host
readwrite

◆ isConnectedToHost

bool MQTT::Client::isConnectedToHost
read

◆ keepAlive

quint16 MQTT::Client::keepAlive
readwrite

◆ lookupActive

bool MQTT::Client::lookupActive
read

◆ mqttVersion

int MQTT::Client::mqttVersion
readwrite

◆ mqttVersions

StringList MQTT::Client::mqttVersions
read

◆ password

QString MQTT::Client::password
readwrite

◆ port

quint16 MQTT::Client::port
readwrite

◆ qos

quint8 MQTT::Client::qos
readwrite

◆ qosLevels

StringList MQTT::Client::qosLevels
read

◆ retain

bool MQTT::Client::retain
readwrite

◆ sslEnabled

bool MQTT::Client::sslEnabled
readwrite

◆ sslProtocol

int MQTT::Client::sslProtocol
readwrite

◆ sslProtocols

StringList MQTT::Client::sslProtocols
read

◆ topic

QString MQTT::Client::topic
readwrite

◆ username

QString MQTT::Client::username
readwrite

The documentation for this class was generated from the following files: