AWS IoT for ESP32 v1.0.0
An ESP-IDF based solution
lib_mqtt.h File Reference

MQTT library header file. More...

Go to the source code of this file.

Data Structures

struct  mqttConfig_st
 MQTT configuration structure. More...
 

Enumerations

enum  mqttStates_et {
  STATE_MQTT_IDLE , STATE_MQTT_START , STATE_MQTT_DISCONNECTED , STATE_MQTT_CONNECTED ,
  STATE_MQTT_ABORT , STATE_MQTT_MAX
}
 
enum  mqttWrtStatus_et
 

Functions

bool MQTT_init (mqttConfig_st *ps_config)
 Initialize MQTT library with given MQTT configuration. More...
 
void MQTT_sync ()
 Run MQTT library, this function should be called periodically by the application. More...
 
bool MQTT_isConnected ()
 Check if MQTT is connected to broker. More...
 
bool MQTT_isStarted ()
 Check if MQTT is initialized and has started. More...
 
bool MQTT_close ()
 Close and terminate MQTT connection. More...
 
bool MQTT_subscribe (char *pTopicStr, uint8_t qos_e)
 Subscribe to a give topic. More...
 
bool MQTT_publish (mqttMsg_st *ps_msg)
 Publish a given message. More...
 
uint8_t MQTT_availableToRead ()
 Check is messages are available on subsribed topics. The library maintains a buffer to store received messages. More...
 
bool MQTT_read (mqttMsg_st *ps_msg)
 Read the received message received. More...
 
void MQTT_printStatus ()
 Print the status of MQTT library. More...
 

Detailed Description

MQTT library header file.

Enumeration Type Documentation

◆ mqttStates_et

An enum to represent states of MQTT library.

Enumerator
STATE_MQTT_IDLE 

Idle state

STATE_MQTT_START 

Initialize and Start MQTT

STATE_MQTT_DISCONNECTED 

MQTT is in Disconnected state

STATE_MQTT_CONNECTED 

MQTT is Connected state

STATE_MQTT_ABORT 

Abort and close MQTT connection

◆ mqttWrtStatus_et

An enum to represent MQTT status.

Function Documentation

◆ MQTT_availableToRead()

uint8_t MQTT_availableToRead ( )

Check is messages are available on subsribed topics. The library maintains a buffer to store received messages.

Parameters
none
Returns
Number of bytes available

◆ MQTT_close()

bool MQTT_close ( )

Close and terminate MQTT connection.

Parameters
none
Returns
Status of close request
Return values
trueif closed successfully
falseif failed to close

◆ MQTT_init()

bool MQTT_init ( mqttConfig_st ps_config)

Initialize MQTT library with given MQTT configuration.

Parameters
[in]ps_configMQTT configuration
Returns
Status of initialization
Return values
trueon success
falseon failure

◆ MQTT_isConnected()

bool MQTT_isConnected ( )

Check if MQTT is connected to broker.

Parameters
none
Returns
Status of connection
Return values
trueif connected
falseif disconnected

◆ MQTT_isStarted()

bool MQTT_isStarted ( )

Check if MQTT is initialized and has started.

Parameters
none
Returns
status of MQTT has started or not
Return values
trueif MQTT has started
falseif MQTT has not started

◆ MQTT_printStatus()

void MQTT_printStatus ( )

Print the status of MQTT library.

Parameters
none
Returns
none

◆ MQTT_publish()

bool MQTT_publish ( mqttMsg_st ps_msg)

Publish a given message.

Parameters
[in]ps_msgMessage to be published
Returns
Status of publish request
Return values
trueif published
falseon error

◆ MQTT_read()

bool MQTT_read ( mqttMsg_st ps_msg)

Read the received message received.

Parameters
[out]ps_msg
Returns
Status of read message
Return values
trueon success
falseon failure

◆ MQTT_subscribe()

bool MQTT_subscribe ( char *  pTopicStr,
uint8_t  qos_e 
)

Subscribe to a give topic.

Parameters
[in]pTopicStrTopic to subscribe
[in]qos_eQOS Level
Returns
Status to indicate if subscrption was successful or not
Return values
truesubscribed successfully
falsefailed to subscribe

◆ MQTT_sync()

void MQTT_sync ( )

Run MQTT library, this function should be called periodically by the application.

Parameters
none
Returns
none