Skip to content

Commit 6a0eb44

Browse files
authored
Merge pull request #736 from particle-iot/fix/wifi-control-requests
Fix wifi configuration on serial
2 parents 9477747 + af9f90d commit 6a0eb44

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

src/cmd/serial.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ const FlashCommand = require('./flash');
2020
const usbUtils = require('./usb-util');
2121
const { platformForId } = require('../lib/platform');
2222
const { FirmwareModuleDisplayNames } = require('particle-usb');
23+
const WifiControlRequest = require('../lib/wifi-control-request');
2324
const semver = require('semver');
2425

2526
const IDENTIFY_COMMAND_TIMEOUT = 20000;
2627

27-
2828
// TODO: DRY this up somehow
2929
// The categories of output will be handled via the log class, and similar for protip.
3030
const cmd = path.basename(process.argv[1]);
@@ -525,18 +525,32 @@ module.exports = class SerialCommand extends CLICommandBase {
525525
}
526526

527527
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')) {
530532
throw new VError('The device does not support Wi-Fi');
531533
}
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+
}
537544
} 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();
539552
}
553+
540554
}
541555

542556
_configWifiFromFile(device, filename){

0 commit comments

Comments
 (0)