connectWifi
Introduction
Connects to a Wi-Fi network. If you have the Wi-Fi information, you can use this interface to connect directly. Note that for devices running Android 10 and above, after a device connects to Wi-Fi, other processes may not be able to use the currently connected Wi-Fi (subject to system capabilities). In other words, the connected Wi-Fi is only valid for the current mini-program. If you want to make it effective for the entire system, you need to configure it manually to connect to Wi-Fi.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
SSID | String | Yes | Wi-Fi network name (SSID) |
BSSID | String | No | Wi-Fi MAC address |
password | String | Yes | Wi-Fi password |
manual | Boolean | No | Default is false. If true, it will pull up the Wi-Fi settings page for manual connection |
Sample Code
Page({
data: {
wifiStatus: '',
connectWifi: '',
},
onReady() {
this.startWifi().then(() => {
this.connectWifi();
});
},
startWifi() {
const _that = this;
return new Promise((resolve, reject) => {
dlt.startWifi({
success: function (res) {
console.log('startWifi success', res);
_that.setData({
wifiStatus: 'startWifi',
});
resolve(res);
},
complete: function (res) {
console.log('startWifi complete', res);
},
fail: function (res) {
console.log('startWifi fail', res);
reject(res);
},
});
});
},
connectWifi() {
const _that = this;
dlt.connectWifi({
SSID: this.data.SSID,
BSSID: '',
password: this.data.password,
manual: false,
success: function (res) {
console.log('connectWifi success', res);
_that.setData({
connectWifi: res,
});
},
complete: function (res) {
console.log('connectWifi complete', res);
},
fail: function (res) {
console.log('connectWifi fail', res);
},
});
},
});