Skip to content

Commit

Permalink
Revert IP timer
Browse files Browse the repository at this point in the history
  • Loading branch information
cziter15 committed May 27, 2024
1 parent bd1beaf commit f6f6885
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/ksf/comp/ksWifiConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ namespace ksf::comps

bool ksWifiConnector::loop(ksApplication* app)
{
/*
It's good to have manual timer for checking if IP address is set.
Sometimes the connection status is not updated as fast as it should.
It occurred for me on ESP32S3 when using "FunBox" as a router. Then after disabling WiFi and
re-enabling it, the device was not able to reconnect to the router.
*/
if (wifiIpCheckTimer.triggered())
gotIpAddress = WiFi.localIP().operator uint32_t() != 0;

if (!isConnected())
{
if (wifiTimeoutTimer.triggered())
Expand Down Expand Up @@ -149,7 +158,7 @@ namespace ksf::comps

bool ksWifiConnector::isConnected() const
{
return WiFi.isConnected();
return WiFi.isConnected() && gotIpAddress;
}

ksWifiConnector::~ksWifiConnector()
Expand Down
3 changes: 2 additions & 1 deletion src/ksf/comp/ksWifiConnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ namespace ksf::comps
protected:
ksSimpleTimer wifiTimeoutTimer{KSF_WIFI_TIMEOUT_MS}; //!< Wifi timer - long timeout in case of issues.
ksSimpleTimer wifiReconnectTimer{KSF_WIFI_RECONNECT_TIME_MS}; //!< Wifi timer - reconnection timeout.
ksSimpleTimer wifiIpCheckTimer{KSF_ONE_SEC_MS}; //!< Wifi timer - IP check interval.
bool wasConnected : 1 {false}; //!< True if connected in previous loop. //!< True if IP address is set.
bool savePower : 1 {true}; //!< True to save power.

bool gotIpAddress : 1{false}; //!< True if IP address is set.
/*!
@brief Internal method that generates MAC address for the device.
Expand Down

0 comments on commit f6f6885

Please sign in to comment.