【鸿蒙HarmonyOS HiSpark IPC DIY Camera】hi3518-wifi的配置与使用
https://harmonyos.51cto.com/#zz
主 要是修改和3518相关的wpa_supplicant.conf hostapd.conf 两个文件,对wifi相关的ssid、passwd等进行配置
【编译生成wifi可执行文件】 请参考以下示例代码编译可执行程序wpa_supplicant:(SDK里面有这些代码,不做修改)
路径 ./applications/sample/camera/communication/wpa_supplicant/src/wpa_sample.c
- #include <dlfcn.h>
- #include <pthread.h>
- #include <stdio.h>
- #include <string.h>
-
- pthread_t g_wpaThread;
-
- char* g_wpaArg[20] = {0};
- int g_wpaArgc = 0;
-
- static void* ThreadMain()
- {
- printf("[WpaSample]init wpa_supplicant. ");
-
- void *handleLibWpa = dlopen("/usr/lib/libwpa.so", RTLD_NOW | RTLD_LOCAL);
- if (handleLibWpa == NULL) {
- printf("[WpaSample]dlopen libwpa failed. ");
- return NULL;
- }
- int (*func)(int, char **) = NULL;
- func = dlsym(handleLibWpa, "wpa_main");
- if (func == NULL) {
- dlclose(handleLibWpa);
- printf("[WpaSample]dlsym wpa_main failed. ");
- return NULL;
- }
- int ret = func(g_wpaArgc, g_wpaArg);
- printf("[WpaSample]run wpa_main failed, ret:%d. ", ret);
- for (int i = 0; i < g_wpaArgc; i++) {
- printf("[WpaSample]arg %d:%s. ", i, g_wpaArg[i]);
- }
- if (dlclose(handleLibWpa) != 0) {
- printf("[WpaSample]dlclose libwpa failed. ");
- return NULL;
- }
- return NULL;
-
- }
-
- int main(int argc, char *argv[])
- {
- g_wpaArgc = argc;
- for (int i = 0; i < g_wpaArgc; i++) {
- g_wpaArg[i] = argv[i];
- }
-
- int ret = pthread_create(&g_wpaThread, NULL, ThreadMain, NULL);
- if (ret != 0) {
- printf("[WpaSample]create thread failed error:%s. ", strerror(ret));
- return 1;
- }
- pthread_join(g_wpaThread, NULL);
- return 0;
-
- }
路径 ./applications/sample/camera/communication目录下面的BUILD.gn文件
- import("//build/lite/config/component/lite_component.gni")
- lite_component("sample") {
- features = [
- "wpa_supplicant:wpa_sample",
- ]
- }
路径 ./applications/sample/camera/communication/wpa_supplicant目录下面的BUILD.gn文件
- import("//build/lite/config/component/lite_component.gni")
- sample_sources = [
- "src/wpa_sample.c",
- ]
- config_file = [
- "config/wpa_supplicant.conf"
- ]
- executable("wpa_sample_exe") {
- output_name = "wpa_supplicant"
- sources = sample_sources
- }
- group("wpa_sample") {
- deps = [
- ":wpa_sample_exe",
- ]
- }
- copy("config") {
- sources = config_file
- outputs = [
- "$root_out_dir/etc/wpa_supplicant.conf"
- ]
- }
路径 ./build/lite/product/ipcamera_hi3518ev300.json
【修改station模式的配置】 将以下配置写到配置文件wpa_supplicant.conf
- country=GB
- ctrl_interface=udp
- network={
- #要连接的SSID
- ssid="example"
- #如果不需要加密就写key_mgmt=NONE
- #key_mgmt=NONE
- #如果需要加密就写这行密码
- psk="12345678"
- }
【修改ap模式的配置】 将以下配置写到配置文件hostapd.conf
- interface=wlan0
- driver=hdf wifi
- ctrl_interface=udp
- ssid=testap
- hw_mode=g
- channel=1
- ignore_broadcast_ssid=0
- #下面是wpa2-psk类型加密的配置
- #如果不需要加密可以删除
- auth_algs=1
- wpa=2
- wpa_passphrase=12345678
- rsn_pairwise=CCMP
【使用方法】
将wpa_supplicant、wpa_supplicant.conf、hostapd.conf拷贝到单板中(sdcard目录)
启动sta的命令:
- ./sdcard/wpa_supplicant -i wlan0 -c /sdcard/wpa_supplicant.conf
启动ap的命令:
- ./sdcard/hostapd -i wlan0 /sdcard/hostapd.conf
【WIFI设备检测】 进入OHOS界面后,输入ifconfig,检查wlan0网口是否加载正常,加载成功标识如下:
OHOS # ifconfig
wlan0 ip:0.0.0.0 netmask:0.0.0.0 gateway:0.0.0.0
HWaddr 0a:11:31:aa:7e:1a MTU:1500 Stop Link UP
lo ip:127.0.0.1 netmask:255.0.0.0 gateway:127.0.0.1
ip6: ::1/64
HWaddr 00 MTU:16436 Running Link UP
https://harmonyos.51cto.com/#zz
相关文章
- Fireasy3 揭秘 -- 依赖注入与服务发现
- Fireasy3 揭秘 -- 自动服务部署
- 问题深究01——为什么不要在foreach循环里进行元素的remove/add操作?
- 乘风破浪,遇见最佳跨平台跨终端框架.Net Core/.Net生态 - 深入OpenAI与马斯克、微软的秘密,通过API轻松接入ChatGPT
- Nginx-初识篇
- 从零开始实现lmax-Disruptor队列(五)Disruptor DSL风格API原理解析
- 【经典算法】第七回:堆排序
- 响应式编程WebFlux-SpringBoot(5)
- 记录用C#写折半查找算法实现
- 【Avalonia】【跨平台】关于Prism项目模块化在Linux下路径问题
- 《软技能-代码之外的生存指南》读书笔记
- C# 实现你自己的异步方法
- 07-Feign远程调用
- 分布式事务TCC
- Spring Cloud体系中Eureka闭源,作用Consul做注册中心到底爽不爽?
- 高企必备项目—SSM框架项目CRM客户管理系统
- 多态详解
- Static、Final关键字详解
- 代理设计模式还不会?2分钟搞定
- instanceof和类型转换