Skip to content

Commit

Permalink
Merge pull request #736 from particle-iot/fix/wifi-control-requests
Browse files Browse the repository at this point in the history
Fix wifi configuration on serial
  • Loading branch information
keeramis authored May 15, 2024
2 parents 9477747 + af9f90d commit 6a0eb44
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/cmd/serial.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ const FlashCommand = require('./flash');
const usbUtils = require('./usb-util');
const { platformForId } = require('../lib/platform');
const { FirmwareModuleDisplayNames } = require('particle-usb');
const WifiControlRequest = require('../lib/wifi-control-request');
const semver = require('semver');

const IDENTIFY_COMMAND_TIMEOUT = 20000;


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

async configureWifi({ port, file }){
const device = await this.whatSerialPortDidYouMean(port, true);
if (!device?.specs?.features?.includes('wifi')) {
const deviceFromSerialPort = await this.whatSerialPortDidYouMean(port, true);
const deviceId = deviceFromSerialPort.deviceId;
const device = await usbUtils.getOneUsbDevice({ idOrName: deviceId });
if (!deviceFromSerialPort?.specs?.features?.includes('wifi')) {
throw new VError('The device does not support Wi-Fi');
}
// configure serial
// there is an issue with control request that doesn't allow us to pre-configure the device with the wifi credentials
// that's the reason we need to use serial to configure the device
if (file){
return this._configWifiFromFile(device, file);

// if device's firmware version is less than 6.0.0, use the old way
const fwVer = device.firmwareVersion;
if (semver.lt(fwVer, '6.0.0')) {
// configure serial
if (file){
return this._configWifiFromFile(deviceFromSerialPort, file);
} else {
return this.promptWifiScan(deviceFromSerialPort);
}
} else {
return this.promptWifiScan(device);
const wifiControlRequest = new WifiControlRequest(deviceFromSerialPort.deviceId, {
file,
ui: this.ui,
newSpin: this.newSpin,
stopSpin: this.stopSpin
});
await wifiControlRequest.configureWifi();
}

}

_configWifiFromFile(device, filename){
Expand Down

0 comments on commit 6a0eb44

Please sign in to comment.