Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program API WIFI


May 19, 2021 WeChat Mini Program Development Document


Table of contents


wx.stopWifi(Object object)

Base library 1.6.0 starts to support, and low versions need to be compatible.

Turn off the Wi-Fi module.

Parameters

Object object

Property Type The default Required Description
success function Whether The interface calls a successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)

Error

Error code The error message Description
0 Ok Normal
12000 not init The startWifi first
12001 system not support The current system does not support related capabilities
12002 password error Wi-Fi The password is wrong
12003 connection timeout The connection timed out
12004 duplicate request Connect Wi-Fi repeatedly
12005 wifi not turned on Android is special and the Wi-Fi switch is not turned on
12006 gps not turned on Android is special and the GPS positioning switch is not turned on
12007 user denied The user refuses to authorize the link Wi-Fi
12008 invalid SSID The SSID is not valid
12009 system config err The system carrier configuration refuses to connect to Wi-Fi
12010 system internal error System other errors that need to be printed in errmsg for specific error reasons
12011 weapp in background The app cannot configure Wi-Fi in the background
12013 wifi config may be expired The System Saved Wi-Fi configuration is out of date and it is recommended to try again after forgetting Wi-Fi

The sample code

wx.stopWifi({
  success (res) {
    console.log(res.errMsg)
  }
})

wx.startWifi(Object object)

Base library 1.6.0 starts to support, and low versions need to be compatible.

Initialize the Wi-Fi module.

parameter

Object object

Attributes type Defaults Required illustrate
success function no Interface call successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)

Error

Error code The error message Description
0 Ok Normal
12000 not init The startWifi first
12001 system not support The current system does not support related capabilities
12002 password error Wi-Fi The password is wrong
12003 connection timeout The connection timed out
12004 duplicate request Connect Wi-Fi repeatedly
12005 wifi not turned on Android is special and the Wi-Fi switch is not turned on
12006 gps not turned on Android is special and the GPS positioning switch is not turned on
12007 user denied The user refuses to authorize the link Wi-Fi
12008 invalid SSID The SSID is not valid
12009 system config err The system carrier configuration refuses to connect to Wi-Fi
12010 system internal error System other errors that need to be printed in errmsg for specific error reasons
12011 weapp in background The app cannot configure Wi-Fi in the background
12013 wifi config may be expired The System Saved Wi-Fi configuration is out of date and it is recommended to try again after forgetting Wi-Fi

The sample code

wx.startWifi({
  success (res) {
    console.log(res.errMsg)
  }
})

wx.setWifiList(Object object)

Base library 1.6.0 starts to support, and low versions need to be compatible.

Set up information about the AP in wifiList. Called after the onGetWifiList callback, iOS has a special interface.

Parameters

Object object

Property Type The default Required Description
wifiList Array.<Object> Is Provides a preset list of Wi-Fi information
success function Whether The interface calls a successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)

The structure of object.wifiList

Property Type The default Required Description
Ssid string Whether The SSID for Wi-Fi
BSSID string Whether BSSID for Wi-Fi
password string Whether Wi-Fi device password

Error

Error code The error message Description
0 Ok Normal
12000 not init The startWifi first
12001 system not support The current system does not support related capabilities
12002 password error Wi-Fi The password is wrong
12003 connection timeout The connection timed out
12004 duplicate request Connect Wi-Fi repeatedly
12005 wifi not turned on Android is special and the Wi-Fi switch is not turned on
12006 gps not turned on Android is special and the GPS positioning switch is not turned on
12007 user denied The user refuses to authorize the link Wi-Fi
12008 invalid SSID The SSID is not valid
12009 system config err The system carrier configuration refuses to connect to Wi-Fi
12010 system internal error System other errors that need to be printed in errmsg for specific error reasons
12011 weapp in background The app cannot configure Wi-Fi in the background
12013 wifi config may be expired The System Saved Wi-Fi configuration is out of date and it is recommended to try again after forgetting Wi-Fi

Attention

  • The interface can only be called after the onGetWifiList callback.
  • At this point, the client hangs and waits for the small program to set up Wi-Fi information, so be sure to call the interface as soon as possible, and if there is no data, pass in an empty array.
  • It is possible to receive multiple callbacks with duplicate Wi-Fi lists within a single process as the surrounding Wi-Fi list is refreshed.

The sample code

wx.onGetWifiList(function(res) {
  if (res.wifiList.length) {
    wx.setWifiList({
      wifiList: [{
        SSID: res.wifiList[0].SSID,
        BSSID: res.wifiList[0].BSSID,
        password: '123456'
      }]
    })
  } else {
    wx.setWifiList({
      wifiList: []
    })
  }
})
wx.getWifiList()


wx.onWifiConnected(function callback)

Base library 1.6.0 starts to support, and low versions need to be compatible.

Listen for Wi-Fi events on the connection

Parameters

function callback

The callback function for events connected to Wi-Fi

Parameters

Object res
Property Type Description
Wifi WifiInfo Wi-Fi information

wx.onGetWifiList(function callback)

Base library 1.6.0 starts to support, and low versions need to be compatible.

Listen to get data events to the Wi-Fi list

Parameters

function callback

