IoT Cloud Demo.
Copyright (c) 2016-2018 Microchip Technology Inc. and its subsidiaries.
#include "asf.h"
#include "common/include/nm_common.h"
#include "driver/include/m2m_wifi.h"
#include "socket/include/socket.h"
#include "demo.h"
#include "PubNub.h"
Data Structures | |
struct | s_msg_temp_keepalive |
struct | s_msg_temp_prov |
struct | s_msg_temp_report |
struct | s_msg_user_input |
Message format definitions. More... | |
Macros | |
#define | HEX2ASCII(x) (((x) >= 10) ? (((x) - 10) + 'A') : ((x) + '0')) |
#define | IPV4_BYTE(val, index) ((val >> (index * 8)) & 0xFF) |
#define | STRING_EOL "\r\n" |
#define | STRING_HEADER |
#define | TEST_BUFFER_SIZE 1460 |
Android app: receive buffer definition. More... | |
Typedefs | |
typedef struct s_msg_temp_keepalive | t_msg_temp_keepalive |
typedef struct s_msg_temp_prov | t_msg_temp_prov |
typedef struct s_msg_temp_report | t_msg_temp_report |
typedef struct s_msg_user_input | t_msg_user_input |
Message format definitions. More... | |
typedef enum wifi_status | wifi_status_t |
Functions | |
static uint32_t | button_press_duration (bool current_button_state) |
Get duration of the SW0 button pressed. More... | |
static void | configure_button_led (void) |
static void | configure_console (void) |
Configure UART console. More... | |
static void | configure_light_sensor (void) |
static void | m2m_wifi_socket_handler (SOCKET sock, uint8_t u8Msg, void *pvMsg) |
Callback to get the Socket event. More... | |
static void | m2m_wifi_state (uint8_t u8MsgType, void *pvMsg) |
Callback to get the Wi-Fi status update. More... | |
int | main (void) |
Main application function. More... | |
static void | set_dev_name_to_mac (uint8 *name, uint8 *mac_addr) |
static void | setup_android_sockets (void) |
static void | socket_resolve_cb (uint8_t *hostName, uint32_t hostIp) |
Callback of gethostbyname function. More... | |
void | SysTick_Handler (void) |
Variables | |
struct adc_module | adc_instance |
UART module for debug. More... | |
struct sockaddr_in | addr |
static struct usart_module | cdc_uart_module |
UART module for debug. More... | |
static uint8 | gau8SocketTestBuffer [TEST_BUFFER_SIZE] |
static const char | gchHttpProvDomainName [] = DEMO_WLAN_AP_DOMAIN_NAME |
static char | gPSK [64] = { 0 } |
static char | gs8DeviceName [] = DEMO_WLAN_AP_NAME |
static int | gSecType = M2M_WIFI_SEC_WPA_PSK |
static char | gSSID [64] = { 0 } |
static tstrM2MAPConfig | gstrM2MAPConfig |
static uint32_t | gu32androidDelay = 0 |
Android app: global counter delay for android app report. More... | |
static uint32_t | gu32disconnectCount = 0 |
WiFi disconnect event counter. More... | |
volatile uint32_t | gu32MsTicks = 0 |
SysTick counter to avoid busy wait delay. More... | |
static uint32_t | gu32publishDelay = 0 |
Global counter delay for timer. More... | |
static uint32_t | gu32subscribeDelay = 0 |
wifi_status_t | gWifiState = WifiStateInit |
WiFi status variable. More... | |
static t_msg_temp_keepalive | msg_temp_keepalive |
Message format declarations. More... | |
static t_msg_temp_report | msg_temp_report |
static pubnub_t * | pPubNubCfg |
static char | PubNubChannel [] = DEMO_PUBNUB_CHANNEL |
static const char | PubNubPublishKey [] = DEMO_PUBNUB_PUBLISH_KEY |
PubNub global variables. More... | |
static const char | PubNubSubscribeKey [] = DEMO_PUBNUB_SUBSCRIBE_KEY |
static SOCKET | sock_rx_android = -1 |
Android app: RX and TX socket descriptors. More... | |
static SOCKET | sock_tx_android = -1 |
#define HEX2ASCII | ( | x | ) | (((x) >= 10) ? (((x) - 10) + 'A') : ((x) + '0')) |
Referenced by set_dev_name_to_mac().
#define IPV4_BYTE | ( | val, | |
index | |||
) | ((val >> (index * 8)) & 0xFF) |
Referenced by socket_resolve_cb().
#define STRING_EOL "\r\n" |
#define STRING_HEADER |
Referenced by main().
#define TEST_BUFFER_SIZE 1460 |
Android app: receive buffer definition.
Referenced by m2m_wifi_socket_handler().
typedef struct s_msg_temp_keepalive t_msg_temp_keepalive |
typedef struct s_msg_temp_prov t_msg_temp_prov |
typedef struct s_msg_temp_report t_msg_temp_report |
typedef struct s_msg_user_input t_msg_user_input |
Message format definitions.
typedef enum wifi_status wifi_status_t |
enum wifi_status |
|
static |
Get duration of the SW0 button pressed.
References gu32MsTicks.
Referenced by main().
|
static |
References port_config::direction, port_get_config_defaults(), PORT_PIN_DIR_OUTPUT, port_pin_set_config(), and port_pin_set_output_level().
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, usart_enable(), and usart_get_config_defaults().
|
static |
References adc_enable(), adc_get_config_defaults(), adc_init(), adc_instance, and GCLK_GENERATOR_0.
Referenced by main().
|
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 DEMO_ANDROID_SENSOR_NAME, gau8SocketTestBuffer, gPSK, gSecType, gSSID, gu32androidDelay, gWifiState, handle_tcpip(), s_msg_temp_report::id0, s_msg_temp_prov::id0, s_msg_temp_report::id1, s_msg_temp_prov::id1, s_msg_temp_report::led, M2M_WIFI_CH_ALL, m2m_wifi_connect(), m2m_wifi_stop_provision_mode(), s_msg_temp_report::name, s_msg_temp_prov::pass, port_pin_set_output_level(), printf, tstrSocketRecvMsg::pu8Buffer, recvfrom(), tstrSocketRecvMsg::s16BufferSize, s_msg_temp_prov::sec, sock_rx_android, SOCKET_MSG_BIND, SOCKET_MSG_RECVFROM, s_msg_temp_prov::ssid, tstrSocketBindMsg::status, TEST_BUFFER_SIZE, WifiStateConnecting, and WifiStateWaitingProv.
Referenced by main().
|
static |
Callback to get the Wi-Fi status update.
[in] | u8MsgType | 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 tstrM2MProvisionInfo::au8Password, tstrM2MAPConfig::au8SSID, tstrM2MProvisionInfo::au8SSID, DEMO_WLAN_AP_DOMAIN_NAME, gchHttpProvDomainName, gPSK, gSecType, gSSID, gu32disconnectCount, gWifiState, M2M_DEFAULT_CONN_EMPTY_LIST, M2M_DEFAULT_CONN_SCAN_MISMATCH, M2M_SUCCESS, M2M_WIFI_CH_ALL, m2m_wifi_connect(), M2M_WIFI_CONNECTED, M2M_WIFI_DISCONNECTED, M2M_WIFI_REQ_DHCP_CONF, M2M_WIFI_RESP_CON_STATE_CHANGED, M2M_WIFI_RESP_DEFAULT_CONNECT, M2M_WIFI_RESP_PROVISION_INFO, m2m_wifi_start_provision_mode(), port_pin_set_output_level(), printf, tstrM2MDefaultConnResp::s8ErrorCode, setup_android_sockets(), tstrM2mWifiStateChanged::u8CurrState, tstrM2MProvisionInfo::u8SecType, tstrM2MProvisionInfo::u8Status, WifiStateConnected, WifiStateConnecting, and WifiStateWaitingProv.
Referenced by main().
int main | ( | void | ) |
Main application function.
Initialize board and WINC1500 Wi-Fi module. Publish and subscribe event to pubnub.
References adc_instance, adc_read(), adc_start_conversion(), addr, at30tse_init(), at30tse_read_temperature(), tstrM2MAPConfig::au8SSID, buf, button_press_duration(), close(), configure_button_led(), configure_console(), configure_light_sensor(), delay_init(), DEMO_ANDROID_REPORT_INTERVAL, DEMO_PUBNUB_PUBLISH_INTERVAL, DEMO_PUBNUB_SUBSCRIBE_INTERVAL, gchHttpProvDomainName, gs8DeviceName, gu32androidDelay, gu32MsTicks, gu32publishDelay, gu32subscribeDelay, gWifiState, pubnub::last_result, s_msg_temp_report::led, s_msg_temp_report::light, m2m_strlen(), M2M_SUCCESS, m2m_wifi_default_connect(), 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_socket_handler(), m2m_wifi_start_provision_mode(), m2m_wifi_state(), mac_addr, s_msg_temp_keepalive::name, s_msg_temp_report::name, nm_bsp_init(), NULL, PBTT_NONE, PBTT_PUBLISH, tstrWifiInitParam::pfAppWifiCb, PNR_IO_ERROR, PNR_OK, port_pin_get_input_level(), port_pin_get_output_level(), port_pin_set_output_level(), port_pin_toggle_output_level(), printf, PS_IDLE, pubnub_get(), pubnub_get_ctx(), pubnub_init(), pubnub_publish(), pubnub_subscribe(), PubNubChannel, PubNubPublishKey, PubNubSubscribeKey, registerSocketCallback(), ret, sendto(), set_dev_name_to_mac(), sock_tx_android, socket_resolve_cb(), socketInit(), pubnub::state, STRING_HEADER, system_cpu_clock_get_hz(), system_init(), pubnub::tcp_socket, s_msg_temp_report::temp, pubnub::trans, WifiStateConnected, WifiStateConnecting, and WifiStateWaitingProv.
References HEX2ASCII, len, and m2m_strlen().
Referenced by main().
|
static |
References _htons, addr, AF_INET, bind(), close(), DEMO_ANDROID_SERVER_PORT, in_addr::s_addr, sockaddr_in::sin_addr, sockaddr_in::sin_family, sockaddr_in::sin_port, SOCK_DGRAM, sock_rx_android, sock_tx_android, and socket().
Referenced by m2m_wifi_state().
|
static |
Callback of gethostbyname function.
[in] | doamin_name | Domain name. |
[in] | server_ip | IP of server. |
References handle_dns_found(), IPV4_BYTE, and printf.
Referenced by main().
void SysTick_Handler | ( | void | ) |
References gu32MsTicks.
struct adc_module adc_instance |
UART module for debug.
Support and FAQ: visit Microchip Support
Referenced by _lightsensor_init(), adc_correction_start(), adc_correction_stop(), adc_differential(), adc_hardware_averaging(), adc_oversampling(), adc_start_read_result(), adc_window_monitor(), adp_example_adc_get_value(), adp_example_adc_init(), configure_adc(), configure_adc_averaging(), configure_adc_callbacks(), configure_adc_differential(), configure_adc_sampling(), configure_adc_temp(), configure_adc_window_monitor(), configure_light_sensor(), io1_board_get_lightvalue(), io1_board_prepare_to_get_info(), main(), sam0_sensors_init(), and setup_transfer_descriptor().
struct sockaddr_in addr |
Referenced by _spi_check_config(), app_init(), appCmdBuffer(), ble_device_config(), ble_set_address(), ConnectNetwork(), dhcpc_init(), dio_output(), dsu_crc32_cal(), ip64_init(), main(), NWK_SetAddr(), packetbuf_attr_clear(), PROCESS_THREAD(), run_udp_client(), run_udp_server(), send_msg(), send_packet(), set_link_addr(), setup_android_sockets(), slip_poll_handler(), socket_cb(), start_get(), start_request(), test_init(), and uip_ds6_defrt_choose().
|
static |
UART module for debug.
|
static |
Referenced by m2m_wifi_socket_handler().
|
static |
Referenced by m2m_wifi_state(), and main().
|
static |
Referenced by m2m_wifi_socket_handler(), and m2m_wifi_state().
|
static |
Referenced by main().
|
static |
Referenced by m2m_wifi_socket_handler(), and m2m_wifi_state().
|
static |
Referenced by m2m_wifi_socket_handler(), and m2m_wifi_state().
|
static |
Referenced by main().
|
static |
Android app: global counter delay for android app report.
Referenced by m2m_wifi_socket_handler(), and main().
|
static |
WiFi disconnect event counter.
Referenced by m2m_wifi_state().
volatile uint32_t gu32MsTicks = 0 |
SysTick counter to avoid busy wait delay.
Referenced by button_press_duration(), main(), and SysTick_Handler().
|
static |
Global counter delay for timer.
Referenced by main().
|
static |
Referenced by main().
wifi_status_t gWifiState = WifiStateInit |
WiFi status variable.
Referenced by m2m_wifi_socket_handler(), m2m_wifi_state(), and main().
|
static |
Message format declarations.
|
static |
|
static |
|
static |
Referenced by main().
|
static |
PubNub global variables.
Referenced by main().
|
static |
Referenced by main().
|
static |
Android app: RX and TX socket descriptors.
Referenced by m2m_wifi_socket_handler(), and setup_android_sockets().
|
static |
Referenced by main(), and setup_android_sockets().