Skip to content

armgit / flix

Public Imported from GitHub
0

Making an ESP32-based quadcopter from scratch

Add command for setting the wifi mode easier

Oleg Kalacheve51b47b798e3
diff --git a/flix/cli.ino b/flix/cli.ino
index ed87692..858e7ac 100644
--- a/flix/cli.ino
+++ b/flix/cli.ino
@@ -45,9 +45,10 @@ const char* motd =
"cr - calibrate RC\n"
"pw - show power info\n"
"wifi - show Wi-Fi info\n"
-"ap <ssid> <password> - setup Wi-Fi access point\n"
-"sta <ssid> <password> - setup Wi-Fi client mode\n"
-"espnow <mac> [<key>] - setup ESP-NOW peer\n"
+"wifi ap/sta/espnow/off - set Wi-Fi mode\n"
+"ap <ssid> <password> - configure Wi-Fi access point\n"
+"sta <ssid> <password> - configure Wi-Fi client mode\n"
+"espnow <mac> [<key>] - configure ESP-NOW peer\n"
"mot - show motor output\n"
"log [dump] - print log header [and data]\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);
} else if (command == "pw") {
print("Voltage: %.1f V\n", voltage);
- } else if (command == "wifi") {
+ } else if (command == "wifi" && arg0 == "") {
printWiFiInfo();
+ } else if (command == "wifi") {
+ setWiFiMode(arg0);
} else if (command == "ap") {
configWiFi(W_AP, arg0.c_str(), arg1.c_str());
} else if (command == "sta") {
diff --git a/flix/wifi.ino b/flix/wifi.ino
index ccdf0fa..8d45ca2 100644
--- a/flix/wifi.ino
+++ b/flix/wifi.ino
@@ -132,3 +132,20 @@ void configWiFi(int mode, const char *first, const char *second) {
}
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]);
+}
diff --git a/gazebo/flix.h b/gazebo/flix.h
index 8c3f1c3..e0ba9ab 100644
--- a/gazebo/flix.h
+++ b/gazebo/flix.h
@@ -79,3 +79,4 @@ void printIMUCalibration() { print("cal: N/A\n"); };
void printIMUInfo() {};
void printWiFiInfo() {};
void configWiFi(bool, const char*, const char*) { print("Skip WiFi config\n"); };
+void setWiFiMode(const String& mode) { print("Skip WiFi mode set\n"); };