Microchip® Advanced Software Framework

aws_iot_mqtt_embedded_client_wrapper.c File Reference

Macros

#define GETLOWER4BYTES   0x0FFFFFFFF
 

Functions

bool aws_iot_is_autoreconnect_enabled (void)
 Is the MQTT client set to reconnect automatically? More...
 
bool aws_iot_is_mqtt_connected (void)
 Is the MQTT client currently connected? More...
 
IoT_Error_t aws_iot_mqtt_attempt_reconnect ()
 MQTT Manual Re-Connection Function. More...
 
IoT_Error_t aws_iot_mqtt_autoreconnect_set_status (bool value)
 Enable or Disable AutoReconnect on Network Disconnect. More...
 
IoT_Error_t aws_iot_mqtt_connect (MQTTConnectParams *pParams)
 MQTT Connection Function. More...
 
IoT_Error_t aws_iot_mqtt_disconnect ()
 Disconnect an MQTT Connection. More...
 
void aws_iot_mqtt_init (MQTTClient_t *pClient)
 Set the MQTT client. More...
 
IoT_Error_t aws_iot_mqtt_publish (MQTTPublishParams *pParams)
 Publish an MQTT message on a topic. More...
 
IoT_Error_t aws_iot_mqtt_subscribe (MQTTSubscribeParams *pParams)
 Subscribe to an MQTT topic. More...
 
IoT_Error_t aws_iot_mqtt_unsubscribe (char *pTopic)
 Unsubscribe to an MQTT topic. More...
 
IoT_Error_t aws_iot_mqtt_yield (int timeout)
 Yield to the MQTT client. More...
 
void pahoDisconnectHandler (void)
 
void pahoMessageCallback (MessageData *md)
 

Variables

static Client c
 
static iot_disconnect_handler clientDisconnectHandler
 
static bool isPowerCycle = true
 
const MQTTCallbackParams MQTTCallbackParamsDefault
 
const MQTTConnectParams MQTTConnectParamsDefault
 
const MQTTMessageParams MQTTMessageParamsDefault
 
const MQTTPublishParams MQTTPublishParamsDefault
 
const MQTTSubscribeParams MQTTSubscribeParamsDefault
 
const MQTTwillOptions MQTTwillOptionsDefault
 
static unsigned char readbuf [AWS_IOT_MQTT_RX_BUF_LEN]
 
static unsigned char writebuf [AWS_IOT_MQTT_TX_BUF_LEN]
 

#define GETLOWER4BYTES   0x0FFFFFFFF

Referenced by pahoMessageCallback().

bool aws_iot_is_autoreconnect_enabled ( void  )

Is the MQTT client set to reconnect automatically?

Called to determine if the MQTT client is set to reconnect automatically. Used to support logic in the device application around reconnecting

Returns
true = enabled, false = disabled

References MQTTIsAutoReconnectEnabled().

Referenced by aws_iot_mqtt_init(), and disconnectCallbackHandler().

bool aws_iot_is_mqtt_connected ( void  )

Is the MQTT client currently connected?

Called to determine if the MQTT client is currently connected. Used to support logic in the device application around reconnecting and managing offline state.

Returns
true = connected, false = not currently connected

References MQTTIsConnected().

Referenced by aws_iot_mqtt_init().

IoT_Error_t aws_iot_mqtt_attempt_reconnect ( void  )

MQTT Manual Re-Connection Function.

Called to establish an MQTT connection with the AWS IoT Service using parameters from the last time a connection was attempted Use after disconnect to start the reconnect process manually Makes only one reconnect attempt

Returns
An IoT Error Type defining successful/failed connection

References GENERIC_ERROR, MQTT_NETWORK_ALREADY_CONNECTED_ERROR, MQTT_NETWORK_DISCONNECTED_ERROR, MQTT_NETWORK_RECONNECTED, MQTT_NULL_VALUE_ERROR, MQTT_RECONNECT_TIMED_OUT, MQTTAttemptReconnect(), NETWORK_ALREADY_CONNECTED, NETWORK_DISCONNECTED, NETWORK_RECONNECT_TIMED_OUT, NULL_VALUE_ERROR, and RECONNECT_SUCCESSFUL.

Referenced by aws_iot_mqtt_init(), and disconnectCallbackHandler().

IoT_Error_t aws_iot_mqtt_autoreconnect_set_status ( bool  value)

Enable or Disable AutoReconnect on Network Disconnect.

