Rover API Documentation
rover::RoverPahoMQTT Class Reference

RoverPahoMQTT contains member functions to use rover as a client and to publish / subscribe to Eclipse Paho MQTT server topics. More...

#include <rover_pahomqtt.hpp>

Inheritance diagram for rover::RoverPahoMQTT:
rover::RoverCloud rover::RoverMQTTCommand

Public Member Functions

 ~RoverPahoMQTT ()
 Destructor for RoverPahoMQTT class. More...
 
 RoverPahoMQTT ()
 Default constructor for RoverPahoMQTT class. More...
 
 RoverPahoMQTT (char *host_name, int port, RoverMQTT_Configure_t MQTT_Configure)
 Copy constructor for RoverPahoMQTT. More...
 
void setHostName (char *host_name)
 Sets private attribute HOST_NAME. More...
 
void setPort (const int port)
 Sets private attribute PORT. More...
 
void setPayload (const char *payload, int payloadLen)
 Sets payload. More...
 
void setTopic (char *topic)
 Sets topic name. More...
 
int read (char *data)
 Public member function for reading subscribed data. This function requires the RoverPahoMQTT to be subscribed first. More...
 
int isDataReady (void)
 Public member function checking if the subscribed data is ready. 0-> data ready -1-> data not ready. More...
 
int publish (void)
 Used for publishing to a topic in an MQTT-broker using asynchronous method. More...
 
int connect (void)
 Used for connecting to MQTT broker asynchronously. More...
 
int subscribe (void)
 Used for subscribing to a topic in an MQTT-broker. To unsubscribe use: RoverPahoMQTT::unsubscribe() More...
 
int unsubscribe (void)
 Used for unsubscribing and disconnecting from a subscription to a topic in an MQTT-broker. More...
 
int getConnected (void)
 Returns connected flag. More...
 
- Public Member Functions inherited from rover::RoverCloud
virtual ~RoverCloud ()
 Virtual destructor. More...
 

Protected Member Functions

void createClient (void)
 Create the MQTT client object. More...
 
void destroyClient (void)
 Destroy the MQTT client object. More...
 
void flushFlags (void)
 Private member function to flush the connection flags for new operation. More...
 
void constructAddress (void)
 Used for constructing the connection address by writing to private attribute my_address. More...
 
void onConnect (MQTTAsync_successData *response)
 Member callback function for onPublisherConnect actions. More...
 
void onPublisherSend (MQTTAsync_successData *response)
 Member callback function for onPublisherSend actions. More...
 
int onSubscriberMessageArrived (char *topicName, int topicLen, MQTTAsync_message *message)
 Member callback function for onSubscriberMessageArrived actions. More...
 
void onSubscribe (MQTTAsync_successData *response)
 Member callback function for onSubscribe actions. More...
 
void onSubscribeFailure (MQTTAsync_failureData *response)
 Member callback function for onSubscribeFailure actions. More...
 
void onConnectFailure (MQTTAsync_failureData *response)
 Member callback function for onConnectFailure actions. More...
 
void onConnectionLost (char *cause)
 Member callback function for onConnectionLost actions. More...
 
void onDisconnect (MQTTAsync_successData *response)
 Member callback function for onDisconnect actions. More...
 

Static Protected Member Functions

static void onConnect_Redirect (void *context, MQTTAsync_successData *response)
 Static function responsible for calling RoverPahoMQTT::onPublisherConnect in a given RoverPahoMQTT context. More...
 
static void onPublisherSend_Redirect (void *context, MQTTAsync_successData *response)
 Static function responsible for calling RoverPahoMQTT::onPublisherSend in a given RoverPahoMQTT context. More...
 
static int onSubscriberMessageArrived_Redirect (void *context, char *topicName, int topicLen, MQTTAsync_message *message)
 Static function responsible for calling RoverPahoMQTT::onSubscriberMessageArrived in a given RoverPahoMQTT context. More...
 
static void onSubscribe_Redirect (void *context, MQTTAsync_successData *response)
 Static function responsible for calling RoverPahoMQTT::onSubscribe in a given RoverPahoMQTT context. More...
 
static void onSubscribeFailure_Redirect (void *context, MQTTAsync_failureData *response)
 Static function responsible for calling RoverPahoMQTT::onSubscribeFailure in a given RoverPahoMQTT context. More...
 
