跳转至

WIFI-AP模式

项目编写

  1. applications/genkipi/app 下新建 wifi_ap 文件夹
  2. wifi_ap 下新建 main.c 文件
  3. wifi_ap 下新建 BUILD.gn文件

代码部分

main.c 文件内容

#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "ohos_init.h"
#include "cmsis_os2.h"

#include "genki_wifi_ap.h"

#define WIFI_SSID "hello_itcast"
#define WIFI_PASSWORD "12345678"


static void wifi_task(void) {
    wifi_ap_start(WIFI_SSID, WIFI_PASSWORD);
}

static void start(void)
{
    osThreadAttr_t attr;

    attr.name = "wifi_ap";
    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 AP task Failed!\r\n");
    }
}

APP_FEATURE_INIT(start);

项目Build.gn

wifi_ap 目录下 BUILD.gn 内容为

static_library("wifi_ap") {
    sources = [
        "main.c"
    ]

    include_dirs = [
        "//utils/native/lite/include",
        "//base/iot_hardware/peripheral/interfaces/kits",
        "//device/itcast/genkipi/interfaces/kits"
    ]
}

外部Build.gn

wifi_ap文件夹上一级目录下BUILD.gn内容为

import("//build/lite/config/component/lite_component.gni")

lite_component("app") {
    features = [
        "wifi_ap"
    ]
}