particle-iot / particle-usb

A library for accessing Particle USB devices
Apache License 2.0
5 stars 1 forks source link

Update `device.scanWiFiNetworks()` to use correct protobuf message and introduce `joinNewWifiNetwork()` #57

Closed joegoggins closed 2 years ago

joegoggins commented 2 years ago

Overview

Updates implementation of device.scanWiFiNetworks() to use CTRL_REQUEST_WIFI_SCAN_NETWORKS (506) rather that CTRL_REQUEST_WIFI_SCAN = 112, which does not work on current version of Device OS (see it commented out in system_contro.h). New implementation continues on the path set by previous pull request by using sendProtobufRequest instead of sendRequest. Increased test coverage of wifi-device.js from 42% to 57%.

Introduces joinNewWifiNetwork(). Increases test coverage of wifi-device.js from 57% to 70%

These new methods have been validated in this mfg-cli PR via 2.1.0-x prereleases. After this PR is merged, we'll cut 2.1.0 proper (non prerelease) and use that to finish out the mfg-cli work.

See sc-95533 for more details.

Known limitation: joinNewWifiNetwork may not work when for open wifi networks that don't have a password. ( This is not a blocker for mfg-cli reasons, would prefer to merge without validating this, and enqueue follow on work to handle this, or perhaps reviewers can test this)

How to test?

  1. Observe new wifi-device.test.js file and the tests passing, all new code with 100% coverage
  2. Plug in a P2 running Device 3.x
  3. Scan networks with node demo.js below
  4. Modify the joinNewWifiNetworkScan demo.js with your SSID and run node demo.js. Observe output { pass: true }
  5. Try it again with invalid ssid + password.

scanWifiNetworks() demo.js

const particleUSB = require('./src/particle-usb');
async function main() {
    const devices = await particleUSB.getDevices();
    const device = devices[0];
    await device.open();
    const reply = await device.scanWifiNetworks();
    console.log(reply);
    await device.close();
}

main();

joinNewWifiNetwork() demo.js

const particleUSB = require('./src/particle-usb');
async function main() {
    const devices = await particleUSB.getDevices();
    const device = devices[0];
    await device.open();
    const reply = await device.joinNewWifiNetwork({
        ssid: 'TODO_PUT_WIFI_SSID_HERE',
        password: 'TODO_PUT_WIFI_PASSWORD_HERE'
    });
    console.log(reply);
    await device.close();
}

main();
joegoggins commented 2 years ago

Closing, superceded by https://github.com/particle-iot/particle-usb/pull/57