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 |
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, 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 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, printf, 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(), buf, close(), configure_button_led(), configure_console(), configure_light_sensor(), delay_init(), gu32MsTicks, gu32publishDelay, gu32subscribeDelay, gWifiState, pubnub::last_result, 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(), mac_addr, 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(), printf, 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, len, 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(), 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
|
static |
UART module for debug.
volatile uint32_t gu32MsTicks = 0 |
SysTick counter to avoid busy wait delay.
|
static |
Global counter delay for timer.
Referenced by main().
|
static |
Referenced by main().
volatile wifi_status_t gWifiState = WifiStateInit |
WiFi status variable.
|
static |
|
static |
Referenced by main().
|
static |
PubNub global variables.
Referenced by main().
|
static |
Referenced by main().