一、WIFI AP热点
1.1AP热点API介绍
wifi_ hotspot.h接口简介:这个wifi_ hotspot.h中包含声明AP热点相关接口函数。
1.2AP热点创建代码
打开“"D1 iot _wifi ap"工程的wifi ap.c文件,可在代码中查看实现创建Wif热点的代码
g_ wifiEventHandler .0nHotspotStaJoin = OnHotspotStaJoinHandler;
g_ wifiEventHandler .0nHotspotStaLleave = OnHotspotStaleaveHandler;
g_ wifiEventHandler .0nHotspotStateChanged = OnHotspotStateChangedHandler;
error = RegisterWifiEvent (&g_ wifiEventHandler);
if (error != WIFI_ SUCCESS)
{
printf(" RegisterWifiEvent failed, error = %d. \r\n" ,error);
return -1;
}
HotspotConfig config = {0};
strcpy(config.ssid, AP_ SSID);
strcpy( config . preSharedKey, AP_ PSK);
config. securityType = WIFI_ SEC_ TYPE_ PSK;
config. band = HOTSPOT_ BAND_ TYPE_ _2G;
config. channelNum = 7;
error = SetHotspotConfig(&config);
if (error != WIFI_ SUCCESS)
{
printf("SetHotspotConfig failed, error = %d. \r\n",error);
return -1;
}
error = EnableHotspot();
if (error != WIFI_ SUCCESS)
{
printf(" EnableHotspot failed, error = %d.\r\n", error);
return -1;
}
if (IsHotspotActive() == WIFI_ HOTSPOT_ NOT _ACTIVE)
{
printf("Wifi station is not actived. \r\n");
return -1;
}
g_ apEnableSuccess = 0;
WaitAPResult();