IoT::MQTT

class IMQTTClient

Library: IoT/MQTT
Package: Generated
Header: IoT/MQTT/IMQTTClient.h

Description

The interface for MQTT clients.

Implementations are expected to receive their client ID and server URI via an implementation defined configuration mechanism. Once configured, a MQTTClient always uses the same client ID and connects to the same server. A MQTT client should automatically attempt to reconnect if the connection to the server is lost.

Inheritance

Direct Base Classes: Poco::OSP::Service

All Base Classes: Poco::OSP::Service, Poco::RefCountedObject

Known Derived Classes: MQTTClientRemoteObject

Member Summary

Member Functions: connect, connectAsync, connected, connectionInfo, disconnect, id, isA, publish, publishMessage, remoting__enableEvents, remoting__typeId, serverURI, statistics, subscribe, subscribeMany, subscribedTopics, type, unsubscribe, unsubscribeMany

Inherited Functions: duplicate, isA, referenceCount, release, type

Types

Ptr

typedef Poco::AutoPtr < IMQTTClient > Ptr;

Constructors

IMQTTClient

IMQTTClient();

Creates a IMQTTClient.

Destructor

~IMQTTClient virtual

virtual ~IMQTTClient();

Destroys the IMQTTClient.

Member Functions

connect virtual

virtual IoT::MQTT::ConnectionInfo connect() = 0;

Connects to the server if not already connected.

Normally, the client connects automatically when a message is published or a topic is subscribed to.

Returns a ConnectionInfo object containing information about the connection.

Fires the connected event if successful.

Throws a Poco::IOException if the connection cannot be established.

connectAsync virtual

virtual void connectAsync() = 0;

Connects to the server if not already connected.

Connecting will be done asynchronously in a background thread.

A successful connection will be reported by firing the connected event.

connected virtual

virtual bool connected() const = 0;

Returns true if the client is currently connected to the server.

connectionInfo virtual

virtual IoT::MQTT::ConnectionInfo connectionInfo() const = 0;

Returns a ConnectionInfo structure describing the currently active connection. If not connected, the ConnectionInfo's serverURI will be empty.

disconnect virtual

virtual void disconnect(
    int timeout
) = 0;

Disconnects from the server.

In order to allow the client time to complete handling of messages that are in-flight when this function is called, a timeout period is specified (in milliseconds). When the timeout period has expired, the client disconnects even if there are still outstanding message acknowledgements. The next time the client connects to the same server, any QoS 1 or 2 messages which have not completed will be retried depending on the clean session settings for both the previous and the new connection.

id virtual

virtual const std::string & id() const = 0;

Returns the configured client ID.

isA virtual

bool isA(
    const std::type_info & otherType
) const;

Returns true if the class is a subclass of the class given by otherType.

publish virtual

virtual int publish(
    const std::string & topic,
    const std::string & payload,
    int qos
) = 0;

Publishes the given message on the given topic, using the given QoS.

Returns a delivery token which can be used with the messageDelivered event to verify that the message has been delivered.

Throws a Poco::IOException if the message cannot be published.

publishMessage virtual

virtual int publishMessage(
    const std::string & topic,
    const IoT::MQTT::Message & message
) = 0;

Publishes the given message on the given topic.

Returns a delivery token which can be used with the messageDelivered event to verify that the message has been delivered.

Throws a Poco::IOException if the message cannot be published.

remoting__enableEvents virtual

virtual std::string remoting__enableEvents(
    Poco::RemotingNG::Listener::Ptr pListener,
    bool enable = bool (true)
) = 0;

Enable or disable delivery of remote events.

The given Listener instance must implement the Poco::RemotingNG::EventListener interface, otherwise this method will fail with a RemotingException.

This method is only used with Proxy objects; calling this method on a RemoteObject will do nothing.

remoting__typeId static

static const Poco::RemotingNG::Identifiable::TypeId & remoting__typeId();

Returns the TypeId of the class.

serverURI virtual

virtual const std::string & serverURI() const = 0;

Returns the configured server URI.

statistics virtual

virtual IoT::MQTT::Statistics statistics() const = 0;

Returns statistics about published and received topics and message counts.

subscribe virtual

virtual void subscribe(
    const std::string & topic,
    int qos
) = 0;

This function attempts to subscribe the client to a single topic, which may contain wildcards. This call also specifies the Quality of service requested for the subscription.

Throws a Poco::IOException if there was a problem registering the subscription.

subscribeMany virtual

virtual void subscribeMany(
    const std::vector < IoT::MQTT::TopicQoS > & topicsAndQoS
) = 0;

This function attempts to subscribe the client to a list of topics (with associated QoS levels), which may contain wildcards.

Throws a Poco::IOException if there was a problem registering the subscriptions.

subscribedTopics virtual

virtual std::vector < IoT::MQTT::TopicQoS > subscribedTopics() const = 0;

Returns a vector containing all currently subscribed topics with their QoS level.

type virtual

const std::type_info & type() const;

Returns the type information for the object's class.

unsubscribe virtual

virtual void unsubscribe(
    const std::string & topic
) = 0;

This function attempts to remove an existing subscription made by the client.

Throws a Poco::IOException if there was a problem removing the subscription.

unsubscribeMany virtual

virtual void unsubscribeMany(
    const std::vector < std::string > & topics
) = 0;

This function attempts to remove existing subscriptions to a list of topics made by the specified client.

Throws a Poco::IOException if there was a problem removing the subscriptions.

Variables

connectionClosed

Poco::BasicEvent < void > connectionClosed;

connectionEstablished

Poco::BasicEvent < const ConnectionEstablishedEvent > connectionEstablished;

connectionLost

Poco::BasicEvent < const ConnectionLostEvent > connectionLost;

messageArrived

Poco::BasicEvent < const MessageArrivedEvent > messageArrived;

messageDelivered

Poco::BasicEvent < const MessageDeliveredEvent > messageDelivered;

Securely control IoT edge devices from anywhere   Connect a Device