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 GET WIFISCAN and base64 WiFi credential commands #262

Merged
merged 12 commits into from
Sep 22, 2023

Conversation

nekomona
Copy link
Contributor

This PR add GET WIFISCAN command to initiate a blocking scan, retrieving what hotspot could be seen by the trackers during provisioning. Could avoid connecting to a 5G hotspot, misspelling, and might help future fancy provisioning.

The result would be printed in the format below:

[INFO ] [SerialCommands] [WSCAN] Scanning for WiFi networks...
[INFO ] [SerialCommands] [WSCAN] Found <Count> networks:
[INFO ] [SerialCommands] [WSCAN] 0:\t<SSID0 Length>\t<SSID0>\t(<RSSI0>)\t<OPEN/PASS>
[INFO ] [SerialCommands] [WSCAN] 1:\t<SSID1 Length>\t<SSID1>\t(<RSSI1>)\t<OPEN/PASS>

In addition, since CmdParser couldn't deal with double quotes in SSID / Password, a base64 version for serial provisioning is added (SET BWIFI <B64SSID> <B64PASS>). Everything is the same except encoded in base64 to avoid double quote in the command.

Currently blocked by #256

@ImUrX
Copy link
Member

ImUrX commented Jul 13, 2023

btw is it necessary for it to be blocking? I have no idea if you can just print it when you get the scan data

@nekomona
Copy link
Contributor Author

I've tried the non-blocking one during the first commit, but it always returns as failed. There should be somewhere buggy but can't locate them. The blocking scan will timeout server connection but reconnects once finished, and it won't break WiFi connection. Since we only need to scan during provisioning, imo the blocking one would be enough.

@Eirenliel Eirenliel merged commit 3789a4c into SlimeVR:main Sep 22, 2023
1 check passed
Copy link
Contributor

@unlogisch04 unlogisch04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There some stuff that need to be locked at.

char pass[65];
const char * b64ssid = parser->getCmdParam(2);
const char * b64pass = parser->getCmdParam(3);
base64_decode_chars(b64ssid, strlen_P(b64ssid), ssid);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this conversation length save? so ssid will not be writen longer that it is?

const char * b64ssid = parser->getCmdParam(2);
const char * b64pass = parser->getCmdParam(3);
base64_decode_chars(b64ssid, strlen_P(b64ssid), ssid);
base64_decode_chars(b64pass, strlen_P(b64pass), pass);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

// Scan would fail if connecting, stop connecting before scan
if (WiFi.status() != WL_CONNECTED) WiFi.disconnect();

WiFi.scanNetworks();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did try it on ESP8266:
It did not work for me after a short time after boot, after the line
[INFO ] [WiFiProvisioning] SmartConfig started it did return everytime:
[INFO ] [SerialCommands] [WSCAN] Scan failed!

i would also love to have this function async, because it will probably mess up some IMUs because they need to fetch data or they may timeout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants