5.2.1 Execution
main.c - Initialize Growl and send a notification message.
- Code summary:
- Configure the Growl
parameters for your account in main.h.
/** Growl Options */ #define PROWL_API_KEY "6ce3b9ff6c29e5c5b8960b28d9e987aec5ed603a" #define NMA_API_KEY "91787604ed50a6cfc2d3f83d1ee196cbc30a3cb08a7e69a0"
- Get the MAC address and
set the device name with the MAC address.
m2m_wifi_get_mac_address(gau8MacAddr); set_dev_name_to_mac((uint8_t *)gacDeviceName, gau8MacAddr); set_dev_name_to_mac((uint8_t *)gstrM2MAPConfig.au8SSID, gau8MacAddr); m2m_wifi_set_device_name((uint8_t *)gacDeviceName, ...);
- Start Provision mode.
m2m_wifi_start_provision_mode((tstrM2MAPConfig *)&gstrM2MAPConfig, (char *)gacHttpProvDomainName, 1);
- When your mobile device
sends the configuration information, the
wifi_cb()
function will be called with theM2M_WIFI_RESP_PROVISION_INFO
message and you can connect to the AP with the given information.static void wifi_cb(uint8_t u8MsgType, void *pvMsg) { case M2M_WIFI_RESP_PROVISION_INFO: tstrM2MProvisionInfo *pstrProvInfo = (tstrM2MProvisionInfo *)pvMsg; if (pstrProvInfo->u8Status == M2M_SUCCESS) { m2m_wifi_connect((char *)pstrProvInfo->au8SSID, strlen((char *)pstrProvInfo->au8SSID), pstrProvInfo->u8SecType, pstrProvInfo->au8Password, M2M_WIFI_CH_ALL); }
- After the device is
connected to the AP, initialize the Growl key and execute the message
handler.
static void wifi_cb(uint8_t u8MsgType, void *pvMsg) { ... case M2M_WIFI_REQ_DHCP_CONF: { ... NMI_GrowlInit((uint8_t *)PROWL_API_KEY, (uint8_t *)NMA_API_KEY); growl_send_message_handler(); } ... }
- The notification message
will be sent through the function shown below.
static int growl_send_message_handler(void) { ... NMI_GrowlSendNotification(NMA_CLIENT, (uint8_t *)"Growl_Sample", (uint8_t *)"Growl_Event", (uint8_t *)"growl_test", NMA_CONNECTION_TYPE); return 0; }
- Configure the Growl
parameters for your account in main.h.
- Build the program and download it into the board.
- Start the application.
- Connect your mobile device to ATWINC15x0/ATWINC3400 AP [WINC1500_08:CA].
- Browse to the webpage (www.microchip.com) to setup AP, populate the page, then press Connect.
- The ATWINC15x0/ATWINC3400 will be connected to the AP that you entered.
- The Growl message will be sent.
This example supports sending growl notifications to the following servers:
- Prowl for iOS push notifications (https://www.prowlapp.com/)
- NMD for Android push notifications (www.notifymydevice.com/)
In order to enable the Growl application (for sending notifications), you need to set your own API key to represent your account. Create your own by:
Create an NMD account at www.notifymydevice.com/ and create an API key. Copy the
obtained key string to the NMA_API_KEY macro in the main.h as
follows:
- #define NMA_API_KEY "f8bd3e7c9c5c10183751ab010e57d8f73494b32da73292f6"
Create a Prowl account at https://www.prowlapp.com/ and
create an API key. Copy the obtained API key string to the PROWL_API_KEY macro in the
file main.h as follows:
- #define PROWL_API_KEY "117911f8a4f2935b2d84abc934be9ff77d883678"
Note: For using Growl, the root
certificate must be installed.