Wi-Fi station/P2P/AP management| including enabling| disabling| scanning| connecting| and information obtaining operations | WiFi STA/P2P/AP模式的管理:开关、扫描、连接、WiFi信息
| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 4 年前 | ||
| 22 小时前 | ||
| 2 个月前 | ||
| 2 年前 | ||
| 4 年前 | ||
| 6 个月前 | ||
| 3 年前 | ||
| 3 年前 |
WLAN组件
简介
无线局域网(Wireless Local Area Networks,WLAN)是一种利用无线电波、红外信号或其他无线传输技术实现设备间数据通信的局域网络。它摆脱了物理线缆的束缚,让用户能在办公场所或公共场所通过移动终端自由接入网络。
WLAN组件子系统为用户提供基础的无线网络连接功能、点对点(P2P)通信能力以及网络状态通知服务,使各类应用能够通过WLAN技术实现设备间的无缝互联。
系统架构

目录结构
/foundation/communication/wifi
├── figures # 图片资源目录
├── interfaces # 接口适配目录
│ ├── innerkits # 内部接口适配目录
│ └── kits # WLAN组件接口的适配代码存放目录
├── services # service适配目录
│ └── wifi_standard # service实现目录
├── tests # 测试代码目录
│ └── wifi_standard # service实现模块测试代码
└── utils # 实用函数目录
├── inc # 实用函数头文件目录
└── src # 实用函数实现目录
Description
Interface Description
The WLAN basic functionalities are provided by the @ohos.wifi class, with its interface (JS interface) descriptions as follows.
Table 1 Main Interfaces (JS Interfaces) for WLAN Basic Functionalities
Usage InstructionsBefore using the WLAN JS APIs, you need to import the interface class @ohos.wifi.
import wf from '@ohos.wifi'; // 导入js接口类
(1) Checking WLAN Status
-
Call the
isWifiActive()interface to check if WLAN is enabled.var isWifiActive = wf.isWifiActive(); // Returns `true` if WLAN is on, otherwise `false`
(2) Initiating a Scan and Retrieving Results
-
Call the
scan()interface to initiate a scan. -
Call the
getScanInfoList()interface to retrieve scan results.// Call the WLAN scan interface var isScanSuccess = wf.scan(); // Returns `true` // Add a delay // Retrieve scan results wf.getScanInfos((err, result) => { if (err) { console.error("get scan info error"); return; } var len = Object.keys(result).length; console.log("get scan info number: " + len); for (var i = 0; i < len; ++i) { console.info("ssid: " + result[i].ssid); console.info("bssid: " + result[i].bssid); console.info("securityType: " + result[i].securityType); console.info("rssi: " + result[i].rssi); console.info("band: " + result[i].band); console.info("frequency: " + result[i].frequency); console.info("timestamp: " + result[i].timestamp); } });
(3) Connecting to WLAN
-
Call
addDeviceConfigto add a configuration, then connect to WLAN using the returned configuration ID, or callconnectToDeviceto connect directly with the configuration.// WLAN configuration details var config = { "ssid":"test_wifi", "bssid":"", "preSharedKey":"12345678", "isHiddenSsid":false, "securityType":3, } Method 1: // Add configuration wf.addDeviceConfig(config, (err, result) => { if (err) { console.error("add device config error"); return; } console.info("config id: " + result); // Connect to WLAN using the configuration ID wf.connectToNetwork(result); }); Method 2: // Connect to WLAN directly using the configuration wf.connectToDevice(config);
Related Repositories
Distributed Soft Bus Subsystem
communication_wifi
项目介绍
Wi-Fi station/P2P/AP management| including enabling| disabling| scanning| connecting| and information obtaining operations | WiFi STA/P2P/AP模式的管理:开关、扫描、连接、WiFi信息
定制我的领域