MediaTek LinkIt™ Development
Platform for RTOS Wi-Fi Developer's
Guide
© 2015 - 2017 MediaTek Inc.
Page 12 of 36
This document contains information that is proprietary to MediaTek Inc. (“MediaTek”) and/or its licensor(s).
Any unauthorized use, reproduction or disclosure of this document in whole or in part is strictly prohibited.
/* Register event handler */
uint8_t status = 0;
int user_event_callback(wifi_event_t event_id, unsigned char *payload,
unsigned int len) /* The handler is triggered when the device connects to
an AP router*/
{
int handled = 0;
switch (event_id) {
case WIFI_EVENT_IOT_CONNECTED:
handled = 1;
if ((len == WIFI_MAC_ADDRESS_LENGTH) && (payload)) {
printf("[User Event Callback Sample]: LinkUp! CONNECTED MAC
= %02x:%02x:%02x:%02x:%02x:%02x\n",
payload[0],payload[1],payload[2],
payload[3],payload[4],payload[5]);
} else {
printf("[User Event Callback Sample]: LinkUp!\n");
}
break;
case WIFI_EVENT_IOT_SCAN_COMPLETE:
handled = 1;
printf("[User Event Callback Sample]: Scan Done!\n");
break;
case WIFI_EVENT_IOT_DISCONNECTED:
handled = 1;
if ((len == WIFI_MAC_ADDRESS_LENGTH) && (payload)) {
printf("[User Event Callback Sample]: Disconnect! DISCONNECTED
MAC
= %02x:%02x:%02x:%02x:%02x:%02x\n",
payload[0],payload[1],payload[2],
payload[3],payload[4],payload[5]);
} else {
printf("[User Event Callback Sample]: Disconnect!\n");
}
break;
case WIFI_EVENT_IOT_PORT_SECURE:
handled = 1;
if ((len == WIFI_MAC_ADDRESS_LENGTH) && (payload)) {
printf("[User Event Callback Sample]: Port Secure! CONNECTED
MAC
= %02x:%02x:%02x:%02x:%02x:%02x\n",
payload[0],payload[1],payload[2],
payload[3],payload[4],payload[5]);
} else {
printf("[User Event Callback Sample]: Port Secure! \n");
}
break;
default:
printf("[User Event Callback Sample]: Unknown event(%d)\n",
event_id);
break;
}
status = wifi_connection_register_event_handler(WIFI_EVENT_IOT_CONNECTED,
(wifi_event_handler_t) user_event_callback);
status =
wifi_connection_register_event_handler(WIFI_EVENT_IOT_SCAN_COMPLETE,
(wifi_event_handler_t) user_event_callback);