Called to enable or disabled the auto reconnect features provided with the SDK

Parameters
valueset to true for enabling and false for disabling
Returns
IoT_Error_t Type defining successful/failed API call

References MQTT_NULL_VALUE_ERROR, NONE_ERROR, NULL_VALUE_ERROR, and setAutoReconnectEnabled().

Referenced by aws_iot_mqtt_init(), and main().

IoT_Error_t aws_iot_mqtt_connect ( MQTTConnectParams pParams)

MQTT Connection Function.

Called to establish an MQTT connection with the AWS IoT Service

Parameters
pParamsPointer to MQTT connection parameters
Returns
An IoT Error Type defining successful/failed connection

References MQTTPacket_connectData::cleansession, clientDisconnectHandler, MQTTPacket_connectData::clientID, CONNECTION_ERROR, MQTTString::cstring, data, TLSConnectParams::DestinationPort, MQTTConnectParams::disconnectHandler, MQTTConnectParams::enableAutoReconnect, iot_tls_init(), MQTTConnectParams::isCleansession, isPowerCycle, MQTTwillOptions::isRetained, MQTTConnectParams::isSSLHostnameVerify, MQTTConnectParams::isWillMsgPresent, MQTTPacket_connectData::keepAliveInterval, MQTTConnectParams::KeepAliveInterval_sec, MQTTPacket_willOptions::message, MQTT_3_1, MQTT_3_1_1, MQTT_NETWORK_ALREADY_CONNECTED_ERROR, MQTTConnectParams::mqttCommandTimeout_ms, MQTTConnect(), MQTTPacket_connectData_initializer, MQTTConnectParams::MQTTVersion, MQTTPacket_connectData::MQTTVersion, NETWORK_ALREADY_CONNECTED, NONE_ERROR, NULL, NULL_VALUE_ERROR, pahoDisconnectHandler(), MQTTPacket_connectData::password, MQTTConnectParams::pClientID, TLSConnectParams::pDestinationURL, TLSConnectParams::pDeviceCertLocation, MQTTConnectParams::pDeviceCertLocation, TLSConnectParams::pDevicePrivateKeyLocation, MQTTConnectParams::pDevicePrivateKeyLocation, MQTTConnectParams::pHostURL, MQTTwillOptions::pMessage, MQTTConnectParams::port, MQTTConnectParams::pPassword, TLSConnectParams::pRootCALocation, MQTTConnectParams::pRootCALocation, MQTTwillOptions::pTopicName, MQTTConnectParams::pUserName, MQTTwillOptions::qos, MQTTPacket_willOptions::qos, readbuf, MQTTPacket_willOptions::retained, TLSConnectParams::ServerVerificationFlag, setDisconnectHandler(), SUCCESS, TLSConnectParams::timeout_ms, MQTTConnectParams::tlsHandshakeTimeout_ms, MQTTPacket_willOptions::topicName, MQTTPacket_connectData::username, MQTTConnectParams::will, MQTTPacket_connectData::will, MQTTPacket_connectData::willFlag, and writebuf.

Referenced by aws_iot_mqtt_init(), and main().

IoT_Error_t aws_iot_mqtt_disconnect ( void  )

Disconnect an MQTT Connection.

Called to send a disconnect message to the broker.

Returns
An IoT Error Type defining successful/failed send of the disconnect control packet.

References DISCONNECT_ERROR, MQTTDisconnect(), and NONE_ERROR.

Referenced by aws_iot_mqtt_init().

IoT_Error_t aws_iot_mqtt_publish ( MQTTPublishParams pParams)

Publish an MQTT message on a topic.

Called to publish an MQTT message on a topic.

Note
Call is blocking. In the case of a QoS 0 message the function returns after the message was successfully passed to the TLS layer. In the case of QoS 1 the function returns after the receipt of the PUBACK control packet.
Parameters
pParamsPointer to MQTT publish parameters
Returns
An IoT Error Type defining successful/failed publish

References MQTTMessage::dup, MQTTMessage::id, MQTTMessageParams::id, MQTTMessageParams::isDuplicate, MQTTMessageParams::isRetained, MQTTPublishParams::MessageParams, MQTTPublish(), NONE_ERROR, MQTTMessage::payload, MQTTMessage::payloadlen, MQTTMessageParams::PayloadLen, MQTTMessageParams::pPayload, MQTTPublishParams::pTopic, PUBLISH_ERROR, MQTTMessageParams::qos, MQTTMessage::qos, and MQTTMessage::retained.

