kopia lustrzana https://github.com/sh123/esp32_loraprs
Add WiFi connect max retries, so it won't completely block processing if WiFi is not available
rodzic
da50386616
commit
74acb404fa
|
@ -12,10 +12,6 @@ Service::Service()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Service::~Service() {
|
|
||||||
delete txQueue_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Service::setup(const Config &conf)
|
void Service::setup(const Config &conf)
|
||||||
{
|
{
|
||||||
previousBeaconMs_ = 0;
|
previousBeaconMs_ = 0;
|
||||||
|
@ -74,9 +70,14 @@ void Service::setupWifi(const String &wifiName, const String &wifiKey)
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(wifiName.c_str(), wifiKey.c_str());
|
WiFi.begin(wifiName.c_str(), wifiKey.c_str());
|
||||||
|
|
||||||
|
int retryCnt = 0;
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
delay(CfgConnRetryMs);
|
delay(CfgConnRetryMs);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
|
if (retryCnt++ >= CfgWiFiConnRetryMaxTimes) {
|
||||||
|
Serial.println("failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Serial.println("ok");
|
Serial.println("ok");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
|
@ -87,10 +88,15 @@ void Service::reconnectWifi()
|
||||||
{
|
{
|
||||||
Serial.print("WIFI re-connecting...");
|
Serial.print("WIFI re-connecting...");
|
||||||
|
|
||||||
|
int retryCnt = 0;
|
||||||
while (WiFi.status() != WL_CONNECTED || WiFi.localIP() == IPAddress(0,0,0,0)) {
|
while (WiFi.status() != WL_CONNECTED || WiFi.localIP() == IPAddress(0,0,0,0)) {
|
||||||
WiFi.reconnect();
|
WiFi.reconnect();
|
||||||
delay(CfgConnRetryMs);
|
delay(CfgConnRetryMs);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
|
if (retryCnt++ >= CfgWiFiConnRetryMaxTimes) {
|
||||||
|
Serial.println("failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println("ok");
|
Serial.println("ok");
|
||||||
|
@ -231,7 +237,7 @@ void Service::onAprsisDataAvailable()
|
||||||
sendAX25ToLora(payload);
|
sendAX25ToLora(payload);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Serial.println("Invalid payload from APRSIS");
|
Serial.println("Unknown payload from APRSIS, ignoring...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ class Service
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Service();
|
Service();
|
||||||
~Service();
|
|
||||||
|
|
||||||
void setup(const Config &conf);
|
void setup(const Config &conf);
|
||||||
void loop();
|
void loop();
|
||||||
|
@ -77,6 +76,7 @@ private:
|
||||||
const int CfgConnRetryMs = 500;
|
const int CfgConnRetryMs = 500;
|
||||||
const int CfgPollDelayMs = 5;
|
const int CfgPollDelayMs = 5;
|
||||||
const int CfgLoraTxQueueSize = 4096;
|
const int CfgLoraTxQueueSize = 4096;
|
||||||
|
const int CfgWiFiConnRetryMaxTimes = 10;
|
||||||
|
|
||||||
// tx when lower than this value from random 0..255
|
// tx when lower than this value from random 0..255
|
||||||
// use lower value for high traffic, use 255 for real time
|
// use lower value for high traffic, use 255 for real time
|
||||||
|
@ -114,7 +114,7 @@ private:
|
||||||
long previousBeaconMs_;
|
long previousBeaconMs_;
|
||||||
byte csmaP_;
|
byte csmaP_;
|
||||||
long csmaSlotTime_;
|
long csmaSlotTime_;
|
||||||
cppQueue *txQueue_;
|
std::shared_ptr<cppQueue>txQueue_;
|
||||||
|
|
||||||
// peripherals
|
// peripherals
|
||||||
BluetoothSerial serialBt_;
|
BluetoothSerial serialBt_;
|
||||||
|
|
Ładowanie…
Reference in New Issue