Microchip® Advanced Software Framework

iot_temperature_demo/demo.c File Reference

IoT Temperature Sensor Demo.

Copyright (c) 2016-2018 Microchip Technology Inc. and its subsidiaries.

#include <string.h>
#include <ctype.h>
#include <stdio.h>
#include "asf.h"
#include "demo.h"
#include "driver/include/m2m_wifi.h"
#include "socket/include/socket.h"
#include "conf_winc.h"

Data Structures

struct  s_msg_temp_keepalive
 
struct  s_msg_temp_report
 
struct  s_msg_user_input
 Message format definitions. More...
 

Macros

#define TEST_BUFFER_SIZE   1460
 Receive buffer definition. More...
 

Typedefs

typedef struct s_msg_temp_keepalive t_msg_temp_keepalive
 
typedef struct s_msg_temp_report t_msg_temp_report
 
typedef struct s_msg_user_input t_msg_user_input
 Message format definitions. More...
 

Functions

static int32_t button_press_duration (bool current_button_state)
 Get duration of the button pressed. More...
 
void demo_start (void)
 Demo main function. More...
 
static void demo_wifi_socket_handler (SOCKET sock, uint8 u8Msg, void *pvMsg)
 Callback to get the Data from socket. More...
 
static void demo_wifi_state (uint8 u8MsgType, void *pvMsg)
 Callback to get the WiFi status update. More...
 
static void parse_user_input (char *user_input)
 Parse user input data. More...
 
static void print_provisioning_details (void)
 Print provisioning information. More...
 

Variables

tstrM2MAPConfig ap_config
 Configure and enable access point mode with provisioning page. More...
 
static uint32_t delay = 0
 Global counter delay for timer. More...
 
char gacHttpProvDomainName [] = DEMO_WLAN_AP_DOMAIN_NAME
 
uint8 gau8HttpProvServerIP [] = DEMO_WLAN_AP_IP_ADDRESS
 
static uint8 gau8SocketTestBuffer [TEST_BUFFER_SIZE]
 
uint32_t ms_ticks
 SysTick counter for non busy wait delay. More...
 
static t_msg_temp_keepalive msg_temp_keepalive
 Message format declarations. More...
 
static t_msg_temp_report msg_temp_report
 
char provision_pwd [30]
 
char provision_ssid [70]
 
static SOCKET rx_socket = -1
 RX and TX socket descriptors. More...
 
static uint32_t toggle_led_ms = 0
 Global counters for LED toggling. More...
 
static SOCKET tx_socket = -1
 
char user_credentials [108]
 
static t_msg_user_input user_data
 
static volatile uint8 wifi_connected = 0
 WiFi status variable. More...
 
static uint8 wifi_provisioned = 1
 

#define TEST_BUFFER_SIZE   1460

Receive buffer definition.

Referenced by demo_wifi_socket_handler().

Message format definitions.

static int32_t button_press_duration ( bool  current_button_state)
static

Get duration of the button pressed.

Returns
-1 if the button has not been released.

References ms_ticks.

Referenced by demo_start().

void demo_start ( void  )

Demo main function.

Referenced by main().

static void demo_wifi_socket_handler ( SOCKET  sock,
uint8  u8Msg,
void *  pvMsg 
)
static

Callback to get the Data from socket.

Parameters
[in]socksocket handler.
[in]u8Msgsocket event type. Possible values are:
  • SOCKET_MSG_BIND
  • SOCKET_MSG_LISTEN
  • SOCKET_MSG_ACCEPT
  • SOCKET_MSG_CONNECT
  • SOCKET_MSG_RECV
  • SOCKET_MSG_SEND
  • SOCKET_MSG_SENDTO
  • SOCKET_MSG_RECVFROM
[in]pvMsgis a pointer to message structure. Existing types are:

References delay, DEMO_PRODUCT_NAME, gau8SocketTestBuffer, s_msg_temp_report::id0, s_msg_temp_report::id1, ioport_set_pin_level(), s_msg_temp_report::led, s_msg_temp_report::name, port_pin_set_output_level(), tstrSocketRecvMsg::pu8Buffer, recvfrom(), rx_socket, tstrSocketRecvMsg::s16BufferSize, SOCK_ERR_TIMEOUT, SOCKET_MSG_BIND, SOCKET_MSG_RECVFROM, tstrSocketBindMsg::status, and TEST_BUFFER_SIZE.

Referenced by demo_start().

static void demo_wifi_state ( uint8  u8MsgType,
void *  pvMsg 
)
static

