WINC1500 Weather Client Example.
Copyright (c) 2016-2018 Microchip Technology Inc. and its subsidiaries.
#include "asf.h"
#include "main.h"
#include "bsp/include/nm_bsp.h"
#include "socket/include/socket.h"
Macros | |
#define | STRING_EOL "\r\n" |
#define | STRING_HEADER |
Functions | |
static void | configure_console (void) |
Configure UART console. More... | |
int | main (void) |
Main application function. More... | |
static void | resolve_cb (uint8_t *hostName, uint32_t hostIp) |
Callback function of IP address. More... | |
static void | set_dev_name_to_mac (uint8_t *name, uint8_t *mac_addr) |
static void | socket_cb (SOCKET sock, uint8_t u8Msg, void *pvMsg) |
Callback function of TCP client socket. More... | |
static void | wifi_cb (uint8_t u8MsgType, void *pvMsg) |
Callback to get the Wi-Fi status update. More... | |
Variables | |
static struct usart_module | cdc_uart_module |
UART module for debug. More... | |
static uint8_t | gau8ReceivedBuffer [MAIN_WIFI_M2M_BUFFER_SIZE] = {0} |
Receive buffer definition. More... | |
static bool | gbConnectedWifi = false |
Wi-Fi status variable. More... | |
static bool | gbHostIpByName = false |
Get host IP status variable. More... | |
static bool | gbTcpConnection = false |
TCP Connection status variable. More... | |
uint32_t | gu32HostIp = 0 |
IP address of host. More... | |
static SOCKET | tcp_client_socket = -1 |
TCP client socket handlers. More... | |
#define STRING_EOL "\r\n" |
#define STRING_HEADER |
Referenced by main().
|
static |
Configure UART console.
References usart_config::baudrate, cdc_uart_module, EDBG_CDC_MODULE, EDBG_CDC_SERCOM_MUX_SETTING, EDBG_CDC_SERCOM_PINMUX_PAD0, EDBG_CDC_SERCOM_PINMUX_PAD1, EDBG_CDC_SERCOM_PINMUX_PAD2, EDBG_CDC_SERCOM_PINMUX_PAD3, usart_config::mux_setting, usart_config::pinmux_pad0, usart_config::pinmux_pad1, usart_config::pinmux_pad2, usart_config::pinmux_pad3, usart_enable(), and usart_get_config_defaults().
Referenced by main().
int main | ( | void | ) |
Main application function.
Initialize system, UART console, network then start weather client.
References _htons, AF_INET, tstrM2MAPConfig::au8DHCPServerIP, tstrM2MAPConfig::au8SSID, configure_console(), connect(), gacDeviceName, gacHttpProvDomainName, gau8MacAddr, gbConnectedWifi, gbHostIpByName, gbTcpConnection, gstrM2MAPConfig, gu32HostIp, m2m_strlen(), M2M_SUCCESS, m2m_wifi_get_mac_address(), m2m_wifi_get_otp_mac_address(), m2m_wifi_handle_events(), m2m_wifi_init(), m2m_wifi_set_device_name(), m2m_wifi_set_mac_address(), m2m_wifi_start_provision_mode(), MAIN_HTTP_PROV_SERVER_DOMAIN_NAME, MAIN_SERVER_PORT, nm_bsp_init(), NULL, tstrWifiInitParam::pfAppWifiCb, registerSocketCallback(), resolve_cb(), in_addr::s_addr, set_dev_name_to_mac(), sockaddr_in::sin_addr, sockaddr_in::sin_family, sockaddr_in::sin_port, SOCK_ERR_NO_ERROR, SOCK_STREAM, socket(), socket_cb(), socketInit(), STRING_HEADER, system_init(), tcp_client_socket, and wifi_cb().
|
static |
Callback function of IP address.
[in] | hostName | Domain name. |
[in] | hostIp | Server IP. |
References gbHostIpByName, gu32HostIp, and IPV4_BYTE.
Referenced by main().
|
static |
References m2m_strlen(), and MAIN_HEX2ASCII.
Referenced by main().
|
static |
Callback function of TCP client socket.
[in] | sock | socket handler. |
[in] | u8Msg | Type of Socket notification |
[in] | pvMsg | A structure contains notification informations. |
References close(), gau8ReceivedBuffer, gbTcpConnection, LED_0_PIN, MAIN_CITY_NAME, MAIN_POST_BUFFER, MAIN_PREFIX_BUFFER, MAIN_WIFI_M2M_BUFFER_SIZE, NULL, port_pin_set_output_level(), tstrSocketRecvMsg::pu8Buffer, recv(), tstrSocketRecvMsg::s16BufferSize, tstrSocketConnectMsg::s8Error, send(), SOCK_ERR_NO_ERROR, SOCKET_MSG_CONNECT, SOCKET_MSG_RECV, and tcp_client_socket.
Referenced by main().
|
static |
Callback to get the Wi-Fi status update.
[in] | u8MsgType | Type of Wi-Fi notification. |
[in] | pvMsg | A pointer to a buffer containing the notification parameters. |
References tstrM2MProvisionInfo::au8Password, tstrM2MProvisionInfo::au8SSID, gbConnectedWifi, gethostbyname(), M2M_SUCCESS, 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, M2M_WIFI_RESP_PROVISION_INFO, MAIN_WEATHER_SERVER_NAME, tstrM2mWifiStateChanged::u8CurrState, tstrM2MProvisionInfo::u8SecType, and tstrM2MProvisionInfo::u8Status.
Referenced by main().
|
static |
UART module for debug.
Referenced by configure_console().
|
static |
Receive buffer definition.
Referenced by socket_cb().
Get host IP status variable.
Referenced by main(), and resolve_cb().
TCP Connection status variable.
Referenced by main(), and socket_cb().
uint32_t gu32HostIp = 0 |
IP address of host.
Referenced by main(), and resolve_cb().
|
static |
TCP client socket handlers.
Referenced by main(), and socket_cb().