Add command for setting the wifi mode easier

This commit is contained in:
Oleg Kalachev
2026-06-09 02:44:09 +03:00
parent 71abe1bcdb
commit e51b47b798
3 changed files with 25 additions and 4 deletions
+7 -4
View File
@@ -45,9 +45,10 @@ const char* motd =
"cr - calibrate RC\n" "cr - calibrate RC\n"
"pw - show power info\n" "pw - show power info\n"
"wifi - show Wi-Fi info\n" "wifi - show Wi-Fi info\n"
"ap <ssid> <password> - setup Wi-Fi access point\n" "wifi ap/sta/espnow/off - set Wi-Fi mode\n"
"sta <ssid> <password> - setup Wi-Fi client mode\n" "ap <ssid> <password> - configure Wi-Fi access point\n"
"espnow <mac> [<key>] - setup ESP-NOW peer\n" "sta <ssid> <password> - configure Wi-Fi client mode\n"
"espnow <mac> [<key>] - configure ESP-NOW peer\n"
"mot - show motor output\n" "mot - show motor output\n"
"log [dump] - print log header [and data]\n" "log [dump] - print log header [and data]\n"
"mfr, mfl, mrr, mrl - test motor (remove props)\n" "mfr, mfl, mrr, mrl - test motor (remove props)\n"
@@ -139,8 +140,10 @@ void doCommand(String str, bool echo = false) {
print("armed: %d\n", armed); print("armed: %d\n", armed);
} else if (command == "pw") { } else if (command == "pw") {
print("Voltage: %.1f V\n", voltage); print("Voltage: %.1f V\n", voltage);
} else if (command == "wifi") { } else if (command == "wifi" && arg0 == "") {
printWiFiInfo(); printWiFiInfo();
} else if (command == "wifi") {
setWiFiMode(arg0);
} else if (command == "ap") { } else if (command == "ap") {
configWiFi(W_AP, arg0.c_str(), arg1.c_str()); configWiFi(W_AP, arg0.c_str(), arg1.c_str());
} else if (command == "sta") { } else if (command == "sta") {
+17
View File
@@ -132,3 +132,20 @@ void configWiFi(int mode, const char *first, const char *second) {
} }
print("✓ Reboot to apply new settings\n"); print("✓ Reboot to apply new settings\n");
} }
void setWiFiMode(const String& mode) {
if (mode == "ap") {
wifiMode = W_AP;
} else if (mode == "sta") {
wifiMode = W_STA;
} else if (mode == "espnow") {
wifiMode = W_ESPNOW;
} else if (mode == "off") {
wifiMode = W_DISABLED;
} else {
print("Invalid Wi-Fi mode\n");
return;
}
static const char *modes[] = {"Disabled", "Access Point (AP)", "Client (STA)", "ESP-NOW"};
print("✓ Wi-Fi mode set to %s, reboot to apply\n", modes[wifiMode]);
}
+1
View File
@@ -79,3 +79,4 @@ void printIMUCalibration() { print("cal: N/A\n"); };
void printIMUInfo() {}; void printIMUInfo() {};
void printWiFiInfo() {}; void printWiFiInfo() {};
void configWiFi(bool, const char*, const char*) { print("Skip WiFi config\n"); }; void configWiFi(bool, const char*, const char*) { print("Skip WiFi config\n"); };
void setWiFiMode(const String& mode) { print("Skip WiFi mode set\n"); };