WIFI-STA模式
项目编写¶
- 在
applications/genkipi/app
下新建wifi_sta
文件夹 - 在
wifi_sta
下新建main.c
文件 - 在
wifi_sta
下新建BUILD.gn
文件
代码部分¶
main.c
文件内容
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "ohos_init.h"
#include "cmsis_os2.h"
#include "genki_wifi_sta.h"
#define WIFI_SSID "itheima"
#define WIFI_PASSWORD "12345678"
#define HOSTNAME "itcast"
static void wifi_task(void) {
wifi_sta_connect(WIFI_SSID, WIFI_PASSWORD, HOSTNAME);
}
static void start(void)
{
osThreadAttr_t attr;
attr.name = "wifi_sta";
attr.attr_bits = 0U;
attr.cb_mem = NULL;
attr.cb_size = 0U;
attr.stack_mem = NULL;
attr.stack_size = 1024 * 4;
attr.priority = 25;
if (osThreadNew((osThreadFunc_t)wifi_task, NULL, &attr) == NULL)
{
printf("Create WIFI STA task Failed!\r\n");
}
}
APP_FEATURE_INIT(start);
项目Build.gn¶
wifi_sta
目录下 BUILD.gn
内容为
static_library("wifi_sta") {
sources = [
"main.c"
]
include_dirs = [
"//utils/native/lite/include",
"//base/iot_hardware/peripheral/interfaces/kits",
"//device/itcast/genkipi/interfaces/kits"
]
}
外部Build.gn¶
wifi_sta
文件夹上一级目录下BUILD.gn
内容为
import("//build/lite/config/component/lite_component.gni")
lite_component("app") {
features = [
"wifi_sta"
]
}