WINC1500 MQTT chat example.
Copyright (c) 2017-2018 Microchip Technology Inc. and its subsidiaries.
#include "asf.h"
#include "main.h"
#include "driver/include/m2m_wifi.h"
#include "MQTTClient/Wrapper/mqtt.h"
#include "socket/include/socket.h"
Macros | |
#define | STRING_EOL "\r\n" |
#define | STRING_HEADER |
Functions | |
static void | check_usart_buffer (char *topic) |
Checking the USART buffer. More... | |
static void | configure_console (void) |
Configure UART console. More... | |
static void | configure_mqtt (void) |
Configure MQTT service. More... | |
int | main (void) |
Main application function. More... | |
static void | mqtt_callback (struct mqtt_module *module_inst, int type, union mqtt_data *data) |
Callback to get the MQTT status update. More... | |
static void | socket_event_handler (SOCKET sock, uint8_t msg_type, void *msg_data) |
Callback to get the Socket event. More... | |
static void | socket_resolve_handler (uint8_t *doamin_name, uint32_t server_ip) |
Callback of gethostbyname function. More... | |
void | SubscribeHandler (MessageData *msgData) |
Prototype for MQTT subscribe Callback. More... | |
static void | uart_callback (const struct usart_module *const module) |
Callback of USART input. More... | |
static void | wifi_callback (uint8 msg_type, void *msg_data) |
Callback to get the Wi-Fi status update. More... | |
Variables | |
static struct usart_module | cdc_uart_module |
UART module for debug. More... | |
static struct mqtt_module | mqtt_inst |
static unsigned char | mqtt_read_buffer [MAIN_MQTT_BUFFER_SIZE] |
static unsigned char | mqtt_send_buffer [MAIN_MQTT_BUFFER_SIZE] |
char | mqtt_user [64] = "" |
User name of chat. More... | |
static char | uart_buffer [MAIN_CHAT_BUFFER_SIZE] |
UART buffer. More... | |
static int | uart_buffer_written = 0 |
Written size of UART buffer. More... | |
static uint16_t | uart_ch_buffer |
A buffer of character from the serial. More... | |
#define STRING_EOL "\r\n" |
#define STRING_HEADER |
Referenced by main().
|
static |
Checking the USART buffer.
Finding the new line character(
or
) in the USART buffer. If buffer was overflowed, Sending the buffer.
References i, MAIN_CHAT_BUFFER_SIZE, mqtt_inst, mqtt_publish(), uart_buffer, and uart_buffer_written.
Referenced by main().
|
static |
Configure UART console.
References usart_config::baudrate, cdc_uart_module, usart_config::mux_setting, usart_config::pinmux_pad0, usart_config::pinmux_pad1, usart_config::pinmux_pad2, usart_config::pinmux_pad3, uart_callback(), USART_CALLBACK_BUFFER_RECEIVED, usart_enable(), usart_get_config_defaults(), and usart_register_callback().
|
static |
Configure MQTT service.
References MAIN_MQTT_BUFFER_SIZE, mqtt_callback(), mqtt_get_config_defaults(), mqtt_init(), mqtt_inst, mqtt_read_buffer, mqtt_register_callback(), mqtt_send_buffer, printf, mqtt_config::read_buffer, mqtt_config::read_buffer_size, result, mqtt_config::send_buffer, and mqtt_config::send_buffer_size.
Referenced by main().
int main | ( | void | ) |
Main application function.
Application entry point.
References cdc_uart_module, check_usart_buffer(), configure_console(), configure_mqtt(), mqtt_module::isConnected, M2M_SUCCESS, M2M_WIFI_CH_ALL, m2m_wifi_connect(), m2m_wifi_handle_events(), m2m_wifi_init(), MAIN_CHAT_TOPIC, MAIN_CHAT_USER_NAME_SIZE, MAIN_WLAN_AUTH, MAIN_WLAN_PSK, MAIN_WLAN_SSID, mqtt_inst, mqtt_user, mqtt_yield(), nm_bsp_init(), NULL, tstrWifiInitParam::pfAppWifiCb, printf, registerSocketCallback(), ret, socket_event_handler(), socket_resolve_handler(), socketInit(), STRING_HEADER, system_cpu_clock_get_hz(), system_init(), uart_ch_buffer, usart_read_job(), and wifi_callback().
|
static |
Callback to get the MQTT status update.
[in] | conn_id | instance id of connection which is being used. |
[in] | type | type of MQTT notification. Possible types are: |
[in] | data | A structure contains notification informations. mqtt_data |
References cdc_uart_module, mqtt_data::connected, MAIN_CHAT_TOPIC, main_mqtt_broker, MQTT_CALLBACK_CONNECTED, MQTT_CALLBACK_DISCONNECTED, MQTT_CALLBACK_SOCK_CONNECTED, MQTT_CONN_RESULT_ACCEPT, mqtt_connect(), mqtt_connect_broker(), mqtt_subscribe(), mqtt_user, NULL, printf, mqtt_data_sock_connected::result, mqtt_data_connected::result, mqtt_data::sock_connected, SubscribeHandler(), USART_CALLBACK_BUFFER_RECEIVED, usart_disable_callback(), and usart_enable_callback().
Referenced by configure_mqtt().
|
static |
Callback to get the Socket event.
[in] | Socket | descriptor. |
[in] | msg_type | type of Socket notification. Possible types are: |
[in] | msg_data | A structure contains notification informations. |
References mqtt_socket_event_handler().
Referenced by main().
|
static |
Callback of gethostbyname function.
[in] | doamin_name | Domain name. |
[in] | server_ip | IP of server. |
References mqtt_socket_resolve_handler().
Referenced by main().
void SubscribeHandler | ( | MessageData * | msgData | ) |
Prototype for MQTT subscribe Callback.
Callback to receive the subscribed Message.
[in] | msgData | Data to be received. |
References MQTTLenString::data, MQTTLenString::len, MQTTString::lenstring, MessageData::message, MQTTMessage::payload, MQTTMessage::payloadlen, printf, and MessageData::topicName.
Referenced by mqtt_callback().
|
static |
Callback of USART input.
[in] | module | USART module structure. |
References MAIN_CHAT_BUFFER_SIZE, uart_buffer, uart_buffer_written, and uart_ch_buffer.
Referenced by configure_console().
|
static |
Callback to get the Wi-Fi status update.
[in] | msg_type | type of Wi-Fi notification. Possible types are:
|
[in] | pvMsg | A pointer to a buffer containing the notification parameters (if any). It should be casted to the correct data type corresponding to the notification type. Existing types are:
|
References M2M_WIFI_CH_ALL, m2m_wifi_connect(), M2M_WIFI_CONNECTED, M2M_WIFI_DISCONNECTED, M2M_WIFI_REQ_DHCP_CONF, m2m_wifi_request_dhcp_client(), M2M_WIFI_RESP_CON_STATE_CHANGED, main_mqtt_broker, MAIN_WLAN_AUTH, MAIN_WLAN_PSK, MAIN_WLAN_SSID, mqtt_connect(), mqtt_disconnect(), mqtt_inst, printf, and tstrM2mWifiStateChanged::u8CurrState.
Referenced by main().
|
static |
UART module for debug.
|
static |
Referenced by check_usart_buffer(), configure_mqtt(), main(), and wifi_callback().
|
static |
Referenced by configure_mqtt().
|
static |
Referenced by configure_mqtt().
char mqtt_user[64] = "" |
User name of chat.
Referenced by main(), and mqtt_callback().
|
static |
UART buffer.
Referenced by check_usart_buffer(), and uart_callback().
|
static |
Written size of UART buffer.
Referenced by check_usart_buffer(), and uart_callback().
|
static |
A buffer of character from the serial.
Referenced by main(), and uart_callback().