# 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:
- StartWifi : Initial Wi-Fi module
- ConnectWifi : Connect to Wi-Fi (iOS 11 and above)
- 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
- StartWifi : Initial Wi-Fi module
- GetWifiList : Request a list of nearby Wi-Fi
- OnGetWifiList : Get to Wi-Fi list data event
- ConnectWifi : connect Wi-Fi
- OnWifiConnected : Event callback for Wi-Fi on a connection
iOS
- StartWifi : Initial Wi-Fi module
- 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)
- OnGetWifiList : Get to Wi-Fi list data event
- Set WifiList : Set information about the AP in the Wi-Fi list to assist users to connect
- 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.
Using a series of mDNS APIs such as wx.startLocalServiceDiscovery , you can obtain the IP of devices within the local network that provide mDNS services.Then pass through wx.request / wx.connectSocket and pass in the format
${IP}: ${PORT} / ${PATH}for local HTTP / WebSocket communication.For detailed documentation refer to " Local Area Network Communications ."Developers can communicate TCP or UDP with a device using TCPSocket.connect or [UDPSocket.connect]] using]((UDPSocket.connect)) depending on the device's circumstances, and knowing the ip address and port to communicate with the device.For detailed documentation refer to " TCP Communication " and " UDP Communication ".
# 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.