@@ -20,11 +20,11 @@ const FlashCommand = require('./flash');
20
20
const usbUtils = require ( './usb-util' ) ;
21
21
const { platformForId } = require ( '../lib/platform' ) ;
22
22
const { FirmwareModuleDisplayNames } = require ( 'particle-usb' ) ;
23
+ const WifiControlRequest = require ( '../lib/wifi-control-request' ) ;
23
24
const semver = require ( 'semver' ) ;
24
25
25
26
const IDENTIFY_COMMAND_TIMEOUT = 20000 ;
26
27
27
-
28
28
// TODO: DRY this up somehow
29
29
// The categories of output will be handled via the log class, and similar for protip.
30
30
const cmd = path . basename ( process . argv [ 1 ] ) ;
@@ -525,18 +525,32 @@ module.exports = class SerialCommand extends CLICommandBase {
525
525
}
526
526
527
527
async configureWifi ( { port, file } ) {
528
- const device = await this . whatSerialPortDidYouMean ( port , true ) ;
529
- if ( ! device ?. specs ?. features ?. includes ( 'wifi' ) ) {
528
+ const deviceFromSerialPort = await this . whatSerialPortDidYouMean ( port , true ) ;
529
+ const deviceId = deviceFromSerialPort . deviceId ;
530
+ const device = await usbUtils . getOneUsbDevice ( { idOrName : deviceId } ) ;
531
+ if ( ! deviceFromSerialPort ?. specs ?. features ?. includes ( 'wifi' ) ) {
530
532
throw new VError ( 'The device does not support Wi-Fi' ) ;
531
533
}
532
- // configure serial
533
- // there is an issue with control request that doesn't allow us to pre-configure the device with the wifi credentials
534
- // that's the reason we need to use serial to configure the device
535
- if ( file ) {
536
- return this . _configWifiFromFile ( device , file ) ;
534
+
535
+ // if device's firmware version is less than 6.0.0, use the old way
536
+ const fwVer = device . firmwareVersion ;
537
+ if ( semver . lt ( fwVer , '6.0.0' ) ) {
538
+ // configure serial
539
+ if ( file ) {
540
+ return this . _configWifiFromFile ( deviceFromSerialPort , file ) ;
541
+ } else {
542
+ return this . promptWifiScan ( deviceFromSerialPort ) ;
543
+ }
537
544
} else {
538
- return this . promptWifiScan ( device ) ;
545
+ const wifiControlRequest = new WifiControlRequest ( deviceFromSerialPort . deviceId , {
546
+ file,
547
+ ui : this . ui ,
548
+ newSpin : this . newSpin ,
549
+ stopSpin : this . stopSpin
550
+ } ) ;
551
+ await wifiControlRequest . configureWifi ( ) ;
539
552
}
553
+
540
554
}
541
555
542
556
_configWifiFromFile ( device , filename ) {
0 commit comments