Microchip® Advanced Software Framework

main.c File Reference

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_tpPubNubCfg
 
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
Value:
"-- SAMW25 PubNub example --"STRING_EOL \
"-- "BOARD_NAME " --"STRING_EOL \
"-- Compiled: "__DATE__ " "__TIME__ " --"STRING_EOL
#define BOARD_NAME
Name string macro.
Definition: samd21_xplained_pro.h:65
#define STRING_EOL
Definition: main.c:102

Referenced by main().

typedef enum wifi_status wifi_status_t

Enumerator
WifiStateInit 
WifiStateWaitingProv 
WifiStateConnecting 
WifiStateConnected 
WifiStateDisConnected 

static void configure_button_led ( void  )
static
static void m2m_tcp_socket_handler ( SOCKET  sock,
uint8_t  u8Msg,
void *  pvMsg 
)
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 handle_tcpip().

Referenced by main().

static void m2m_wifi_state ( uint8_t  u8MsgType,
void *  pvMsg 
)
static

Callback to get the Wi-Fi status update.

Parameters
[in]u8MsgTypetype 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 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().

static void set_dev_name_to_mac ( uint8 name,
uint8 mac_addr 
)
static

References HEX2ASCII, and m2m_strlen().

Referenced by main().

static void socket_resolve_cb ( uint8_t *  hostName,
uint32_t  hostIp 
)
static

Callback of gethostbyname function.

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

struct usart_module cdc_uart_module
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().

uint32_t gu32publishDelay = 0
static

Global counter delay for timer.

Referenced by main().

uint32_t gu32subscribeDelay = 0
static

Referenced by main().

volatile wifi_status_t gWifiState = WifiStateInit

WiFi status variable.

Referenced by m2m_wifi_state(), and main().

pubnub_t* pPubNubCfg
static
char PubNubChannel[] = MAIN_PUBNUB_CHANNEL
static

Referenced by main().

const char PubNubPublishKey[] = MAIN_PUBNUB_PUBLISH_KEY
static

PubNub global variables.

Referenced by main().

const char PubNubSubscribeKey[] = MAIN_PUBNUB_SUBSCRIBE_KEY
static

Referenced by main().