Callback to get the WiFi status update.

Parameters
[in]u8MsgTypetype of WiFi 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 tstrM2MConnInfo::acSSID, tstrM2MProvisionInfo::au8Password, tstrM2MProvisionInfo::au8SSID, s_msg_user_input::channel, gacHttpProvDomainName, ioport_set_pin_level(), 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_get_connection_info(), M2M_WIFI_REQ_DHCP_CONF, m2m_wifi_request_dhcp_client(), M2M_WIFI_RESP_CON_STATE_CHANGED, M2M_WIFI_RESP_CONN_INFO, M2M_WIFI_RESP_DEFAULT_CONNECT, M2M_WIFI_RESP_PROVISION_INFO, M2M_WIFI_SEC_OPEN, m2m_wifi_start_provision_mode(), s_msg_user_input::password, port_pin_set_output_level(), print_provisioning_details(), printf, provision_pwd, provision_ssid, tstrM2MDefaultConnResp::s8ErrorCode, s_msg_user_input::security, s_msg_user_input::SSID, strncpy(), tstrM2mWifiStateChanged::u8CurrState, tstrM2MProvisionInfo::u8SecType, tstrM2MProvisionInfo::u8Status, wifi_connected, and wifi_provisioned.

Referenced by demo_start().

static void parse_user_input ( char *  user_input)
static
static void print_provisioning_details ( void  )
static

Print provisioning information.

References DEMO_WLAN_AP_NAME, and printf.

Referenced by demo_start(), and demo_wifi_state().

tstrM2MAPConfig ap_config
Initial value:
= {
}
#define DEMO_WLAN_AP_NAME
Access point configuration for provisioning.
Definition: iot_cloud_demo/demo.h:42
#define DEMO_WLAN_AP_MODE
Definition: iot_cloud_demo/demo.h:48
#define DEMO_WLAN_AP_WEP_KEY
Definition: iot_cloud_demo/demo.h:46
#define DEMO_WLAN_AP_IP_ADDRESS
Definition: iot_cloud_demo/demo.h:50
#define DEMO_WLAN_AP_CHANNEL
Definition: iot_cloud_demo/demo.h:43
#define DEMO_WLAN_AP_WEP_SIZE
Definition: iot_cloud_demo/demo.h:45
#define DEMO_WLAN_AP_WEP_INDEX
Definition: iot_cloud_demo/demo.h:44
#define DEMO_WLAN_AP_SECURITY
Definition: iot_cloud_demo/demo.h:47

Configure and enable access point mode with provisioning page.

uint32_t delay = 0
static
char gacHttpProvDomainName[] = DEMO_WLAN_AP_DOMAIN_NAME
uint8 gau8HttpProvServerIP[] = DEMO_WLAN_AP_IP_ADDRESS
uint8 gau8SocketTestBuffer[TEST_BUFFER_SIZE]
static
uint32_t ms_ticks

SysTick counter for non busy wait delay.

SysTick counter for non busy wait delay.

Referenced by button_press_duration(), demo_start(), getTimeInMillis(), m2m_wifi_socket_handler(), reset_start_time(), run_udp_client(), and SysTick_Handler().

t_msg_temp_keepalive msg_temp_keepalive
static
Initial value:
=
{
.id0 = 0,
.id1 = 1,
.type = 2,
}
#define DEMO_PRODUCT_NAME
Sensor name.
Definition: iot_temperature_demo/demo.h:48

Message format declarations.

t_msg_temp_report msg_temp_report
static
Initial value:
=
{
.id0 = 0,
.id1 = 2,
.led = 0,
.temp = 0,
}
#define DEMO_PRODUCT_NAME
Sensor name.
Definition: iot_temperature_demo/demo.h:48
char provision_pwd[30]

Referenced by demo_wifi_state(), and m2m_wifi_state().

char provision_ssid[70]

Referenced by demo_wifi_state(), and m2m_wifi_state().

SOCKET rx_socket = -1
static

RX and TX socket descriptors.

Referenced by demo_start(), and demo_wifi_socket_handler().

uint32_t toggle_led_ms = 0
static

Global counters for LED toggling.

Referenced by demo_start().

SOCKET tx_socket = -1
static

Referenced by demo_start().

char user_credentials[108]

Referenced by demo_start().

t_msg_user_input user_data
static
volatile uint8 wifi_connected = 0
static

WiFi status variable.

Referenced by demo_start(), and demo_wifi_state().

uint8 wifi_provisioned = 1
static

Referenced by demo_start(), and demo_wifi_state().