My Project
 All Classes Functions Variables Pages
Public Member Functions | Friends | List of all members
PubSubClient Class Reference

Public Member Functions

 PubSubClient (Socket &client)
 
 PubSubClient (std::string ip, uint16_t port)
 
 PubSubClient (std::string ip, uint16_t port, Socket &client)
 
 PubSubClient (std::string ip, uint16_t port, MQTT_CALLBACK_SIGNATURE, Socket &client)
 
PubSubClientsetServer (std::string ip, uint16_t port)
 Set server ip and Port of my MQTT server. More...
 
PubSubClientsetCallback (MQTT_CALLBACK_SIGNATURE)
 Set the callback function for incoming data. More...
 
PubSubClientsetClient (Socket &client)
 Set the socket, which we want to use for our MQTT communication. More...
 
bool connect (const char *id)
 Connect to a MQTT server. More...
 
bool connect (const char *id, const char *user, const char *pass)
 Connect to a MQTT server. More...
 
bool connect (const char *id, const char *willTopic, uint8_t willQos, bool willRetain, const char *willMessage)
 Connect to a MQTT server. More...
 
bool connect (const char *id, const char *user, const char *pass, const char *willTopic, uint8_t willQos, bool willRetain, const char *willMessage)
 Connect to a MQTT server. More...
 
bool connect ()
 Connect to a MQTT server with the with the previous settings. Note: do not call this function without settings, this will not work! For the very first connect process, use the connect function with parameters. More...
 
void disconnect ()
 Disconnect form MQTT server and close the socket. More...
 
bool publish (const char *topic, const char *payload)
 Publish a MQTT message. More...
 
bool publish (const char *topic, const char *payload, bool retained)
 Publish a MQTT message. More...
 
bool publish (const char *topic, const uint8_t *payload, unsigned int plength)
 Publish a MQTT message. More...
 
bool publish (const char *topic, const uint8_t *payload, unsigned int plength, bool retained)
 Publish a MQTT message. More...
 
bool subscribe (const char *topic, bool ack=false)
 Subscribe a MQTT topic. More...
 
bool unsubscribe (const char *topic, bool ack=false)
 Unsubscribe a MQTT topic. More...
 
bool isSubscribeDone ()
 Check the state of subscription. If there was received a subscription ACK, we return a true here. More...
 
bool isUnsubscribeDone ()
 Check the state of unsubscription. If there was received a unsubscription ACK, we return a true here. More...
 
bool connected ()
 Check the connection to the MQTT server. More...
 
int state ()
 Get the current MYTT state form the instance. More...
 
void keepAliveChecker ()
 This is a Timer called routine, which checks the PING_outstanding flag. This flag is set in this function. We send a Keep alive message to the server here. If there is a data in, or output, or we receive the MQTT ping request, the flag will be set to false by other functions. This function is called every MQTT_KEEPALIVE interval. If the flag is still true, we have a error with the connection. More...
 
void timeoutChecker ()
 This is a Timer called routine, which is called, when we reach the timeout. Used is this function for all ACK commands, which comes over MQTT. Notice, that the KeepAlivePing has his own Timer, to prevent conflicts. Basically, if this function is called, we have detected a MQTT timeout! More...
 

Friends

class PubSubClientTask
 

Member Function Documentation

bool PubSubClient::connect ( const char *  id)

Connect to a MQTT server.

Parameters
[in]Deviceid to identify this device.
Returns
success (true), or no success (false).
bool PubSubClient::connect ( const char *  id,
const char *  user,
const char *  pass 
)

Connect to a MQTT server.

Parameters
[in]Deviceid to identify this device. [in] my user name. [in] my password.
Returns
success (true), or no success (false).
bool PubSubClient::connect ( const char *  id,
const char *  willTopic,
uint8_t  willQos,
bool  willRetain,
const char *  willMessage 
)

Connect to a MQTT server.

Parameters
[in]Deviceid to identify this device. [in] last will: topic name. [in] last will: qos-level. [in] last will: as retained message. [in] last will: payload.
Returns
success (true), or no success (false).
bool PubSubClient::connect ( const char *  id,
const char *  user,
const char *  pass,
const char *  willTopic,
uint8_t  willQos,
bool  willRetain,
const char *  willMessage 
)