static void onConnectFailure_Redirect (void *context, MQTTAsync_failureData *response)
 Static function responsible for calling RoverPahoMQTT::onConnectFailure in a given RoverPahoMQTT context. More...
 
static void onConnectionLost_Redirect (void *context, char *cause)
 Static function responsible for calling RoverPahoMQTT::onConnectionLost in a given RoverPahoMQTT context. More...
 
static void onDisconnect_Redirect (void *context, MQTTAsync_successData *response)
 Static function responsible for calling RoverPahoMQTT::onDisconnect in a given RoverPahoMQTT context. More...
 

Protected Attributes

char * HOST_NAME
 Host name used for connecting to the Eclipse Paho MQTT server. More...
 
int PORT
 Port used for connecting to the Eclipse Paho MQTT server. More...
 
RoverMQTT_SubscribeData_t defaultRoverSubscribeData
 Member attribute for subscribed data. More...
 
RoverMQTT_Configure_t defaultRoverMQTTConfigure
 Member attribute for configuration data. More...
 
RoverMQTT_StatusFlags_t defaultRoverMQTTFlags
 Member attribute for flags. More...
 
RoverMQTT_ReturnCodes_t defaultReturnCodes
 Member attribute for return codes. More...
 
MQTTAsync client = NULL
 Client object from MQTTAsync. More...
 
MQTTClient client2
 Client object from MQTTClient. More...
 
MQTTAsync_connectOptions conn_opts
 Connect options. More...
 
MQTTAsync_disconnectOptions disc_opts
 Disconnect options. More...
 
volatile MQTTAsync_token deliveredtoken
 Delivered token. More...
 

Private Attributes

char * payload = {}
 Payload pointer to manage memory. More...
 
char my_address [100] = {}
 MQTT address. More...
 
int connected = 0
 

Detailed Description

RoverPahoMQTT contains member functions to use rover as a client and to publish / subscribe to Eclipse Paho MQTT server topics.

Warning
For oncreate examples please go to: https://github.com/app4mc-rover/rover-app/tree/master/src/examples

Constructor & Destructor Documentation

rover::RoverPahoMQTT::~RoverPahoMQTT ( )

Destructor for RoverPahoMQTT class.

rover::RoverPahoMQTT::RoverPahoMQTT ( )

Default constructor for RoverPahoMQTT class.

rover::RoverPahoMQTT::RoverPahoMQTT ( char *  host_name,
int  port,
RoverMQTT_Configure_t  MQTT_Configure 
)

Copy constructor for RoverPahoMQTT.

Member Function Documentation

int rover::RoverPahoMQTT::connect ( void  )

Used for connecting to MQTT broker asynchronously.

Returns
Return code 0-> success; others-> fail return codes
1: Connection refused: Unacceptable protocol version
2: Connection refused: Identifier rejected
3: Connection refused: Server unavailable
4: Connection refused: Bad user name or password
5: Connection refused: Not authorized
6-255: Reserved for future use
Reference: [paho.mqtt.c] Asynchronous MQTT Client Documentation
void rover::RoverPahoMQTT::constructAddress ( void  )
protected

Used for constructing the connection address by writing to private attribute my_address.

Returns
void
void rover::RoverPahoMQTT::createClient ( void  )
protected

Create the MQTT client object.

void rover::RoverPahoMQTT::destroyClient ( void  )
protected

Destroy the MQTT client object.

void rover::RoverPahoMQTT::flushFlags ( void  )
protected

Private member function to flush the connection flags for new operation.

Returns
void
int rover::RoverPahoMQTT::getConnected ( void  )

Returns connected flag.

Returns
connected flag 1:connected 0: not connected
int rover::RoverPahoMQTT::isDataReady ( void  )

Public member function checking if the subscribed data is ready. 0-> data ready -1-> data not ready.

void rover::RoverPahoMQTT::onConnect ( MQTTAsync_successData *  response)
protected

Member callback function for onPublisherConnect actions.

Parameters
responseResponse data from MQTTAsync instance
Returns
void
void rover::RoverPahoMQTT::onConnect_Redirect ( void *  context,
MQTTAsync_successData *  response 
)
staticprotected

Static function responsible for calling RoverPahoMQTT::onPublisherConnect in a given RoverPahoMQTT context.