Gets the callback function to the Wi-Fi list data event

Parameters

Object res
Property Type Description
wifiList Array.<WifiInfo> Wi-Fi list data

wx.offWifiConnected(function callback)

Base library 2.9.0 starts to support, and low versions need to be compatible.

Cancels listening for Wi-Fi events on the connection.

Parameters

function callback

The callback function for events connected to Wi-Fi


wx.offGetWifiList(function callback)

Base library 2.9.0 starts to support, and low versions need to be compatible.

Cancel listening to get data events to Wi-Fi lists.

Parameters

function callback

Gets the callback function to the Wi-Fi list data event


wx.getWifiList(Object object)

Base library 1.6.0 starts to support, and low versions need to be compatible.

Request a list of Wi-Fi. R eturn wifiList data in a callback registered onGetWifiList. The user authorization scope.userLocation is required before android calls can be made.

iOS will jump to the system's Wi-Fi interface, and Android won't. B oth versions of iOS 11.0 and iOS 11.1 failed due to system problems. However, it was fixed in iOS 11.2.

Parameters

Object object

Property Type The default Required Description
success function Whether The interface calls a successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)

Error

Error code The error message Description
0 Ok Normal
12000 not init The startWifi first
12001 system not support The current system does not support related capabilities
12002 password error Wi-Fi The password is wrong
12003 connection timeout The connection timed out
12004 duplicate request Connect Wi-Fi repeatedly
12005 wifi not turned on Android is special and the Wi-Fi switch is not turned on
12006 gps not turned on Android is special and the GPS positioning switch is not turned on
12007 user denied The user refuses to authorize the link Wi-Fi
12008 invalid SSID The SSID is not valid
12009 system config err The system carrier configuration refuses to connect to Wi-Fi
12010 system internal error System other errors that need to be printed in errmsg for specific error reasons
12011 weapp in background The app cannot configure Wi-Fi in the background
12013 wifi config may be expired The System Saved Wi-Fi configuration is out of date and it is recommended to try again after forgetting Wi-Fi

wx.getConnectedWifi(Object object)

Base library 1.6.0 starts to support, and low versions need to be compatible.

Gets Wi-Fi information in connection.

Parameters

Object object

Property Type The default Required Description
success function Whether The interface calls a successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)

object.success callback function

Parameters
Object res
Property Type Description
Wifi WifiInfo Wi-Fi information

Error

Error code The error message Description
0 Ok Normal
12000 not init The startWifi first
12001 system not support The current system does not support related capabilities
12002 password error Wi-Fi The password is wrong
12003 connection timeout The connection timed out
12004 duplicate request Connect Wi-Fi repeatedly
12005 wifi not turned on Android is special and the Wi-Fi switch is not turned on
12006 gps not turned on Android is special and the GPS positioning switch is not turned on
12007 user denied The user refuses to authorize the link Wi-Fi
12008 invalid SSID The SSID is not valid
12009 system config err The system carrier configuration refuses to connect to Wi-Fi
12010 system internal error System other errors that need to be printed in errmsg for specific error reasons
12011 weapp in background The app cannot configure Wi-Fi in the background
12013 wifi config may be expired The System Saved Wi-Fi configuration is out of date and it is recommended to try again after forgetting Wi-Fi

wx.connectWifi(Object object)

Base library 1.6.0 starts to support, and low versions need to be compatible.

Connect to Wi-Fi. I f Wi-Fi information is known, the interface can be used directly to connect. Only android and iOS 11 versions are supported.

Parameters

Object object

Property Type The default Required Description The lowest version
Ssid string Is Wi-Fi device SSID
BSSID string Whether Wi-Fi device BSSID
password string Is Wi-Fi device password
maunal boolean false Whether Jump to the system settings page to connect, android only 2.12.0
success function Whether The interface calls a successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)

Error

Error code The error message Description
0 Ok Normal
12000 not init The startWifi first
12001 system not support The current system does not support related capabilities
12002 password error Wi-Fi The password is wrong
12003 connection timeout The connection timed out
12004 duplicate request Connect Wi-Fi repeatedly
12005 wifi not turned on Android is special and the Wi-Fi switch is not turned on
12006 gps not turned on Android is special and the GPS positioning switch is not turned on
12007 user denied The user refuses to authorize the link Wi-Fi
12008 invalid SSID The SSID is not valid
12009 system config err The system carrier configuration refuses to connect to Wi-Fi
12010 system internal error System other errors that need to be printed in errmsg for specific error reasons
12011 weapp in background The app cannot configure Wi-Fi in the background
12013 wifi config may be expired The System Saved Wi-Fi configuration is out of date and it is recommended to try again after forgetting Wi-Fi

The sample code

wx.connectWifi({
  SSID: '',
  password: '',
  success (res) {
    console.log(res.errMsg)
  }
})

WifiInfo

Wifi information

Property

string SSID

The SSID for Wi-Fi

string BSSID

BSSID for Wi-Fi

boolean secure

Whether Wi-Fi is secure

number signalStrength

Wi-Fi signal strength

number frequency

Base library 2.12.0 starts to support, and low versions need to be compatible.

Wi-Fi band unit MHz