kopia lustrzana https://github.com/lora-aprs/LoRa_APRS_iGate
move conect function into loop function
rodzic
629138c54c
commit
ef0b705d31
|
@ -19,7 +19,6 @@ AprsIsTask::~AprsIsTask()
|
|||
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"));
|
||||
connect(config);
|
||||
|
||||
_beaconMsg = std::shared_ptr<APRSMessage>(new APRSMessage());
|
||||
_beaconMsg->setSource(config->callsign);
|
||||
|
@ -35,8 +34,9 @@ bool AprsIsTask::loop(std::shared_ptr<Configuration> config)
|
|||
{
|
||||
if(!_aprs_is->connected())
|
||||
{
|
||||
connect(config);
|
||||
return connect(config);
|
||||
}
|
||||
|
||||
_aprs_is->getAPRSMessage();
|
||||
|
||||
if(!inputQueue.empty())
|
||||
|
@ -57,19 +57,18 @@ bool AprsIsTask::loop(std::shared_ptr<Configuration> config)
|
|||
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(config->aprs_is.server);
|
||||
logPrintI(" on port: ");
|
||||
logPrintlnI(String(config->aprs_is.port));
|
||||
//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.");
|
||||
logPrintlnI("Waiting 1 seconds before retrying...");
|
||||
//show_display("ERROR", "Server connection failed!", "waiting 5 sec");
|
||||
delay(1000);
|
||||
return false;
|
||||
}
|
||||
logPrintlnI("Connected to APRS-IS server!");
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ private:
|
|||
std::shared_ptr<APRSMessage> _beaconMsg;
|
||||
time_t _beacon_next_time;
|
||||
|
||||
void connect(std::shared_ptr<Configuration> config);
|
||||
bool connect(std::shared_ptr<Configuration> config);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include "Task.h"
|
||||
|
||||
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->addFilesystem("SPIFFS", &SPIFFS);
|
||||
_ftpServer->begin();
|
||||
logPrintlnI("FTP Server init done!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -36,6 +34,11 @@ bool FTPTask::loop(std::shared_ptr<Configuration> config)
|
|||
{
|
||||
if(config->ftp.active)
|
||||
{
|
||||
if(!_beginCalled)
|
||||
{
|
||||
_ftpServer->begin();
|
||||
_beginCalled = true;
|
||||
}
|
||||
_ftpServer->handle();
|
||||
static bool configWasOpen = false;
|
||||
if(configWasOpen && _ftpServer->countConnections() == 0)
|
||||
|
|
|
@ -15,6 +15,7 @@ public:
|
|||
|
||||
private:
|
||||
std::shared_ptr<FTPServer> _ftpServer;
|
||||
bool _beginCalled;
|
||||
};
|
||||
|
||||
#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->setCodingRate4(config->lora.codingRate4);
|
||||
_lora_aprs->enableCrc();
|
||||
logPrintlnI("LoRa init done!");
|
||||
//show_display("INFO", "LoRa init done!", 2000);
|
||||
|
||||
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));
|
||||
is_thread->inputQueue.addElement(msg);
|
||||
}
|
||||
|
||||
if(!inputQueue.empty())
|
||||
{
|
||||
std::shared_ptr<APRSMessage> msg = inputQueue.getElement();
|
||||
_lora_aprs->sendMessage(msg);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ public:
|
|||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
||||
|
||||
TaskQueue<std::shared_ptr<APRSMessage>> inputQueue;
|
||||
|
||||
private:
|
||||
std::shared_ptr<LoRa_APRS> _lora_aprs;
|
||||
};
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "Task.h"
|
||||
|
||||
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)
|
||||
{
|
||||
_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;
|
||||
}
|
||||
|
||||
bool NTPTask::loop(std::shared_ptr<Configuration> config)
|
||||
{
|
||||
if(!_beginCalled)
|
||||
{
|
||||
_ntpClient->begin();
|
||||
_beginCalled = true;
|
||||
}
|
||||
if(_ntpClient->update())
|
||||
{
|
||||
setTime(_ntpClient->getEpochTime());
|
||||
logPrintI("Current time: ");
|
||||
logPrintlnI(_ntpClient->getFormattedTime());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ public:
|
|||
|
||||
private:
|
||||
std::shared_ptr<NTPClient> _ntpClient;
|
||||
bool _beginCalled;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "Task.h"
|
||||
|
||||
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");
|
||||
});
|
||||
_ota->setHostname(config->callsign.c_str());
|
||||
_ota->begin();
|
||||
logPrintlnI("OTA init done!");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OTATask::loop(std::shared_ptr<Configuration> config)
|
||||
{
|
||||
if(!_beginCalled)
|
||||
{
|
||||
_ota->begin();
|
||||
_beginCalled = true;
|
||||
}
|
||||
_ota->handle();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ public:
|
|||
|
||||
private:
|
||||
std::shared_ptr<ArduinoOTAClass> _ota;
|
||||
bool _beginCalled;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,7 +16,6 @@ WifiTask::~WifiTask()
|
|||
bool WifiTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig)
|
||||
{
|
||||
//WiFi.onEvent(WiFiEvent);
|
||||
//WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
|
||||
WiFi.setHostname(config->callsign.c_str());
|
||||
_wiFiMulti = std::shared_ptr<WiFiMulti>(new WiFiMulti());;
|
||||
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);
|
||||
_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;
|
||||
}
|
||||
|
||||
|
@ -45,8 +33,9 @@ bool WifiTask::loop(std::shared_ptr<Configuration> config)
|
|||
if(wifi_status != WL_CONNECTED)
|
||||
{
|
||||
logPrintlnE("WiFi not connected!");
|
||||
//show_display("ERROR", "WiFi not connected!");
|
||||
delay(1000);
|
||||
return false;
|
||||
}
|
||||
//logPrintD("IP address: ");
|
||||
//logPrintlnD(WiFi.localIP().toString());
|
||||
return true;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue