mirror of
https://github.com/lora-aprs/LoRa_APRS_iGate.git
synced 2025-12-06 07:42:00 +01:00
move conect function into loop function
This commit is contained in:
parent
629138c54c
commit
ef0b705d31
|
|
@ -19,7 +19,6 @@ AprsIsTask::~AprsIsTask()
|
||||||
bool AprsIsTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig)
|
bool AprsIsTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig)
|
||||||
{
|
{
|
||||||
_aprs_is = std::shared_ptr<APRS_IS>(new APRS_IS(config->callsign, config->aprs_is.passcode , "ESP32-APRS-IS", "0.1"));
|
_aprs_is = std::shared_ptr<APRS_IS>(new APRS_IS(config->callsign, config->aprs_is.passcode , "ESP32-APRS-IS", "0.1"));
|
||||||
connect(config);
|
|
||||||
|
|
||||||
_beaconMsg = std::shared_ptr<APRSMessage>(new APRSMessage());
|
_beaconMsg = std::shared_ptr<APRSMessage>(new APRSMessage());
|
||||||
_beaconMsg->setSource(config->callsign);
|
_beaconMsg->setSource(config->callsign);
|
||||||
|
|
@ -35,8 +34,9 @@ bool AprsIsTask::loop(std::shared_ptr<Configuration> config)
|
||||||
{
|
{
|
||||||
if(!_aprs_is->connected())
|
if(!_aprs_is->connected())
|
||||||
{
|
{
|
||||||
connect(config);
|
return connect(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
_aprs_is->getAPRSMessage();
|
_aprs_is->getAPRSMessage();
|
||||||
|
|
||||||
if(!inputQueue.empty())
|
if(!inputQueue.empty())
|
||||||
|
|
@ -57,19 +57,18 @@ bool AprsIsTask::loop(std::shared_ptr<Configuration> config)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AprsIsTask::connect(std::shared_ptr<Configuration> config)
|
bool AprsIsTask::connect(std::shared_ptr<Configuration> config)
|
||||||
{
|
{
|
||||||
logPrintI("connecting to APRS-IS server: ");
|
logPrintI("connecting to APRS-IS server: ");
|
||||||
logPrintI(config->aprs_is.server);
|
logPrintI(config->aprs_is.server);
|
||||||
logPrintI(" on port: ");
|
logPrintI(" on port: ");
|
||||||
logPrintlnI(String(config->aprs_is.port));
|
logPrintlnI(String(config->aprs_is.port));
|
||||||
//show_display("INFO", "Connecting to APRS-IS server");
|
//show_display("INFO", "Connecting to APRS-IS server");
|
||||||
while(!_aprs_is->connect(config->aprs_is.server, config->aprs_is.port))
|
if(!_aprs_is->connect(config->aprs_is.server, config->aprs_is.port))
|
||||||
{
|
{
|
||||||
logPrintlnE("Connection failed.");
|
logPrintlnE("Connection failed.");
|
||||||
logPrintlnI("Waiting 1 seconds before retrying...");
|
return false;
|
||||||
//show_display("ERROR", "Server connection failed!", "waiting 5 sec");
|
|
||||||
delay(1000);
|
|
||||||
}
|
}
|
||||||
logPrintlnI("Connected to APRS-IS server!");
|
logPrintlnI("Connected to APRS-IS server!");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ private:
|
||||||
std::shared_ptr<APRSMessage> _beaconMsg;
|
std::shared_ptr<APRSMessage> _beaconMsg;
|
||||||
time_t _beacon_next_time;
|
time_t _beacon_next_time;
|
||||||
|
|
||||||
void connect(std::shared_ptr<Configuration> config);
|
bool connect(std::shared_ptr<Configuration> config);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
#include "Task.h"
|
#include "Task.h"
|
||||||
|
|
||||||
FTPTask::FTPTask()
|
FTPTask::FTPTask()
|
||||||
: Task(TASK_FTP)
|
: Task(TASK_FTP), _beginCalled(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -26,8 +26,6 @@ bool FTPTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<Board
|
||||||
_ftpServer->addUser(user.name, user.password);
|
_ftpServer->addUser(user.name, user.password);
|
||||||
}
|
}
|
||||||
_ftpServer->addFilesystem("SPIFFS", &SPIFFS);
|
_ftpServer->addFilesystem("SPIFFS", &SPIFFS);
|
||||||
_ftpServer->begin();
|
|
||||||
logPrintlnI("FTP Server init done!");
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -36,6 +34,11 @@ bool FTPTask::loop(std::shared_ptr<Configuration> config)
|
||||||
{
|
{
|
||||||
if(config->ftp.active)
|
if(config->ftp.active)
|
||||||
{
|
{
|
||||||
|
if(!_beginCalled)
|
||||||
|
{
|
||||||
|
_ftpServer->begin();
|
||||||
|
_beginCalled = true;
|
||||||
|
}
|
||||||
_ftpServer->handle();
|
_ftpServer->handle();
|
||||||
static bool configWasOpen = false;
|
static bool configWasOpen = false;
|
||||||
if(configWasOpen && _ftpServer->countConnections() == 0)
|
if(configWasOpen && _ftpServer->countConnections() == 0)
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<FTPServer> _ftpServer;
|
std::shared_ptr<FTPServer> _ftpServer;
|
||||||
|
bool _beginCalled;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ bool LoraTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<Boar
|
||||||
_lora_aprs->setSignalBandwidth(config->lora.signalBandwidth);
|
_lora_aprs->setSignalBandwidth(config->lora.signalBandwidth);
|
||||||
_lora_aprs->setCodingRate4(config->lora.codingRate4);
|
_lora_aprs->setCodingRate4(config->lora.codingRate4);
|
||||||
_lora_aprs->enableCrc();
|
_lora_aprs->enableCrc();
|
||||||
logPrintlnI("LoRa init done!");
|
|
||||||
//show_display("INFO", "LoRa init done!", 2000);
|
//show_display("INFO", "LoRa init done!", 2000);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -52,5 +51,12 @@ bool LoraTask::loop(std::shared_ptr<Configuration> config)
|
||||||
std::shared_ptr<AprsIsTask> is_thread = std::static_pointer_cast<AprsIsTask>(TaskManager::instance().getTask(TASK_APRS_IS));
|
std::shared_ptr<AprsIsTask> is_thread = std::static_pointer_cast<AprsIsTask>(TaskManager::instance().getTask(TASK_APRS_IS));
|
||||||
is_thread->inputQueue.addElement(msg);
|
is_thread->inputQueue.addElement(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!inputQueue.empty())
|
||||||
|
{
|
||||||
|
std::shared_ptr<APRSMessage> msg = inputQueue.getElement();
|
||||||
|
_lora_aprs->sendMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ public:
|
||||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
||||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
||||||
|
|
||||||
|
TaskQueue<std::shared_ptr<APRSMessage>> inputQueue;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<LoRa_APRS> _lora_aprs;
|
std::shared_ptr<LoRa_APRS> _lora_aprs;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
#include "Task.h"
|
#include "Task.h"
|
||||||
|
|
||||||
NTPTask::NTPTask()
|
NTPTask::NTPTask()
|
||||||
: Task(TASK_NTP)
|
: Task(TASK_NTP), _beginCalled(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -16,27 +16,21 @@ NTPTask::~NTPTask()
|
||||||
bool NTPTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig)
|
bool NTPTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig)
|
||||||
{
|
{
|
||||||
_ntpClient = std::shared_ptr<NTPClient>(new NTPClient(config->ntpServer.c_str()));
|
_ntpClient = std::shared_ptr<NTPClient>(new NTPClient(config->ntpServer.c_str()));
|
||||||
_ntpClient->begin();
|
|
||||||
while(!_ntpClient->forceUpdate())
|
|
||||||
{
|
|
||||||
logPrintlnW("NTP Client force update issue! Waiting 1 sek...");
|
|
||||||
logPrintlnD(_ntpClient->getFormattedTime());
|
|
||||||
//show_display("WARN", "NTP Client force update issue! Waiting 1 sek...", 1000);
|
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
setTime(_ntpClient->getEpochTime());
|
|
||||||
logPrintI("Current time: ");
|
|
||||||
logPrintlnI(_ntpClient->getFormattedTime());
|
|
||||||
logPrintlnI("NTP Client init done!");
|
|
||||||
//show_display("INFO", "NTP Client init done!", 2000);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NTPTask::loop(std::shared_ptr<Configuration> config)
|
bool NTPTask::loop(std::shared_ptr<Configuration> config)
|
||||||
{
|
{
|
||||||
|
if(!_beginCalled)
|
||||||
|
{
|
||||||
|
_ntpClient->begin();
|
||||||
|
_beginCalled = true;
|
||||||
|
}
|
||||||
if(_ntpClient->update())
|
if(_ntpClient->update())
|
||||||
{
|
{
|
||||||
setTime(_ntpClient->getEpochTime());
|
setTime(_ntpClient->getEpochTime());
|
||||||
|
logPrintI("Current time: ");
|
||||||
|
logPrintlnI(_ntpClient->getFormattedTime());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<NTPClient> _ntpClient;
|
std::shared_ptr<NTPClient> _ntpClient;
|
||||||
|
bool _beginCalled;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
#include "Task.h"
|
#include "Task.h"
|
||||||
|
|
||||||
OTATask::OTATask()
|
OTATask::OTATask()
|
||||||
: Task(TASK_OTA)
|
: Task(TASK_OTA), _beginCalled(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,13 +49,16 @@ bool OTATask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<Board
|
||||||
else if (error == OTA_END_ERROR) logPrintlnE("End Failed");
|
else if (error == OTA_END_ERROR) logPrintlnE("End Failed");
|
||||||
});
|
});
|
||||||
_ota->setHostname(config->callsign.c_str());
|
_ota->setHostname(config->callsign.c_str());
|
||||||
_ota->begin();
|
|
||||||
logPrintlnI("OTA init done!");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OTATask::loop(std::shared_ptr<Configuration> config)
|
bool OTATask::loop(std::shared_ptr<Configuration> config)
|
||||||
{
|
{
|
||||||
|
if(!_beginCalled)
|
||||||
|
{
|
||||||
|
_ota->begin();
|
||||||
|
_beginCalled = true;
|
||||||
|
}
|
||||||
_ota->handle();
|
_ota->handle();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<ArduinoOTAClass> _ota;
|
std::shared_ptr<ArduinoOTAClass> _ota;
|
||||||
|
bool _beginCalled;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ WifiTask::~WifiTask()
|
||||||
bool WifiTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig)
|
bool WifiTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig)
|
||||||
{
|
{
|
||||||
//WiFi.onEvent(WiFiEvent);
|
//WiFi.onEvent(WiFiEvent);
|
||||||
//WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
|
|
||||||
WiFi.setHostname(config->callsign.c_str());
|
WiFi.setHostname(config->callsign.c_str());
|
||||||
_wiFiMulti = std::shared_ptr<WiFiMulti>(new WiFiMulti());;
|
_wiFiMulti = std::shared_ptr<WiFiMulti>(new WiFiMulti());;
|
||||||
for(Configuration::Wifi::AP ap : config->wifi.APs)
|
for(Configuration::Wifi::AP ap : config->wifi.APs)
|
||||||
|
|
@ -25,17 +24,6 @@ bool WifiTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<Boar
|
||||||
logPrintlnD(ap.SSID);
|
logPrintlnD(ap.SSID);
|
||||||
_wiFiMulti->addAP(ap.SSID.c_str(), ap.password.c_str());
|
_wiFiMulti->addAP(ap.SSID.c_str(), ap.password.c_str());
|
||||||
}
|
}
|
||||||
logPrintlnI("Waiting for WiFi");
|
|
||||||
//show_display("INFO", "Waiting for WiFi");
|
|
||||||
while(_wiFiMulti->run() != WL_CONNECTED)
|
|
||||||
{
|
|
||||||
//show_display("INFO", "Waiting for WiFi", "....");
|
|
||||||
delay(500);
|
|
||||||
}
|
|
||||||
logPrintlnI("WiFi connected");
|
|
||||||
logPrintD("IP address: ");
|
|
||||||
logPrintlnD(WiFi.localIP().toString());
|
|
||||||
//show_display("INFO", "WiFi connected", "IP: ", WiFi.localIP().toString(), 2000);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -45,8 +33,9 @@ bool WifiTask::loop(std::shared_ptr<Configuration> config)
|
||||||
if(wifi_status != WL_CONNECTED)
|
if(wifi_status != WL_CONNECTED)
|
||||||
{
|
{
|
||||||
logPrintlnE("WiFi not connected!");
|
logPrintlnE("WiFi not connected!");
|
||||||
//show_display("ERROR", "WiFi not connected!");
|
return false;
|
||||||
delay(1000);
|
|
||||||
}
|
}
|
||||||
|
//logPrintD("IP address: ");
|
||||||
|
//logPrintlnD(WiFi.localIP().toString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue