@@ -31,7 +31,8 @@ module.exports = class WiFiControlRequest {
31
31
} else {
32
32
network = await this . getNetworkToConnect ( ) ;
33
33
}
34
- await this . joinWifi ( network ) ;
34
+ await this . setWifiCredentials ( network ) ;
35
+ console . log ( 'Done! WiFi credentials have been set.' ) ;
35
36
}
36
37
37
38
async getNetworkToConnectFromJson ( ) {
@@ -205,6 +206,33 @@ module.exports = class WiFiControlRequest {
205
206
throw this . _handleDeviceError ( lastError , { action : 'join Wi-Fi network' } ) ;
206
207
}
207
208
209
+ async setWifiCredentials ( { ssid, password } ) {
210
+ // open device by id
211
+ let retries = RETRY_COUNT ;
212
+ const spin = this . newSpin ( `Setting Wi-Fi credentials for '${ ssid } '` ) . start ( ) ;
213
+ let lastError ;
214
+ while ( retries > 0 ) {
215
+ try {
216
+ if ( ! this . device || this . device . isOpen === false ) {
217
+ this . device = await usbUtils . getOneUsbDevice ( { api : this . api , idOrName : this . deviceId } ) ;
218
+ }
219
+ await this . device . setWifiCredentials ( { ssid, password } ) ;
220
+ this . stopSpin ( ) ;
221
+ return ;
222
+ } catch ( error ) {
223
+ lastError = error ;
224
+ await utilities . delay ( TIME_BETWEEN_RETRIES ) ;
225
+ retries -- ;
226
+ } finally {
227
+ if ( this . device && this . device . isOpen ) {
228
+ await this . device . close ( ) ;
229
+ }
230
+ }
231
+ }
232
+ this . stopSpin ( ) ;
233
+ throw this . _handleDeviceError ( lastError , { action : 'set Wi-Fi credentials' } ) ;
234
+ }
235
+
208
236
async pickNetworkManually ( ) {
209
237
const ssid = await this . _promptForSSID ( ) ;
210
238
const password = await this . _promptForPassword ( ) ;
0 commit comments