Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wifi configuration on serial #736

Merged
merged 4 commits into from
May 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading