diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 26c67df..e21938b 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -11,6 +11,7 @@ #include "lora_utils.h" #include "wifi_utils.h" #include "digi_utils.h" +#include "time_utils.h" #include "gps_utils.h" #include "display.h" #include "utils.h" @@ -42,6 +43,7 @@ void setup() { delay(1000); Utils::setupDiplay(); WIFI_Utils::setup(); + TIME_Utils::setup(); LoRa_Utils::setup(); Utils::validateDigiFreqs(); iGateBeaconPacket = GPS_Utils::generateBeacon(); @@ -58,6 +60,7 @@ void loop() { APRS_IS_Utils::checkStatus(); show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, eigthLine, 0); while (espClient.connected()) { + TIME_Utils::getDateTime(); Utils::checkDisplayInterval(); Utils::checkBeaconInterval(); APRS_IS_Utils::processLoRaPacket(LoRa_Utils::receivePacket()); diff --git a/src/aprs_is_utils.cpp b/src/aprs_is_utils.cpp index 321baeb..838d3b2 100644 --- a/src/aprs_is_utils.cpp +++ b/src/aprs_is_utils.cpp @@ -171,7 +171,8 @@ void processAPRSISPacket(String packet) { lastScreenOn = millis(); delay(500); espClient.write(queryAnswer.c_str()); - show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "Callsign = " + Sender, "TYPE --> QUERY", 1000); + seventhLine = "Callsign = " + Sender; + eigthLine = "TYPE --> QUERY"; } } else { Serial.print("Received from APRS-IS : " + packet); @@ -180,7 +181,7 @@ void processAPRSISPacket(String packet) { display_toggle(true); lastScreenOn = millis(); Utils::typeOfPacket(packet); - show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, Sender + " -> " + Addressee, eigthLine, 0); + seventhLine = Sender + " -> " + Addressee; } } } diff --git a/src/query_utils.cpp b/src/query_utils.cpp index d55d0e9..805d9a6 100644 --- a/src/query_utils.cpp +++ b/src/query_utils.cpp @@ -11,7 +11,7 @@ namespace QUERY_Utils { String process(String query, String station, String queryOrigin) { String answer; - if (query=="?APRS?" || query=="?aprs?" || query=="?Aprs?" || query=="H" || query=="h" || query=="Help" || query=="help" || query=="?") { + if (query=="?APRS?" || query=="?aprs?" || query=="?Aprs?" || query=="H" || query=="h" || query=="HELP" || query=="Help" || query=="help" || query=="?") { answer = "?APRSV ?APRSP ?APRSL ?APRSH ?WHERE callsign"; } else if (query=="?APRSV" || query=="?aprsv" || query=="?Aprsv") { answer = "CD2RXU_LoRa_iGate 1.2 v" + versionDate; diff --git a/src/time_utils.cpp b/src/time_utils.cpp new file mode 100644 index 0000000..b4dbb6f --- /dev/null +++ b/src/time_utils.cpp @@ -0,0 +1,75 @@ +#include "time_utils.h" +#include "display.h" +#include "time.h" + +extern String firstLine; +extern String secondLine; +extern String thirdLine; +extern String fourthLine; +extern String fifthLine; +extern String sixthLine; +extern String seventhLine; +extern String eigthLine; + +namespace TIME_Utils { + +void getDateTime() { + struct tm timeinfo; + String year, month, day, hour, minute, seconds; + if(!getLocalTime(&timeinfo)){ + Serial.println("Failed to obtain time"); + fourthLine = "no time info... restarting"; + ESP.restart(); + } + + year = (String)(timeinfo.tm_year + 1900); + + month = (String)(timeinfo.tm_mon+1); + if (month.length() == 1) { + month = "0" + month; + } + + day = (String)(timeinfo.tm_mday); + if (day.length() == 1) { + day = "0" + day; + } + + hour = (String)(timeinfo.tm_hour); + if (hour == 0) { + hour = "00"; + } else if (hour.length() == 1) { + hour = "0" + hour; + } + + minute = (String)(timeinfo.tm_min); + if (minute == 0) { + minute = "00"; + } else if (minute.length() == 1) { + minute = "0" + minute; + } + + seconds = (String)(timeinfo.tm_sec); + if (seconds == 0) { + seconds = "00"; + } else if (seconds.length() == 1) { + seconds = "0" + seconds; + } + + fourthLine = year + "/" + month + "/" + day + " - " + hour + ":" + minute + ":" + seconds; + show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, eigthLine, 0); +} + +void setup() { + const char* ntpServer = "pool.ntp.org"; + const long GMT = 0; // for receiving UTC time + const long gmtOffset_sec = GMT*60*60; + const int daylightOffset_sec = 3600; + + configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); + //configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); + getDateTime(); +} + + + +} diff --git a/src/time_utils.h b/src/time_utils.h new file mode 100644 index 0000000..14783ff --- /dev/null +++ b/src/time_utils.h @@ -0,0 +1,13 @@ +#ifndef TIME_UTILS_H_ +#define TIME_UTILS_H_ + +#include + +namespace TIME_Utils { + +void getDateTime(); +void setup(); + +} + +#endif \ No newline at end of file diff --git a/src/wifi_utils.cpp b/src/wifi_utils.cpp index 9e264f3..a25cca0 100644 --- a/src/wifi_utils.cpp +++ b/src/wifi_utils.cpp @@ -56,7 +56,7 @@ void startWiFi() { digitalWrite(greenLed,LOW); Serial.print("Connected as "); Serial.println(WiFi.localIP()); - show_display("", "", " Connected!!", 1000); + show_display("", "", " Connected!!", "" , " loading programs...", 1000); } void setup() {