From 0a34a2117fd18e8c71433e93e90de05f6a29ceff Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Sat, 25 Mar 2023 12:27:56 +0100 Subject: [PATCH] chknet command --- ESP32/main.ino | 32 ++++++++++++++++++++++++-------- debugger.cpp | 7 +++++++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/ESP32/main.ino b/ESP32/main.ino index 50fb914..18c0b7a 100644 --- a/ESP32/main.ino +++ b/ESP32/main.ino @@ -274,16 +274,12 @@ void configure_network(console *const c) WiFi.begin(parts.at(0).c_str(), parts.at(1).c_str()); } -void start_network(console *const c) -{ - WiFi.mode(WIFI_STA); - - set_hostname(); - - WiFi.begin(); +void wait_network(console *const c) { + constexpr const int timeout = 10 * 3; int i = 0; - while (WiFi.waitForConnectResult() != WL_CONNECTED && i < 10 * 3) { + + while (WiFi.waitForConnectResult() != WL_CONNECTED && i < timeout) { c->put_string("."); delay(1000 / 3); @@ -291,6 +287,26 @@ void start_network(console *const c) i++; } + if (i == timeout) + c->put_string_lf("Time out connecting"); +} + +void check_network(console *const c) { + wait_network(c); + + c->put_string_lf(""); + c->put_string_lf(format("Local IP address: %s", WiFi.localIP().toString().c_str())); +} + +void start_network(console *const c) { + WiFi.mode(WIFI_STA); + + set_hostname(); + + WiFi.begin(); + + wait_network(c); + c->put_string_lf(""); c->put_string_lf(format("Local IP address: %s", WiFi.localIP().toString().c_str())); } diff --git a/debugger.cpp b/debugger.cpp index 20d9118..f9ace57 100644 --- a/debugger.cpp +++ b/debugger.cpp @@ -14,6 +14,7 @@ void setBootLoader(bus *const b); void configure_disk(console *const c); void configure_network(console *const c); +void check_network(console *const c); void start_network(console *const c); #endif @@ -367,6 +368,11 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto continue; } + else if (cmd == "chknet") { + check_network(cnsl); + + continue; + } else if (cmd == "startnet") { start_network(cnsl); @@ -406,6 +412,7 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto #if defined(ESP32) cnsl->put_string_lf("cfgnet - configure network (e.g. WiFi)"); cnsl->put_string_lf("startnet - start network"); + cnsl->put_string_lf("chknet - check network status"); cnsl->put_string_lf("cfgdisk - configure disk"); #endif