Microchip® Advanced Software Framework

main21.c File Reference

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
Value:
"-- WINC1500 Wi-Fi MQTT chat example --"STRING_EOL \
"-- "BOARD_NAME " --"STRING_EOL \
"-- Compiled: "__DATE__ " "__TIME__ " --"STRING_EOL
#define STRING_EOL
Definition: main21.c:94
#define BOARD_NAME
Name string macro.
Definition: saml21_xplained_pro.h:65

Referenced by main().

static void check_usart_buffer ( char *  topic)
static

Checking the USART buffer.

Finding the new line character(
or
) in the USART buffer. If buffer was overflowed, Sending the buffer.

References MAIN_CHAT_BUFFER_SIZE, mqtt_inst, mqtt_publish(), uart_buffer, and uart_buffer_written.

Referenced by main().

static void mqtt_callback ( struct mqtt_module module_inst,
int  type,
union mqtt_data data 
)
static
static void socket_event_handler ( SOCKET  sock,
uint8_t  msg_type,
void *  msg_data 
)
static

Callback to get the Socket event.

Parameters
[in]Socketdescriptor.
[in]msg_typetype of Socket notification. Possible types are:
[in]msg_dataA structure contains notification informations.

References mqtt_socket_event_handler().

Referenced by main().

static void socket_resolve_handler ( uint8_t *  doamin_name,
uint32_t  server_ip 
)
static

Callback of gethostbyname function.

Parameters
[in]doamin_nameDomain name.
[in]server_ipIP 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.

Parameters
[in]msgDataData to be received.

References MQTTLenString::data, MQTTLenString::len, MQTTString::lenstring, MessageData::message, MQTTMessage::payload, MQTTMessage::payloadlen, and MessageData::topicName.

Referenced by mqtt_callback().

static void uart_callback ( const struct usart_module *const  module)
static

Callback of USART input.

Parameters
[in]moduleUSART module structure.

References MAIN_CHAT_BUFFER_SIZE, uart_buffer, uart_buffer_written, and uart_ch_buffer.

Referenced by configure_console().

static void wifi_callback ( uint8  msg_type,
void *  msg_data 
)
static

Callback to get the Wi-Fi status update.

Parameters
[in]msg_typetype of Wi-Fi notification. Possible types are:
[in]pvMsgA 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, and tstrM2mWifiStateChanged::u8CurrState.

Referenced by main().

struct usart_module cdc_uart_module
static

UART module for debug.

Referenced by configure_console(), main(), and mqtt_callback().

struct mqtt_module mqtt_inst
static
unsigned char mqtt_read_buffer[MAIN_MQTT_BUFFER_SIZE]
static

Referenced by configure_mqtt().

unsigned char mqtt_send_buffer[MAIN_MQTT_BUFFER_SIZE]
static

Referenced by configure_mqtt().

char mqtt_user[64] = ""

User name of chat.

Referenced by main(), and mqtt_callback().

char uart_buffer[MAIN_CHAT_BUFFER_SIZE]
static

UART buffer.

Referenced by check_usart_buffer(), and uart_callback().

int uart_buffer_written = 0
static

Written size of UART buffer.

Referenced by check_usart_buffer(), and uart_callback().

uint16_t uart_ch_buffer
static

A buffer of character from the serial.

Referenced by main(), and uart_callback().