# Wireless LAN (Wi-Fi)
In the Mini Program to support the search for the surrounding Wi-Fi Device, and at the same time, the connection can be initiated with a password for the specified device.
This series of interfaces is system native capability. If you want to seeWeChat Link Wi-FiAbility and configuration jump Mini Program, please refer tofile。
# 1. Connection Specified Wi-Fi equipment
If you know Wi-Fi Device name and password, and confirm that the device is nearby, you can specify the connection directly in the Mini Program Wi-Fi。
The interface call timing is:
- startWifi: to initialize Wi-Fi Modular
- connectWifi: Connect Wi-Fi(iOS need 11 The above version is supported)
- onWifiConnected: Connect on Wi-Fi The event callback
# 2. Connecting the perimeter Wi-Fi equipment
The Mini Program can be accessed by scanning a nearby Wi-Fi Device, allowing the user to select a device to connect.
Due to system limitations, the timing of interface calls varies on different platforms:
Android
- startWifi: to initialize Wi-Fi Modular
- getWifiList: Request to get around Wi-Fi list
- onGetWifiList: Get to the Wi-Fi List Data Events
- connectWifi: Connect Wi-Fi
- onWifiConnected: Connect on Wi-Fi The event callback
iOS
- startWifi: to initialize Wi-Fi Modular
- getWifiList: Request to get around Wi-Fi List. This interface will jump to the system settings in the WeChat settings page, need to guide the user intoWireless LANSettings page, manually connect the device.(iOS 11.0 and 11.1 Version failed due to system problems
- onGetWifiList: Get to the Wi-Fi List Data Events
- setWifiList: Set up Wi-Fi list in AP To assist the user to connect
- onWifiConnected: Connect on Wi-Fi The event callback
# 3. Wi-Fi Device communication under the network
adopt wx.getConnectedWifi Can get the current system connection Wi-Fi Information, after confirming that the current connection is the device Wi-Fi Then (the phone and the device are in the same LAN), you can use the relevant interface to communicate with the device.
use wx.startLocalServiceDiscovery Wait for a series mDNS API , can be obtained within the LAN to provide mDNS Service equipment IP And then through the wx.request / wx.connectSocket And pass in the format of
${IP}:${PORT}/${PATH}
of url Parameters, you can perform local HTTP / WebSocket Correspondence. Detailed Documentation ReferenceLAN communication。The developer, depending on the circumstances of the specific device, is aware of the ip address and port Afterwards, use the TCPSocket.connect or UDPSocket.connect Can be connected to the device. TCP or UDP Correspondence. Detailed Documentation ReferenceTCP Signal communicationandUDP Signal communication。
# 4. Note
- Android system 6.0 The above version, when the positioning switch is not turned on, the device will not be able to access the surrounding Wi-Fi Information.
- Wi-Fi The associated interface is temporarily unavailable wx.canIUse Interface determination.