-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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 WifiScan
and WifiTest
commands
#16141
Add WifiScan
and WifiTest
commands
#16141
Conversation
Move Wifi Struct definition to a header file in order to be accessible from functions outside support_wifi.ino file
Hi @ascillato |
Oups, my bad, you can have spaces in the SSID (and maybe the password too) |
Yes, exactly. The comma and the spaces are accepted for SSId, but the + is not, so that is why, it is useful as separator here. The supported characters for SSId according to the standard are explained at https://www.cisco.com/assets/sol/sb/WAP321_Emulators/WAP321_Emulator_v1.0.0.3/help/Wireless05.html |
@ascillato Hi, nice new commands! Tested and encountered a little bug. If a BSSID supports WPA2 and WPA3 there is wrong shown My test scan (ESP32)
|
I think there is a difference in esp8266 and esp32 enumaration esp8266:
with scan result:
Esp32:
with scan result:
|
Let me write a common I'll also move some globals to the correct location. @ascillato pls do nothing now. |
Fix wifiscan encryption types (#16141)
@Jason2866 give latest commit a try. |
@arendst LGTM
esp8266 (WPA3 unknown to SDK, so this result is as expected)
|
Hi, thanks 👍 |
Sometimes, WiFiTest0 times out and the device goes to the network anyway. Seems to be a race condition, maybe? The device may go to the specified wifi network before it finishes the http response? |
Description:
This PR adds 2 new commands called
WifiScan
andWifiTest
which are aimed for phone apps to help in the initial configuration of Tasmota and to make more user-friendly apps.WifiScan
will scan for the Wi-Fi Networks that a Tasmota device can reach and will return the ordered list.WifiTest
can be used to test if the credentials given by the user are correct and that the device can connect to a network. Both support HTTP call and polling.On Android you can make the app to search for Wi-Fi Networks, but on iPhone you can't. On iPhone, you have to minimize the app and go to configuration. What Apple has is to connect to a known AP with known SSId and Password. That can be preconfigured in Tasmota, but if you have all your devices with the same SSId and Password, that could make conflicts in case of having several devices. https://developer.apple.com/forums/thread/39633 https://developer.apple.com/library/archive/qa/qa1942/_index.html Another approach on iPhone is to use the api NEHotspotConfiguration, which makes a pop-up asking if the user wants to connect to a predefined network without exiting the app, but that is still outside the app.
So, one solution is to have everything inside the app by offloading this limitation to the ESP8266 device. In short, to make Tasmota search for available networks and report back to the App. With this approach, the user will see on the app exactly which networks Tasmota can reach and how much signal they have. The procedure would be that the App sends the commands to Tasmota by HTTP and then polls for its status and responses (this is because HTTP commands have immediate responses).
Besides that, as these commands can be used also from console and from MQTT, they are useful to check which other networks are being saw by your installed devices and which possible interferences they have. Also, these commands are the base for an upcoming PR with a new command to mass configure all your Tasmota preflashed devices at once (in short, to configure only one device and to instruct that one to connect and configure the rest of installed devices in range).
WifiScan
WifiScan 1
will start a network scan. The results can be seen in the console and by MQTT. In the case of HTTP, you can ask Tasmota for the result by commandWifiscan
. The results will remain in RAM for 1 minute after the scan has finished.To start an scan, it must be used
WifiScan 1
:http://192.168.4.1/cm?cmnd=WifiScan%201
Tasmota should answer:
{"WifiScan":"Scanning"}
(a second later or so) it can be polled for the result by command
WifiScan
:http://192.168.4.1/cm?cmnd=WifiScan
Tasmota should answer:
that is a JSON ordered by RSSI
If a scan is being performed and Tasmota is instructed to initiate a new scan (
WifiScan 1
), it will answer{"WifiScan":"Busy"}
.If it is asked the result (
WifiScan
) before Tasmota has finished, it will answer{"WifiScan":"Scanning"}
.If it is asked the result (
WifiScan
) but an scan was not initiated or was initiated more than a minute ago, it will answer{"WifiScan":"Not Started"}
.A scan can be triggered at any time and in any mode (AP, STA or AP+STA).
WifiTest
WifiTest mySSID+myPASSWORD
can be used to test if that SSId and Password are correct so as to connect to a Network. In the present PR, this command is available only when Tasmota is in AP mode. In an upcoming PR, this can be expanded to STA mode. This command uses the dual mode of ESP devices which let them do both things, be in AP mode connected to a Phone AND also connect and test the router.Note: The separator of SSID and Password is a + symbol since is not allowed as SSId according to https://www.cisco.com/assets/sol/sb/WAP321_Emulators/WAP321_Emulator_v1.0.0.3/help/Wireless05.html
To start a WiFi Test, it must be sent:
http://192.168.4.1/cm?cmnd=WifiTest%20mySSID%2BmyPASSWORD
that is the command: WifiTest mySSID+myPASSWORD
Tasmota should answer:
{"WifiTest":"Testing"}
(a second later or so) it can be polled for the result by command
WifiTest
:http://192.168.4.1/cm?cmnd=WifiTest
Tasmota should answer:
{"WifiTest":"Successful"}
Or
{"WifiTest":"Connect failed"}
{"WifiTest":"Connect failed as no IP address received"}
{"WifiTest":"Connect failed as AP cannot be reached"}
{"WifiTest":"Connect failed with AP timeout"}
If a test is being performed and Tasmota is instructed to initiate a new test, it will answer
{"WifiTest":"Busy"}
.If it is asked the result (
WifiTest
) before Tasmota has finished, it will answer{"WifiTest":"Testing"}
.If it is asked the result (
WifiTest
) but a test was not initiated, it will answer{"WifiTest":"Not Started"}
.If the connection was successful Tasmota will save the SSID and PASSWORD, and if no other configuration is required to be sent to Tasmota, the APP should tell Tasmota to restart in order to connect to the new WiFi Network. If no command is received in 3 minutes, Tasmota will shutdown the AP mode restart in STA mode connecting to the recently configured network.
For restarting, the App should send:
http://192.168.4.1/cm?cmnd=restart%201
This extra step is useful in order to let the app KNOW that the connection was successful and be able to move to the next step.
The full syntax of this command is:
WifiTest0 SSID+PASSWORD
will test and if successful will save the credentials on the SSID Slot number 1 of Tasmota and will restart.WifiTest SSID+PASSWORD
orWifiTest1 SSID+PASSWORD
will test and if successful will save the credentials on the SSID Slot number 1 of Tasmota without a restart.WifiTest2 SSID+PASSWORD
will test and if successful will save the credentials on the SSID Slot number 2 of Tasmota and without a restart.Resources Cost for Tasmota Version 12.0.2.4
Notes:
Related issue (if applicable): NA
Checklist:
NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass