improve logging for wifi

This commit is contained in:
wellenvogel 2021-12-09 12:01:26 +01:00
parent 24cd250d86
commit 934f94fcaa
2 changed files with 23 additions and 8 deletions

View File

@ -15,6 +15,7 @@ class GwWifi{
unsigned long apShutdownTime=0; unsigned long apShutdownTime=0;
bool apActive=false; bool apActive=false;
bool fixedApPass=true; bool fixedApPass=true;
bool clientIsConnected=false;
public: public:
GwWifi(const GwConfigHandler *config,GwLog *log, bool fixedApPass=true); GwWifi(const GwConfigHandler *config,GwLog *log, bool fixedApPass=true);
void setup(); void setup();

View File

@ -36,25 +36,39 @@ void GwWifi::setup(){
if (apShutdownTime < 120 && apShutdownTime != 0) apShutdownTime=120; //min 2 minutes if (apShutdownTime < 120 && apShutdownTime != 0) apShutdownTime=120; //min 2 minutes
logger->logString("GWWIFI: AP auto shutdown %s (%ds)",apShutdownTime> 0?"enabled":"disabled",apShutdownTime); logger->logString("GWWIFI: AP auto shutdown %s (%ds)",apShutdownTime> 0?"enabled":"disabled",apShutdownTime);
apShutdownTime=apShutdownTime*1000; //ms apShutdownTime=apShutdownTime*1000; //ms
clientIsConnected=false;
connectInternal(); connectInternal();
} }
bool GwWifi::connectInternal(){ bool GwWifi::connectInternal(){
if (wifiClient->asBoolean()){ if (wifiClient->asBoolean()){
clientIsConnected=false;
logger->logString("creating wifiClient ssid=%s",wifiSSID->asString().c_str()); logger->logString("creating wifiClient ssid=%s",wifiSSID->asString().c_str());
WiFi.begin(wifiSSID->asCString(),wifiPass->asCString()); wl_status_t rt=WiFi.begin(wifiSSID->asCString(),wifiPass->asCString());
LOG_DEBUG(GwLog::LOG,"wifiClient connect returns %d",(int)rt);
lastConnectStart=millis(); lastConnectStart=millis();
return true; return true;
} }
return false; return false;
} }
#define RETRY_MILLIS 10000 #define RETRY_MILLIS 20000
void GwWifi::loop(){ void GwWifi::loop(){
if (wifiClient->asBoolean() && ! clientConnected()){ if (wifiClient->asBoolean())
long now=millis(); {
if (lastConnectStart > now || (lastConnectStart+RETRY_MILLIS) < now){ if (!clientConnected())
logger->logString("wifiClient: retry connect to %s",wifiSSID->asCString()); {
WiFi.disconnect(); long now = millis();
connectInternal(); if (lastConnectStart > now || (lastConnectStart + RETRY_MILLIS) < now)
{
LOG_DEBUG(GwLog::LOG,"wifiClient: retry connect to %s", wifiSSID->asCString());
WiFi.disconnect();
connectInternal();
}
}
else{
if (! clientIsConnected){
LOG_DEBUG(GwLog::LOG,"client %s now connected",wifiSSID->asCString());
clientIsConnected=true;
}
} }
} }
if (apShutdownTime != 0 && apActive){ if (apShutdownTime != 0 && apActive){