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

Add set credentials usb request #2763

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

scott-brust
Copy link
Member

@scott-brust scott-brust commented Apr 10, 2024

Problem

The existing JoinNewNetworkRequest protobuf message has some behavior that might be undesireable in some circumstances.

  • The wifi network specified in the request must be present for the credentials to be stored
  • The device will power on wifi and attempt to connect to wifi (not necessarily using the new credentials if there are existing credentials/networks known)

Solution

For use cases like a factory environment where the end wifi network is not present, it is desired to set credentials without attempting to immediately power on wifi and connect. The SetNetworkCredentialsRequest will simply store the credentials to the devices internal list of wifi credentials.

Some items to note:

  • Currently, devices in the 5x line of Device OS can store 10 wifi credentials.
  • ⚠️ If a device has 10 credentials and is asked to store more, it will discard the last credential in the list and replace it with the specified one. Not sure if this is the clearest behavior

Steps to Test

I used particle-usb with the protobuf module updated to the branch here
Install / build the definitions as in the example.

I added the following snippet to particle-usb.js to test the device OS parsing/handling of the new request

async function testDevices(){
    const devices = await getDevices();

    for (let device of devices) {
    console.log("Device Type: ", device.type);
    }

	let device = devices[0];
	await device.open();

	let message = {
		type_id : 507, // CTRL_REQUEST_WIFI_SET_NETWORK_CREDENTIALS
		ssid: "TP-Link_F6E0",
		bssid: null,
		security: 4, //   WPA_WPA2_PSK = 4
		hidden: false,
		credentials: {
			type: 1, // CredentialsType.PASSWORD
			password: "78019348"
		}
	}

	for (let iter = 0; iter < 20; iter++) {
		message.ssid = "network".concat(iter);
		let rep = await device._sendAndHandleProtobufRequest('wifi.SetNetworkCredentialsRequest', message, { timeout: 30000 });
		console.log( rep);
	}
}

testDevices();

Test with node particle-usb.js

Example App

The connection-manager app has some helpful commands to list/clear wifi APs to validate testing. See a and l commands.

Relevant PRs

particle-iot/device-os-protobuf#31

@scott-brust scott-brust marked this pull request as ready for review April 10, 2024 21:07
@scott-brust scott-brust added this to the 5.8.1 milestone Apr 12, 2024
@scott-brust scott-brust modified the milestones: 5.8.1, 5.8.2 May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant