From 62107a5b4ad93bc608c2b8c5d39cd89b00f979f4 Mon Sep 17 00:00:00 2001 From: richonguzman Date: Fri, 6 Dec 2024 12:03:37 -0300 Subject: [PATCH] passcode verified --- include/aprs_is_utils.h | 3 +++ src/LoRa_APRS_iGate.cpp | 12 ++++++------ src/aprs_is_utils.cpp | 32 ++++++++++++++++++++++++-------- src/utils.cpp | 5 +++-- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/include/aprs_is_utils.h b/include/aprs_is_utils.h index 7c2b9e10..23e6a57f 100644 --- a/include/aprs_is_utils.h +++ b/include/aprs_is_utils.h @@ -8,6 +8,7 @@ namespace APRS_IS_Utils { void upload(const String& line); void connect(); + void checkStatus(); String checkForStartingBytes(const String& packet); @@ -19,6 +20,8 @@ namespace APRS_IS_Utils { void processAPRSISPacket(const String& packet); void listenAPRSIS(); + void firstConnection(); + } #endif \ No newline at end of file diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 6af4a4df..505ba228 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -48,7 +48,7 @@ ___________________________________________________________________*/ #include "A7670_utils.h" #endif -String versionDate = "2024.12.04"; +String versionDate = "2024.12.06"; Configuration Config; WiFiClient espClient; #ifdef HAS_GPS @@ -136,6 +136,7 @@ void setup() { A7670_Utils::setup(); #endif Utils::checkRebootMode(); + APRS_IS_Utils::firstConnection(); } void loop() { @@ -149,14 +150,13 @@ void loop() { if (Config.lowVoltageCutOff > 0) { BATTERY_Utils::checkIfShouldSleep(); } - + thirdLine = Utils::getLocalIP(); - WIFI_Utils::checkWiFi(); - #ifdef HAS_A7670 if (Config.aprs_is.active && !modemLoggedToAPRSIS) A7670_Utils::APRS_IS_connect(); #else + WIFI_Utils::checkWiFi(); if (Config.aprs_is.active && (WiFi.status() == WL_CONNECTED) && !espClient.connected()) APRS_IS_Utils::connect(); #endif @@ -191,10 +191,10 @@ void loop() { } } - if (Config.aprs_is.active) { // If APRSIS enabled + if (Config.aprs_is.active) { APRS_IS_Utils::listenAPRSIS(); // listen received packet from APRSIS } - + STATION_Utils::processOutputPacketBuffer(); displayShow(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0); diff --git a/src/aprs_is_utils.cpp b/src/aprs_is_utils.cpp index 43cefc3a..06436807 100644 --- a/src/aprs_is_utils.cpp +++ b/src/aprs_is_utils.cpp @@ -22,7 +22,8 @@ extern String seventhLine; extern bool modemLoggedToAPRSIS; extern bool backUpDigiMode; -uint32_t lastRxTime = millis(); +uint32_t lastRxTime = millis(); +bool passcodeValid = false; #ifdef HAS_A7670 extern bool stationBeacon; @@ -50,11 +51,9 @@ namespace APRS_IS_Utils { } if (count == 20) { Serial.println("Tried: " + String(count) + " FAILED!"); - } - else { + } else { Serial.println("Connected!\n(Server: " + String(Config.aprs_is.server) + " / Port: " + String(Config.aprs_is.port) + ")"); // String filter = "t/m/" + Config.callsign + "/" + (String)Config.aprs_is.reportingDistance; - String aprsAuth = "user "; aprsAuth += Config.callsign; aprsAuth += " pass "; @@ -62,7 +61,6 @@ namespace APRS_IS_Utils { aprsAuth += " vers CA2RXU_LoRa_iGate 2.0 filter "; aprsAuth += Config.aprs_is.filter; upload(aprsAuth); - delay(200); } } @@ -174,7 +172,7 @@ namespace APRS_IS_Utils { } void processLoRaPacket(const String& packet) { - if (espClient.connected() || modemLoggedToAPRSIS) { + if (passcodeValid && (espClient.connected() || modemLoggedToAPRSIS)) { if (packet != "") { if ((packet.substring(0, 3) == "\x3c\xff\x01") && (packet.indexOf("NOGATE") == -1) && (packet.indexOf("RFONLY") == -1)) { int firstColonIndex = packet.indexOf(":"); @@ -259,13 +257,22 @@ namespace APRS_IS_Utils { } void processAPRSISPacket(const String& packet) { - if (!packet.startsWith("#")) { + if (!passcodeValid && packet.indexOf(Config.callsign) != -1) { + if (packet.indexOf("unverified") != -1 ) { + Serial.println("\n****APRS PASSCODE NOT VALID****\n"); + displayShow(firstLine, "", " APRS PASSCODE", " NOT VALID !!!", "", "", "", 0); + while (1) {}; + } else if (packet.indexOf("verified") != -1 ) { + passcodeValid = true; + } + } + if (passcodeValid && !packet.startsWith("#")) { if (Config.aprs_is.messagesToRF && packet.indexOf("::") > 0) { String Sender = packet.substring(0, packet.indexOf(">")); const String& AddresseeAndMessage = packet.substring(packet.indexOf("::") + 2); String Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":")); Addressee.trim(); - if (Addressee == Config.callsign) { // its for me! + if (Addressee == Config.callsign) { // its for me! String receivedMessage; if (AddresseeAndMessage.indexOf("{") > 0) { // ack? String ackMessage = "ack"; @@ -350,4 +357,13 @@ namespace APRS_IS_Utils { #endif } + void firstConnection() { + if (Config.aprs_is.active && (WiFi.status() == WL_CONNECTED) && !espClient.connected()) { + connect(); + while (!passcodeValid) { + listenAPRSIS(); + } + } + } + } \ No newline at end of file diff --git a/src/utils.cpp b/src/utils.cpp index 665b0439..5d764054 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -37,12 +37,13 @@ extern int wxModuleType; extern bool backUpDigiMode; extern bool shouldSleepLowVoltage; extern bool transmitFlag; +extern bool passcodeValid; extern std::vector lastHeardStations; bool statusAfterBoot = true; bool sendStartTelemetry = true; -bool beaconUpdate = true; +bool beaconUpdate = false; uint32_t lastBeaconTx = 0; uint32_t lastScreenOn = millis(); String beaconPacket; @@ -185,7 +186,7 @@ namespace Utils { void checkBeaconInterval() { uint32_t lastTx = millis() - lastBeaconTx; - if (lastBeaconTx == 0 || lastTx >= Config.beacon.interval * 60 * 1000) { + if (passcodeValid && (lastBeaconTx == 0 || lastTx >= Config.beacon.interval * 60 * 1000)) { beaconUpdate = true; }