Connect to a MQTT server.

Parameters
[in]Deviceid to identify this device. [in] my user name. [in] my password. [in] last will: topic name. [in] last will: qos-level. [in] last will: as retained message. [in] last will: payload.
Returns
success (true), or no success (false).
bool PubSubClient::connect ( )

Connect to a MQTT server with the with the previous settings. Note: do not call this function without settings, this will not work! For the very first connect process, use the connect function with parameters.

Parameters
N/A
Returns
success (true), or no success (false).
bool PubSubClient::connected ( )

Check the connection to the MQTT server.

Returns
connected (true/false)
void PubSubClient::disconnect ( )

Disconnect form MQTT server and close the socket.

Returns
N/A.
bool PubSubClient::isSubscribeDone ( )

Check the state of subscription. If there was received a subscription ACK, we return a true here.

Returns
Is subscription validated with ACK (true/false)
bool PubSubClient::isUnsubscribeDone ( )

Check the state of unsubscription. If there was received a unsubscription ACK, we return a true here.

Returns
Is unsubscription validated with ACK (true/false)
void PubSubClient::keepAliveChecker ( )

This is a Timer called routine, which checks the PING_outstanding flag. This flag is set in this function. We send a Keep alive message to the server here. If there is a data in, or output, or we receive the MQTT ping request, the flag will be set to false by other functions. This function is called every MQTT_KEEPALIVE interval. If the flag is still true, we have a error with the connection.

Parameters
N/A.
Returns
N/A.
bool PubSubClient::publish ( const char *  topic,
const char *  payload 
)

Publish a MQTT message.

Parameters
[in]mytopic. [in] my payload.
Returns
success (true), or no success (false).
bool PubSubClient::publish ( const char *  topic,
const char *  payload,
bool  retained 
)

Publish a MQTT message.

Parameters
[in]mytopic. [in] my payload. [in] is this a retained message (true/false)
Returns
success (true), or no success (false).
bool PubSubClient::publish ( const char *  topic,
const uint8_t *  payload,
unsigned int  plength 
)

Publish a MQTT message.

Parameters
[in]mytopic. [in] my payload. [in] length of the message
Returns
success (true), or no success (false).
bool PubSubClient::publish ( const char *  topic,
const uint8_t *  payload,
unsigned int  plength,
bool  retained 
)

Publish a MQTT message.

Parameters
[in]mytopic. [in] my payload. [in] length of the message [in] is this a retained message (true/false)
Returns
success (true), or no success (false).
PubSubClient & PubSubClient::setCallback ( MQTT_CALLBACK_SIGNATURE  )

Set the callback function for incoming data.

Parameters
[in]callbackfunction
Returns
My instance.
PubSubClient & PubSubClient::setClient ( Socket client)

Set the socket, which we want to use for our MQTT communication.

Parameters
[in]thenew socket instance
Returns
My instance.
PubSubClient & PubSubClient::setServer ( std::string  ip,
uint16_t  port 
)

Set server ip and Port of my MQTT server.

Parameters
[in]ipof the distant MQTT server. [in] the port of the distant MQTT port.
Returns
My instance.
int PubSubClient::state ( )

Get the current MYTT state form the instance.

Parameters
N/A.
Returns
current MQTT state.
bool PubSubClient::subscribe ( const char *  topic,
bool  ack = false 
)

Subscribe a MQTT topic.

Parameters
[in]mytopic [in] qos of subscription
Returns
request transmitted with success (true), or no success (false).
void PubSubClient::timeoutChecker ( )

This is a Timer called routine, which is called, when we reach the timeout. Used is this function for all ACK commands, which comes over MQTT. Notice, that the KeepAlivePing has his own Timer, to prevent conflicts. Basically, if this function is called, we have detected a MQTT timeout!

Parameters
N/A.
Returns
N/A.
bool PubSubClient::unsubscribe ( const char *  topic,
bool  ack = false 
)

Unsubscribe a MQTT topic.

Parameters
[in]mytopic [in] qos of unsubscription
Returns
request transmitted with success (true), or no success (false).

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