From bb45b96ecabd128671e6c527e03503d6d8e52406 Mon Sep 17 00:00:00 2001 From: keeramis Date: Tue, 14 May 2024 23:00:38 -0700 Subject: [PATCH] Configure wifi using serial commands for device os < 6.x --- src/cmd/serial.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/cmd/serial.js b/src/cmd/serial.js index 7a588c6cf..0220cae1b 100644 --- a/src/cmd/serial.js +++ b/src/cmd/serial.js @@ -21,6 +21,7 @@ const usbUtils = require('./usb-util'); const { platformForId } = require('../lib/platform'); const { FirmwareModuleDisplayNames } = require('../lib/require-optional')('particle-usb'); const WifiControlRequest = require('../lib/wifi-control-request'); +const semver = require('semver'); const IDENTIFY_COMMAND_TIMEOUT = 20000; @@ -524,19 +525,24 @@ 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'); } - if (device?.specs?.generation <= 2 ) { + + // 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(device, file); + return this._configWifiFromFile(deviceFromSerialPort, file); } else { - return this.promptWifiScan(device); + return this.promptWifiScan(deviceFromSerialPort); } } else { - const wifiControlRequest = new WifiControlRequest(device.deviceId, { + const wifiControlRequest = new WifiControlRequest(deviceFromSerialPort.deviceId, { file, ui: this.ui, newSpin: this.newSpin,