UNPKG

@twilio/plugin-microvisor

Version:

Interact with your Twilio Microvisor devices

61 lines (60 loc) 2.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseCommand = void 0; exports.BaseCommand = require('@twilio/cli-core').baseCommands.BaseCommand; const serialport_1 = require("serialport"); const common_1 = require("../../../lib/provision/common"); const MAIN_ERROR = "Could not clear WiFi credentials"; const EOL = (process.platform == "linux" || process.platform == "darwin") ? "\n" : "\r\n"; class MicrovisorWiFiConfigClear extends exports.BaseCommand { async run() { await super.run(); const passThis = this; passThis.mainError = MAIN_ERROR; // Check user perms on Linux if (!(0, common_1.checkUserPermissions)()) { this.logger.error(`${passThis.mainError}. Please re-run as root or as a member of dialout.${EOL}`); process.exit(1); } // NOTE Port auto-opens const port = new serialport_1.SerialPort({ path: passThis.args.devicePath, baudRate: 115200 }); // Set a timeout value const timer = setTimeout(common_1.didTimeout, 5000, passThis, port); port.on("open", function () { // Clear the pipes port.flush(); // Issue the command to clear the credentials port.write("wifi clearConfig\n", "utf8", function (err) { if (err instanceof Error) { clearTimeout(timer); port.close(); passThis.logger.error(`${passThis.mainError} (${err.message}).${EOL}`); } }); }); port.on("data", function () { clearTimeout(timer); port.close(); passThis.logger.info("WiFi credentials cleared"); }); port.on("error", function (err) { passThis.logger.error(`${passThis.mainError} (${err.message}).${EOL}`); }); } async runCommand() { return run(); } } exports.default = MicrovisorWiFiConfigClear; MicrovisorWiFiConfigClear.description = "Clear a Microvisor device's WiFi credentials, if set"; MicrovisorWiFiConfigClear.args = [ { name: 'devicePath', required: true, description: 'The path to the device file or COM port' } ]; // Remove some unnecessary options delete MicrovisorWiFiConfigClear.flags['cli-output-format']; delete MicrovisorWiFiConfigClear.flags.silent; delete MicrovisorWiFiConfigClear.flags.profile;