Skip to content

Commit

Permalink
Fixed $WiFi/ListAPs. (#1276)
Browse files Browse the repository at this point in the history
* Fixed $WiFi/ListAPs.

* Fix crash with $wifi/mode=off
  • Loading branch information
MitchBradley authored Aug 2, 2024
1 parent 4677619 commit 34551c6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 35 deletions.
4 changes: 4 additions & 0 deletions FluidNC/src/WebUI/TelnetServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ namespace WebUI {
std::queue<TelnetClient*> TelnetServer::_disconnected;

void TelnetServer::init() {
if (WiFi.getMode() == WIFI_OFF) {
return;
}

deinit();

telnet_port =
Expand Down
3 changes: 2 additions & 1 deletion FluidNC/src/WebUI/WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ namespace WebUI {

_setupdone = false;

if (!http_enable->get()) {
if (WiFi.getMode() == WIFI_OFF || !http_enable->get()) {
return;
}

_port = http_port->get();

//create instance
Expand Down
69 changes: 35 additions & 34 deletions FluidNC/src/WebUI/WifiConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ namespace WebUI {
void wifi_stats(JSONencoder& j) {
j.id_value_object("Sleep mode", WiFi.getSleep() ? "Modem" : "None");
int mode = WiFi.getMode();
if (mode != WIFI_MODE_NULL) {
if (mode != WIFI_OFF) {
//Is OTA available ?
size_t flashsize = 0;
if (esp_ota_get_running_partition()) {
Expand Down Expand Up @@ -337,7 +337,7 @@ namespace WebUI {
void status_report(Channel& out) {
log_stream(out, "Sleep mode: " << (WiFi.getSleep() ? "Modem" : "None"));
int mode = WiFi.getMode();
if (mode != WIFI_MODE_NULL) {
if (mode != WIFI_OFF) {
//Is OTA available ?
size_t flashsize = 0;
if (esp_ota_get_running_partition()) {
Expand Down Expand Up @@ -471,7 +471,7 @@ namespace WebUI {

static const char* modeName() {
switch (WiFi.getMode()) {
case WIFI_MODE_NULL:
case WIFI_OFF:
return "None";
case WIFI_STA:
return "STA";
Expand Down Expand Up @@ -555,13 +555,13 @@ namespace WebUI {
s << " # webcommunication: Sync: ";
s << std::to_string(Web_Server::port() + 1) + ":";
switch (WiFi.getMode()) {
case WIFI_MODE_AP:
case WIFI_AP:
s << IP_string(WiFi.softAPIP());
break;
case WIFI_MODE_STA:
case WIFI_STA:
s << IP_string(WiFi.localIP());
break;
case WIFI_MODE_APSTA:
case WIFI_AP_STA:
s << IP_string(WiFi.softAPIP());
break;
default:
Expand Down Expand Up @@ -758,7 +758,7 @@ namespace WebUI {
}

static void StopWiFi() {
if (WiFi.getMode() != WIFI_MODE_NULL) {
if (WiFi.getMode() != WIFI_OFF) {
if ((WiFi.getMode() == WIFI_STA) || (WiFi.getMode() == WIFI_AP_STA)) {
WiFi.disconnect(true);
}
Expand All @@ -785,7 +785,7 @@ namespace WebUI {
std::string result;

auto mode = WiFi.getMode();
if (mode == WIFI_MODE_STA || mode == WIFI_MODE_APSTA) {
if (mode == WIFI_STA || mode == WIFI_AP_STA) {
result += "Mode=STA:SSID=";
result += WiFi.SSID().c_str();
result += ":Status=";
Expand All @@ -804,8 +804,8 @@ namespace WebUI {
std::string result;

auto mode = WiFi.getMode();
if (mode == WIFI_MODE_AP || mode == WIFI_MODE_APSTA) {
if (WiFi.getMode() == WIFI_MODE_APSTA) {
if (mode == WIFI_AP || mode == WIFI_AP_STA) {
if (WiFi.getMode() == WIFI_AP_STA) {
result += "]\n[MSG:";
}
result += "Mode=AP:SSID=";
Expand All @@ -823,7 +823,7 @@ namespace WebUI {
}

static bool isOn() {
return !(WiFi.getMode() == WIFI_MODE_NULL);
return !(WiFi.getMode() == WIFI_OFF);
}

// Used by js/scanwifidlg.js
Expand All @@ -842,31 +842,32 @@ namespace WebUI {

// An initial async scanNetworks was issued at startup, so there
// is a good chance that scan information is already available.
int n = WiFi.scanComplete();
switch (n) {
case -2: // Scan not triggered
WiFi.scanNetworks(true); // Begin async scan
break;
case -1: // Scan in progress
break;
default:
for (int i = 0; i < n; ++i) {
j.begin_object();
j.member("SSID", WiFi.SSID(i).c_str());
j.member("SIGNAL", getSignal(WiFi.RSSI(i)));
j.member("IS_PROTECTED", WiFi.encryptionType(i) != WIFI_AUTH_OPEN);
// j->member("IS_PROTECTED", WiFi.encryptionType(i) == WIFI_AUTH_OPEN ? "0" : "1");
j.end_object();
}
WiFi.scanDelete();
// Restart the scan in async mode so new data will be available
// when we ask again.
n = WiFi.scanComplete();
if (n == -2) {
WiFi.scanNetworks(true);
}
int n;
while (true) {
n = WiFi.scanComplete();
if (n >= 0) { // Scan completed with n results
break;
}
if (n == WIFI_SCAN_FAILED) { // Begin async scan
// async hidden passive ms_per_chan
WiFi.scanNetworks(true, false, false, 1000);
}
// Else WIFI_SCAN_RUNNING
delay(1000);
}

for (int i = 0; i < n; ++i) {
j.begin_object();
j.member("SSID", WiFi.SSID(i).c_str());
j.member("SIGNAL", getSignal(WiFi.RSSI(i)));
j.member("IS_PROTECTED", WiFi.encryptionType(i) != WIFI_AUTH_OPEN);
// j->member("IS_PROTECTED", WiFi.encryptionType(i) == WIFI_AUTH_OPEN ? "0" : "1");
j.end_object();
}
WiFi.scanDelete();
// Restart the scan in async mode so new data will be available
// when we ask again.
WiFi.scanNetworks(true);
j.end_array();
j.end();
return Error::Ok;
Expand Down

0 comments on commit 34551c6

Please sign in to comment.