# Wireless local area network (Wi-Fi)

In Weixin Mini Program support to search the surrounding Wi-Fi devices, and can be directed to the specified device, pass in the password to initiate a connection.

This family of interfaces is a system-native capability, and to view the capabilities and configurations of WeChat Wi-Fi connection, refer to the documentation .

# 1. Connect specified Wi-Fi devices

If you know the Wi-Fi device name and password and confirm that the device is nearby, you can directly connect to the specified Wi-Fi in Weixin Mini Program.

The interface call sequence is as follows:

  1. StartWifi : Initial Wi-Fi module
  2. ConnectWifi : Connect to Wi-Fi (iOS 11 and above)
  3. OnWifiConnected : Event callback for Wi-Fi on a connection

# 2. Connect the surrounding Wi-Fi devices

Weixin Mini Program can scan nearby Wi-Fi devices to allow users to select a device to connect to.

Due to system limitations, the timing of interface call varies from platform to platform:

Android

  1. StartWifi : Initial Wi-Fi module
  2. GetWifiList : Request a list of nearby Wi-Fi
  3. OnGetWifiList : Get to Wi-Fi list data event
  4. ConnectWifi : connect Wi-Fi
  5. OnWifiConnected : Event callback for Wi-Fi on a connection

iOS

  1. StartWifi : Initial Wi-Fi module
  2. GetWifiList : Request a list of nearby Wi-Fi.This interface will jump to the WeChat settings page in the connection settings, you need to guide the user into the "wireless local network" settings page, manually connect the device.(iOS 11.0 and 11.1 versions failed due to system issues)
  3. OnGetWifiList : Get to Wi-Fi list data event
  4. Set WifiList : Set information about the AP in the Wi-Fi list to assist users to connect
  5. OnWifiConnected : Event callback for Wi-Fi on a connection

# 3. Device communication over Wi-Fi networks

Through wx.getConnectedWifi you can obtain the current system connection Wi-Fi information. After confirming that the current connection is device Wi-Fi (the phone and the device are on the same local area network), you can communicate with the device using the relevant interface.

# 4. Note

  • Android system version 6.0 or above, when the positioning switch is not turned on, it will cause the device to not get the surrounding Wi-Fi information normally.
  • Wi-Fi connection is temporarily unavailable wx.canIUse interface judgment.