Interface WifiHandle

Wifi操控句柄

Description

通过 Wifi.open() 开启设备,以获得句柄对象,用于操控 Wifi。 WifiHandle 继承 IEventSource,可用on/off/once方法监听消息事件。

Hierarchy

Properties

active: boolean

此句柄对象是否有效?

Description

如果用Wifi.close()关闭了Wifi设备,而之前打开时返回的句柄对象仍被引用,则此对象的active属性将变为false。 false 表示句柄对象虽然还在,但是其对应Wifi设备已经被关闭过了。 失效的句柄,不能用来对Wifi进行操控,会抛出异常。

apConfig: null | {
    authMethod: null | AuthMethodType;
    ssid: string;
}

AP模式配置。null表示未启用AP模式。

apMac: string

AP模式的MAC地址

staConfig: null | {
    authMethod: null | AuthMethodType;
    ssid: string;
}

STA模式配置。null表示未启用STA模式。

staIp: null | IpInfo

STA模式下获取的IP地址信息

staMac: string

STA模式的MAC地址

staStarted: boolean
staStatus: WifiStatus

STA模式状态

Methods

  • 配置WIFI工作模式

    Parameters

    • sta: null | {
          authMethod?: null | AuthMethodType;
          password: string;
          ssid: string;
      }

      配置STA模式。null表示不启用STA模式

    • ap: null | {
          authMethod?: null | AuthMethodType;
          password?: string;
          ssid: string;
      }

      配置AP模式。null表示不启用AP模式

    Returns WifiHandle

  • 触发事件

    Type Parameters

    • T extends "state-change" | "ip-assigned"

    Parameters

    • type: T

      事件类型

    • Rest ...args: {
          ip-assigned: [null | string];
          state-change: [WifiStatus];
      }[T]

      事件参数

    Returns WifiHandle

  • 取消监听

    Type Parameters

    • T extends "state-change" | "ip-assigned"

    Parameters

    • type: T
    • handler: ((...args: {
          ip-assigned: [null | string];
          state-change: [WifiStatus];
      }[T]) => void)
        • (...args: {
              ip-assigned: [null | string];
              state-change: [WifiStatus];
          }[T]): void
        • Parameters

          • Rest ...args: {
                ip-assigned: [null | string];
                state-change: [WifiStatus];
            }[T]

          Returns void

    Returns WifiHandle

  • 添加监听

    Type Parameters

    • T extends "state-change" | "ip-assigned"

    Parameters

    • type: T

      Event type

    • handler: ((...args: {
          ip-assigned: [null | string];
          state-change: [WifiStatus];
      }[T]) => void)

      A callback function to process the incomming event

        • (...args: {
              ip-assigned: [null | string];
              state-change: [WifiStatus];
          }[T]): void
        • Parameters

          • Rest ...args: {
                ip-assigned: [null | string];
                state-change: [WifiStatus];
            }[T]

          Returns void

    Returns WifiHandle

  • 添加一次性监听

    Type Parameters

    • T extends "state-change" | "ip-assigned"

    Parameters

    • type: T

      Event type

    • handler: ((...args: {
          ip-assigned: [null | string];
          state-change: [WifiStatus];
      }[T]) => void)

      A callback function to process the incomming event

        • (...args: {
              ip-assigned: [null | string];
              state-change: [WifiStatus];
          }[T]): void
        • Parameters

          • Rest ...args: {
                ip-assigned: [null | string];
                state-change: [WifiStatus];
            }[T]

          Returns void

    Returns WifiHandle

  • 扫描AP

    Returns Promise<ApInfo[]>