Add WiFi connect max retries, so it won't completely block processing if WiFi is not available

pull/15/head
sh123 2021-02-01 12:11:50 +02:00
rodzic da50386616
commit 74acb404fa
2 zmienionych plików z 13 dodań i 7 usunięć

Wyświetl plik

@ -12,10 +12,6 @@ Service::Service()
{
}
Service::~Service() {
delete txQueue_;
}
void Service::setup(const Config &conf)
{
previousBeaconMs_ = 0;
@ -74,9 +70,14 @@ void Service::setupWifi(const String &wifiName, const String &wifiKey)
WiFi.mode(WIFI_STA);
WiFi.begin(wifiName.c_str(), wifiKey.c_str());
int retryCnt = 0;
while (WiFi.status() != WL_CONNECTED) {
delay(CfgConnRetryMs);
Serial.print(".");
if (retryCnt++ >= CfgWiFiConnRetryMaxTimes) {
Serial.println("failed");
return;
}
}
Serial.println("ok");
Serial.println(WiFi.localIP());
@ -87,10 +88,15 @@ void Service::reconnectWifi()
{
Serial.print("WIFI re-connecting...");
int retryCnt = 0;
while (WiFi.status() != WL_CONNECTED || WiFi.localIP() == IPAddress(0,0,0,0)) {
WiFi.reconnect();
delay(CfgConnRetryMs);
Serial.print(".");
if (retryCnt++ >= CfgWiFiConnRetryMaxTimes) {
Serial.println("failed");
return;
}
}
Serial.println("ok");
@ -231,7 +237,7 @@ void Service::onAprsisDataAvailable()
sendAX25ToLora(payload);
}
else {
Serial.println("Invalid payload from APRSIS");
Serial.println("Unknown payload from APRSIS, ignoring...");
}
}
}

Wyświetl plik

@ -17,7 +17,6 @@ class Service
{
public:
Service();
~Service();
void setup(const Config &conf);
void loop();
@ -77,6 +76,7 @@ private:
const int CfgConnRetryMs = 500;
const int CfgPollDelayMs = 5;
const int CfgLoraTxQueueSize = 4096;
const int CfgWiFiConnRetryMaxTimes = 10;
// tx when lower than this value from random 0..255
// use lower value for high traffic, use 255 for real time
@ -114,7 +114,7 @@ private:
long previousBeaconMs_;
byte csmaP_;
long csmaSlotTime_;
cppQueue *txQueue_;
std::shared_ptr<cppQueue>txQueue_;
// peripherals
BluetoothSerial serialBt_;