diff --git a/loraprs_service.cpp b/loraprs_service.cpp index 4dec39d..1ede27b 100644 --- a/loraprs_service.cpp +++ b/loraprs_service.cpp @@ -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..."); } } } diff --git a/loraprs_service.h b/loraprs_service.h index ee130d5..9cb3387 100644 --- a/loraprs_service.h +++ b/loraprs_service.h @@ -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_ptrtxQueue_; // peripherals BluetoothSerial serialBt_;