Parameters
contextGiven context for RoverPahoMQTT. Internal use: this
responseResponse data from MQTTAsync instance
Returns
void
void rover::RoverPahoMQTT::onConnectFailure ( MQTTAsync_failureData *  response)
protected

Member callback function for onConnectFailure actions.

Parameters
responseResponse data from MQTTAsync instance
Returns
void
void rover::RoverPahoMQTT::onConnectFailure_Redirect ( void *  context,
MQTTAsync_failureData *  response 
)
staticprotected

Static function responsible for calling RoverPahoMQTT::onConnectFailure in a given RoverPahoMQTT context.

Parameters
contextGiven context for RoverPahoMQTT. Internal use: this
responseResponse data from MQTTAsync instance
Returns
void
void rover::RoverPahoMQTT::onConnectionLost ( char *  cause)
protected

Member callback function for onConnectionLost actions.

Parameters
responseResponse data from MQTTAsync instance
Returns
void
void rover::RoverPahoMQTT::onConnectionLost_Redirect ( void *  context,
char *  cause 
)
staticprotected

Static function responsible for calling RoverPahoMQTT::onConnectionLost in a given RoverPahoMQTT context.

Parameters
contextGiven context for RoverPahoMQTT. Internal use: this
causeCause of connection loss
Returns
void
void rover::RoverPahoMQTT::onDisconnect ( MQTTAsync_successData *  response)
protected

Member callback function for onDisconnect actions.

Parameters
responseResponse data from MQTTAsync instance
Returns
void
void rover::RoverPahoMQTT::onDisconnect_Redirect ( void *  context,
MQTTAsync_successData *  response 
)
staticprotected

Static function responsible for calling RoverPahoMQTT::onDisconnect in a given RoverPahoMQTT context.

Parameters
contextGiven context for RoverPahoMQTT. Internal use: this
responseResponse data from MQTTAsync instance
Returns
void
void rover::RoverPahoMQTT::onPublisherSend ( MQTTAsync_successData *  response)
protected

Member callback function for onPublisherSend actions.

Parameters
responseResponse data from MQTTAsync instance
Returns
void
void rover::RoverPahoMQTT::onPublisherSend_Redirect ( void *  context,
MQTTAsync_successData *  response 
)
staticprotected

Static function responsible for calling RoverPahoMQTT::onPublisherSend in a given RoverPahoMQTT context.

Parameters
contextGiven context for RoverPahoMQTT. Internal use: this
responseResponse data from MQTTAsync instance
Returns
void
void rover::RoverPahoMQTT::onSubscribe ( MQTTAsync_successData *  response)
protected

Member callback function for onSubscribe actions.

Parameters
responseResponse data from MQTTAsync instance
Returns
void
void rover::RoverPahoMQTT::onSubscribe_Redirect ( void *  context,
MQTTAsync_successData *  response 
)
staticprotected

Static function responsible for calling RoverPahoMQTT::onSubscribe in a given RoverPahoMQTT context.

Parameters
contextGiven context for RoverPahoMQTT. Internal use: this
responseResponse data from MQTTAsync instance
Returns
void
void rover::RoverPahoMQTT::onSubscribeFailure ( MQTTAsync_failureData *  response)
protected

Member callback function for onSubscribeFailure actions.

Parameters
responseResponse data from MQTTAsync instance
Returns
void
void rover::RoverPahoMQTT::onSubscribeFailure_Redirect ( void *  context,
MQTTAsync_failureData *  response 
)
staticprotected

Static function responsible for calling RoverPahoMQTT::onSubscribeFailure in a given RoverPahoMQTT context.

Parameters
contextGiven context for RoverPahoMQTT. Internal use: this
responseResponse data from MQTTAsync instance
Returns
void
int rover::RoverPahoMQTT::onSubscriberMessageArrived ( char *  topicName,
int  topicLen,
MQTTAsync_message *  message 
)
protected

Member callback function for onSubscriberMessageArrived actions.

Parameters
topicNamereceived topic name
topicLenreceived topic name length
messagereceived message
Returns
int
int rover::RoverPahoMQTT::onSubscriberMessageArrived_Redirect ( void *  context,
char *  topicName,
int  topicLen,
MQTTAsync_message *  message 
)
staticprotected

Static function responsible for calling RoverPahoMQTT::onSubscriberMessageArrived in a given RoverPahoMQTT context.

