Skip to content

Commit

Permalink
For WebUI v3, ESP 800 was sending hardcoded values for the WebSocket …
Browse files Browse the repository at this point in the history
…address, rather than the values as actually configured
  • Loading branch information
michmela44 committed Nov 4, 2024
1 parent 3c58324 commit fbc75ba
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions FluidNC/src/WebUI/WifiConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,23 @@ namespace WebUI {
j.member("Authentication", "Disabled");
#endif
j.member("WebCommunication", "Synchronous");
j.member("WebSocketIP", "localhost");

j.member("WebSocketPort", "82");
switch (WiFi.getMode()) {
case WIFI_AP:
j.member("WebSocketIP", IP_string(WiFi.softAPIP()));
break;
case WIFI_STA:
j.member("WebSocketIP", IP_string(WiFi.localIP()));
break;
case WIFI_AP_STA:
j.member("WebSocketIP", IP_string(WiFi.softAPIP()));
break;
default:
j.member("WebSocketIP", "0.0.0.0");
break;
}

j.member("WebSocketPort", std::to_string(Web_Server::port() + 2));
j.member("HostName", WiFi.getHostname());
j.member("WiFiMode", modeName());
j.member("FlashFileSystem", "LittleFS");
Expand Down

5 comments on commit fbc75ba

@MitchBradley
Copy link
Collaborator

@MitchBradley MitchBradley commented on fbc75ba Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a failure mode here. If the response includes an explicit IP address, and later the WiFi router goes down and comes back up, a different IP address can be assigned but WebUI will still know the old one and be unable to reconnect. See lines 578-588 (line numbers after this patch) for more information.

@michmela44
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't disagree with the assessment, however, I'm not sure what could/should be done in that case.

The code here was copied from the ESP800 implementation that already existed for the V2 UI at line 579 of this file:

            // If we omit the explicit IP address for the websocket,
            // WebUI will use the same IP address that it uses for
            // HTTP, with the port number as above.  That is better
            // than providing an explicit address, because if the WiFi
            // drops and comes back up again, DHCP might assign a
            // different IP address so the one provided below would no
            // longer work.  But if we are using an MDNS address like
            // fluidnc.local, a websocket reconnection will succeed
            // because MDNS will offer the new IP address.
            s << ":";
            switch (WiFi.getMode()) {
                case WIFI_AP:
                    s << IP_string(WiFi.softAPIP());
                    break;
                case WIFI_STA:
                    s << IP_string(WiFi.localIP());
                    break;
                case WIFI_AP_STA:
                    s << IP_string(WiFi.softAPIP());
                    break;
                default:
                    s << "0.0.0.0";
                    break;
            }

At the moment, this address is only being used in WebUI3 to fill out the modal dialog that appears when connecting from within the captive portal in AP mode.

Image

@michmela44
Copy link
Contributor Author

@michmela44 michmela44 commented on fbc75ba Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about this a bit more....

If the router went down and lost connection, WebUI3 will detect the disconnect and show a screen with a "Connect again" button like this.

Image

In this case, I believe it will reconnect, and retrieve the settings again with ESP800, which will contain the new address.

So practically speaking, I don't think there is a case with WebUI3 where this can cause an issue.

@MitchBradley
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you test it? The easy way to simulate the router going down is to connect via a mobile hotspot. The mobile hotspot that is built into recent Windows is very convenient for such tests.

@michmela44
Copy link
Contributor Author

@michmela44 michmela44 commented on fbc75ba Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did end up testing afterwards last night that the "Connect again" button does trigger the ESP800 to be sent again with WebUI3, which should only come into play if you are in STA mode with DHCP enabled, but connected using mDNS at http://fluid.local or whatever it's configured as.

Direct IP address connection will force you to do a full refresh when it changes. AP mode should not be affected.

Please sign in to comment.