PubNub Example.
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 "main.h"
#include "PubNub.h"
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 |
Typedefs | |
typedef enum wifi_status | wifi_status_t |
Enumerations | |
enum | wifi_status { WifiStateInit, WifiStateWaitingProv, WifiStateConnecting, WifiStateConnected, WifiStateDisConnected } |
Functions | |
static void | configure_button_led (void) |
static void | configure_console (void) |
Configure UART console. More... | |
static void | configure_light_sensor (void) |
static void | m2m_tcp_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 | 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... | |
static struct usart_module | cdc_uart_module |
UART module for debug. 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 |
volatile wifi_status_t | gWifiState = WifiStateInit |
WiFi status variable. More... | |
static pubnub_t * | pPubNubCfg |
static char | PubNubChannel [] = MAIN_PUBNUB_CHANNEL |
static const char | PubNubPublishKey [] = MAIN_PUBNUB_PUBLISH_KEY |
PubNub global variables. More... | |
static const char | PubNubSubscribeKey [] = MAIN_PUBNUB_SUBSCRIBE_KEY |
#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().
typedef enum wifi_status wifi_status_t |
enum wifi_status |
|
static |
References port_config::direction, LED0_INACTIVE, LED0_PIN, 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, 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().
|
static |
References ADC_CLOCK_PRESCALER_DIV512, adc_enable(), ADC_GAIN_FACTOR_DIV2, adc_get_config_defaults(), adc_init(), adc_instance, ADC_POSITIVE_INPUT_PIN0, ADC_REFERENCE_INTVCC1, ADC_RESOLUTION_12BIT, adc_config::clock_prescaler, adc_config::clock_source, adc_config::gain_factor, GCLK_GENERATOR_0, adc_config::positive_input, adc_config::reference, and adc_config::resolution.
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 handle_tcpip().
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 gWifiState, M2M_WIFI_CH_ALL, m2m_wifi_connect(), M2M_WIFI_CONNECTED, M2M_WIFI_DISCONNECTED, M2M_WIFI_REQ_DHCP_CONF, M2M_WIFI_RESP_CON_STATE_CHANGED, MAIN_WLAN_AUTH, MAIN_WLAN_PSK, MAIN_WLAN_SSID, tstrM2mWifiStateChanged::u8CurrState, WifiStateConnected, and WifiStateDisConnected.
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(), at30tse_init(), at30tse_read_temperature(), close(), configure_button_led(), configure_console(), configure_light_sensor(), delay_init(), gu32MsTicks, gu32publishDelay, gu32subscribeDelay, gWifiState, pubnub::last_result, LED0_ACTIVE, LED0_INACTIVE, LED0_PIN, M2M_SUCCESS, m2m_tcp_socket_handler(), M2M_WIFI_CH_ALL, m2m_wifi_connect(), m2m_wifi_get_mac_address(), m2m_wifi_get_otp_mac_address(), m2m_wifi_handle_events(), m2m_wifi_init(), m2m_wifi_state(), MAIN_PUBNUB_PUBLISH_INTERVAL, MAIN_PUBNUB_SUBSCRIBE_INTERVAL, MAIN_WLAN_AUTH, MAIN_WLAN_PSK, MAIN_WLAN_SSID, nm_bsp_init(), NULL, PBTT_NONE, PBTT_PUBLISH, tstrWifiInitParam::pfAppWifiCb, PNR_IO_ERROR, PNR_OK, port_pin_get_output_level(), port_pin_set_output_level(), PS_IDLE, pubnub_get(), pubnub_get_ctx(), pubnub_init(), pubnub_publish(), pubnub_subscribe(), PubNubChannel, PubNubPublishKey, PubNubSubscribeKey, registerSocketCallback(), set_dev_name_to_mac(), socket_resolve_cb(), socketInit(), pubnub::state, STRING_HEADER, system_cpu_clock_get_hz(), system_init(), pubnub::tcp_socket, pubnub::trans, and WifiStateConnected.
References HEX2ASCII, and m2m_strlen().
Referenced by main().
|
static |
Callback of gethostbyname function.
[in] | doamin_name | Domain name. |
[in] | server_ip | IP of server. |
References handle_dns_found(), and IPV4_BYTE.
Referenced by main().
void SysTick_Handler | ( | void | ) |
References gu32MsTicks.
struct adc_module adc_instance |
UART module for debug.
Referenced by configure_light_sensor(), and main().
|
static |
UART module for debug.
Referenced by configure_console().
volatile uint32_t gu32MsTicks = 0 |
SysTick counter to avoid busy wait delay.
Referenced by main(), and SysTick_Handler().
|
static |
Global counter delay for timer.
Referenced by main().
|
static |
Referenced by main().
volatile wifi_status_t gWifiState = WifiStateInit |
WiFi status variable.
Referenced by m2m_wifi_state(), and main().
|
static |
|
static |
Referenced by main().
|
static |
PubNub global variables.
Referenced by main().
|
static |
Referenced by main().