chknet command

This commit is contained in:
folkert van heusden 2023-03-25 12:27:56 +01:00
parent 3d97379ba5
commit 0a34a2117f
Signed by untrusted user who does not match committer: folkert
GPG key ID: 6B6455EDFEED3BD1
2 changed files with 31 additions and 8 deletions

View file

@ -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()));
}

View file

@ -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