Referenced by aws_iot_mqtt_init(), and main().

IoT_Error_t aws_iot_mqtt_subscribe ( MQTTSubscribeParams pParams)

Subscribe to an MQTT topic.

Called to send a subscribe message to the broker requesting a subscription to an MQTT topic.

Note
Call is blocking. The call returns after the receipt of the SUBACK control packet.
Parameters
pParamsPointer to MQTT subscribe parameters
Returns
An IoT Error Type defining successful/failed subscription

References MQTTSubscribeParams::mHandler, MQTTSubscribe(), NONE_ERROR, pahoMessageCallback(), MQTTSubscribeParams::pTopic, MQTTSubscribeParams::qos, and SUBSCRIBE_ERROR.

Referenced by aws_iot_mqtt_init(), and main().

IoT_Error_t aws_iot_mqtt_unsubscribe ( char *  pTopic)

Unsubscribe to an MQTT topic.

Called to send an usubscribe message to the broker requesting removal of a subscription to an MQTT topic.

Note
Call is blocking. The call returns after the receipt of the UNSUBACK control packet.
Parameters
pTopicPointer to the requested topic string. Ensure the string is null terminated
Returns
An IoT Error Type defining successful/failed unsubscription

References MQTTUnsubscribe(), NONE_ERROR, and UNSUBSCRIBE_ERROR.

Referenced by aws_iot_mqtt_init().

IoT_Error_t aws_iot_mqtt_yield ( int  timeout)

Yield to the MQTT client.

Called to yield the current thread to the underlying MQTT client. This time is used by the MQTT client to manage PING requests to monitor the health of the TCP connection as well as periodically check the socket receive buffer for subscribe messages. Yield() must be called at a rate faster than the keepalive interval. It must also be called at a rate faster than the incoming message rate as this is the only way the client receives processing time to manage incoming messages.

Parameters
timeoutMaximum number of milliseconds to pass thread execution to the client.
Returns
An IoT Error Type defining successful/failed client processing. If this call results in an error it is likely the MQTT connection has dropped. iot_is_mqtt_connected can be called to confirm.

References MQTT_ATTEMPTING_RECONNECT, MQTT_BUFFER_RX_MESSAGE_INVALID, MQTT_NETWORK_DISCONNECTED_ERROR, MQTT_NETWORK_RECONNECTED, MQTT_NULL_VALUE_ERROR, MQTT_RECONNECT_TIMED_OUT, MQTTPACKET_BUFFER_TOO_SHORT, MQTTYield(), NETWORK_ATTEMPTING_RECONNECT, NETWORK_DISCONNECTED, NETWORK_RECONNECT_TIMED_OUT, NONE_ERROR, NULL_VALUE_ERROR, RECONNECT_SUCCESSFUL, RX_MESSAGE_BIGGER_THAN_MQTT_RX_BUF, RX_MESSAGE_INVALID, SUCCESS, and YIELD_ERROR.

Referenced by aws_iot_mqtt_init(), and main().

void pahoDisconnectHandler ( void  )

References clientDisconnectHandler, and NULL.

Referenced by aws_iot_mqtt_connect().

Client c
static

Referenced by _eeprom_emulator_create_master_page(), _eeprom_emulator_is_page_free_on_row(), _eeprom_emulator_move_data_to_spare(), _eeprom_emulator_update_page_mapping(), _eeprom_emulator_verify_master_page(), _rww_eeprom_emulator_create_master_page(), _rww_eeprom_emulator_is_page_free_on_row(), _rww_eeprom_emulator_move_data_to_spare(), _rww_eeprom_emulator_update_page_mapping(), _rww_eeprom_emulator_verify_master_page(), about_co_routine(), about_task(), arp_update(), base64decode(), buf_bufto(), buffered_uart_getchar(), buffered_uart_getchar_nowait(), casecmp(), create_name(), dir_find(), dir_next(), dir_read(), dir_register(), eeprom_emulator_read_buffer(), eeprom_emulator_write_buffer(), frame802154_create(), frame802154_parse(), get_fileinfo(), getbytes(), httpd_cgi_add(), ifft(), jsmn_parse(), jsmn_parse_string(), me_decode16(), me_encode(), MQTTPacket_decode(), MQTTPacket_decodenb(), MQTTRun(), netstack_aes_decrypt(), netstack_aes_encrypt(), netstack_aes_verify(), nmi_inet_addr(), parse_header_byte(), PROCESS_THREAD(), readChar(), ringbuf_get(), ringbuf_put(), rww_eeprom_emulator_read_buffer(), rww_eeprom_emulator_write_buffer(), serial_bridge_frame_get_nm_command(), set_packet_attrs(), sio2host_getchar(), sio2host_getchar_nowait(), sio2ncp_getchar(), sio2ncp_getchar_nowait(), slip_input_byte(), slip_send(), slip_set_input_callback(), slip_write(), slipdev_poll(), slipdev_send(), uip_icmp6_echo_reply_callback_add(), uip_init(), uip_process(), uip_udp_packet_send(), uiplib_ip4addrconv(), uiplib_ip6addrconv(), usart_getdata_xmd(), usart_putdata_xmd(), websocket_open(), and writeChar().

