WiFi连接的代码示例是 wm_sta_demo.c
1.测试步骤
手机设置热点,或者将路由器的热点名称改成 hihope
mm改成12345678
在UserMain函数最后面调用w800_sta_demo函数
void UserMain(void)
{
printf("\n user task \n");
#if DEMO_CONSOLE
CreateDemoTask();
#endif
#if defined(LOSCFG_KERNEL_TEST_FULL) || defined(LOSCFG_KERNEL_TEST)
LosAppInit();
#else
if (DeviceManagerStart()) {
printf("[%s] No drivers need load by hdf manager!",__func__);
}
#endif
w800_sta_demo();
}
编译烧录后查看打印信息:
说明WiFi连接成功
2.代码部分
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "lwip/ip4_addr.h"
#include "lwip/netif.h"
#include "lwip/netifapi.h"
#include "cmsis_os2.h"
#include "ohos_init.h"
#include "wifi_device.h"
#include "wifi_error_code.h"
#define DEF_TIMEOUT 15
#define ONE_SECOND 1
#define DHCP_DELAY 100
static int WiFiInit(void);
static void WaitScanResult(void);
static int WaitConnectResult(void);
static void OnWifiScanStateChangedHandler(int state, int size);
static void OnWifiConnectionChangedHandler(int state, WifiLinkedInfo *info);
static void OnHotspotStaJoinHandler(StationInfo *info);
static void OnHotspotStateChangedHandler(int state);
static void OnHotspotStaLeaveHandler(StationInfo *info);
static void PrintLinkedInfo(WifiLinkedInfo* info);
static int g_staScanSuccess = 0;
static int g_connectSuccess = 0;
s