Parameters
contextGiven context for RoverPahoMQTT. Internal use: this
topicNamereceived topic name
topicLenreceived topic name length
messagereceived message
Returns
int
int rover::RoverPahoMQTT::publish ( void  )

Used for publishing to a topic in an MQTT-broker using asynchronous method.

Returns
Return code 0-> success; others-> fail return codes
1: Connection refused: Unacceptable protocol version
2: Connection refused: Identifier rejected
3: Connection refused: Server unavailable
4: Connection refused: Bad user name or password
5: Connection refused: Not authorized
6-255: Reserved for future use
Reference: [paho.mqtt.c] Asynchronous MQTT Client Documentation
int rover::RoverPahoMQTT::read ( char *  data)

Public member function for reading subscribed data. This function requires the RoverPahoMQTT to be subscribed first.

Parameters
datachar* Data pointer that will be modified.
Returns
status: 0-> Successful read, 1-> No data available
void rover::RoverPahoMQTT::setHostName ( char *  host_name)
virtual

Sets private attribute HOST_NAME.

Parameters
host_name

Implements rover::RoverCloud.

void rover::RoverPahoMQTT::setPayload ( const char *  payload,
int  payloadLen 
)

Sets payload.

Parameters
payloadPayload
payloadLenPayload length
void rover::RoverPahoMQTT::setPort ( const int  port)
virtual

Sets private attribute PORT.

Parameters
portPort

Implements rover::RoverCloud.

void rover::RoverPahoMQTT::setTopic ( char *  topic)

Sets topic name.

Parameters
topicTopic name
int rover::RoverPahoMQTT::subscribe ( void  )

Used for subscribing to a topic in an MQTT-broker. To unsubscribe use: RoverPahoMQTT::unsubscribe()

Returns
Return code 0-> success; others-> fail return codes 1: Connection refused: Unacceptable protocol version
2: Connection refused: Identifier rejected
3: Connection refused: Server unavailable
4: Connection refused: Bad user name or password
5: Connection refused: Not authorized
6-255: Reserved for future use
Reference: [paho.mqtt.c] Asynchronous MQTT Client Documentation
int rover::RoverPahoMQTT::unsubscribe ( void  )

Used for unsubscribing and disconnecting from a subscription to a topic in an MQTT-broker.

Returns
Return code 0-> success; others-> fail sreturn codes 1: Connection refused: Unacceptable protocol version
2: Connection refused: Identifier rejected
3: Connection refused: Server unavailable
4: Connection refused: Bad user name or password
5: Connection refused: Not authorized
6-255: Reserved for future use
Reference: [paho.mqtt.c] Asynchronous MQTT Client Documentation

Member Data Documentation

MQTTAsync rover::RoverPahoMQTT::client = NULL
protected

Client object from MQTTAsync.

MQTTClient rover::RoverPahoMQTT::client2
protected

Client object from MQTTClient.

MQTTAsync_connectOptions rover::RoverPahoMQTT::conn_opts
protected

Connect options.

int rover::RoverPahoMQTT::connected = 0
private
RoverMQTT_ReturnCodes_t rover::RoverPahoMQTT::defaultReturnCodes
protected

Member attribute for return codes.

RoverMQTT_Configure_t rover::RoverPahoMQTT::defaultRoverMQTTConfigure
protected

Member attribute for configuration data.

RoverMQTT_StatusFlags_t rover::RoverPahoMQTT::defaultRoverMQTTFlags
protected

Member attribute for flags.

RoverMQTT_SubscribeData_t rover::RoverPahoMQTT::defaultRoverSubscribeData
protected

Member attribute for subscribed data.

volatile MQTTAsync_token rover::RoverPahoMQTT::deliveredtoken
protected

Delivered token.

MQTTAsync_disconnectOptions rover::RoverPahoMQTT::disc_opts
protected

Disconnect options.

char* rover::RoverPahoMQTT::HOST_NAME
protected

Host name used for connecting to the Eclipse Paho MQTT server.

char rover::RoverPahoMQTT::my_address[100] = {}
private

MQTT address.

char* rover::RoverPahoMQTT::payload = {}
private

Payload pointer to manage memory.

int rover::RoverPahoMQTT::PORT
protected

Port used for connecting to the Eclipse Paho MQTT server.


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