Skip to content

Commit

Permalink
Support for setting network credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed May 16, 2024
1 parent 971a306 commit e089514
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/wifi-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,47 @@ const WifiDevice = base => class extends base {
);
}

/**
* Set a new WiFi network for Gen 3+ devices.
*
* Note, there are known bugs with this method/Device OS:
* - sc-96270: where P2's don't do anything with bssid or security fields; so cannot connect to hidden networks
* - sc-96826: Connecting to open network without passsword does not work
*
* Supported platforms:
* - Gen 4: Supported on P2 since Device OS 5.8.2
* @param {string} ssid - SSID of Wifi Network
* @param {string} password - Password of Wifi network, if not set will not use security
* @param {Object} options See sendControlRequest(), same options are here.
* @return {ProtobufInteraction} -
*/
async setWifiCredentials({ ssid, password = null }, options) {
let dataPayload;
if (password === null) {
dataPayload = {
ssid,
bssid: null,
security: 0 // Security.NO_SECURITY
};
throw new Error('joinNewWifiNetwork() does not currently support connecting to networks without a password/security, sc-TODO');
} else {
dataPayload = {
ssid,
bssid: null,
security: null,
credentials: {
type: 1, // CredentialsType.PASSWORD
password
},
};
}
return await this._sendAndHandleProtobufRequest(
'wifi.SetNetworkCredentialsRequest',
dataPayload,
options
);
}

/**
* Clear Wifi networks for Gen 3+ devices
*
Expand Down

0 comments on commit e089514

Please sign in to comment.