iot_disconnect_handler clientDisconnectHandler
static
bool isPowerCycle = true
static

Referenced by aws_iot_mqtt_connect().

const MQTTCallbackParams MQTTCallbackParamsDefault
Initial value:
={
.pTopicName = NULL,
.TopicNameLen = 0,
.MessageParams = {.qos = QOS_0, .isRetained=false, .isDuplicate = false, .id = 0, .pPayload = NULL, .PayloadLen = 0}
}
#define NULL
Definition: def.h:47
QoS 0 = at most once delivery.
Definition: aws_iot_mqtt_interface.h:48
const MQTTConnectParams MQTTConnectParamsDefault
Initial value:
= {
.enableAutoReconnect = 0,
.pHostURL = AWS_IOT_MQTT_HOST,
.port = AWS_IOT_MQTT_PORT,
.pRootCALocation = NULL,
.pDeviceCertLocation = NULL,
.pDevicePrivateKeyLocation = NULL,
.pClientID = NULL,
.pUserName = NULL,
.pPassword = NULL,
.MQTTVersion = MQTT_3_1_1,
.KeepAliveInterval_sec = 10,
.isCleansession = true,
.isWillMsgPresent = false,
.will={.pTopicName = NULL, .pMessage = NULL, .isRetained = false, .qos = QOS_0},
.mqttCommandTimeout_ms = 1000,
.tlsHandshakeTimeout_ms = 2000,
.isSSLHostnameVerify = true,
.disconnectHandler = NULL
}
#define NULL
Definition: def.h:47
MQTT 3.1.1 (protocol message byte = 4)
Definition: aws_iot_mqtt_interface.h:37
QoS 0 = at most once delivery.
Definition: aws_iot_mqtt_interface.h:48

Referenced by aws_iot_shadow_connect(), and main().

const MQTTMessageParams MQTTMessageParamsDefault
Initial value:
={
.qos = QOS_0,
.isRetained=false,
.isDuplicate = false,
.id = 0,
.pPayload = NULL,
.PayloadLen = 0
}
#define NULL
Definition: def.h:47
QoS 0 = at most once delivery.
Definition: aws_iot_mqtt_interface.h:48

Referenced by main(), and publishToShadowAction().

const MQTTPublishParams MQTTPublishParamsDefault
Initial value:
={
.pTopic = NULL,
.MessageParams = {.qos = QOS_0, .isRetained=false, .isDuplicate = false, .id = 0, .pPayload = NULL, .PayloadLen = 0}
}
#define NULL
Definition: def.h:47
QoS 0 = at most once delivery.
Definition: aws_iot_mqtt_interface.h:48

Referenced by main(), and publishToShadowAction().

const MQTTSubscribeParams MQTTSubscribeParamsDefault
Initial value:
={
.pTopic = NULL,
.qos = QOS_0,
.mHandler = NULL
}
#define NULL
Definition: def.h:47
QoS 0 = at most once delivery.
Definition: aws_iot_mqtt_interface.h:48

Referenced by main(), and subscribeToShadowActionAcks().

const MQTTwillOptions MQTTwillOptionsDefault
Initial value:
={
.pTopicName = NULL,
.pMessage = NULL,
.isRetained = false,
.qos = QOS_0
}
#define NULL
Definition: def.h:47
QoS 0 = at most once delivery.
Definition: aws_iot_mqtt_interface.h:48
unsigned char readbuf[AWS_IOT_MQTT_RX_BUF_LEN]
static

Referenced by aws_iot_mqtt_connect().

unsigned char writebuf[AWS_IOT_MQTT_TX_BUF_LEN]
static

Referenced by aws_iot_mqtt_connect().