From d334164b6fdaec694e71fc1e482f91e726ca46e3 Mon Sep 17 00:00:00 2001 From: richonguzman Date: Sat, 11 Oct 2025 18:27:06 -0300 Subject: [PATCH] Beacon Freq on Digi Mode --- data/igate_conf.json | 3 ++- data_embed/index.html | 15 +++++++++++++++ data_embed/script.js | 1 + include/configuration.h | 1 + include/station_utils.h | 8 +------- include/utils.h | 2 +- src/configuration.cpp | 6 +++++- src/lora_utils.cpp | 9 +++++++-- src/station_utils.cpp | 39 +++++++++++++++++++++++++++++++-------- src/utils.cpp | 6 +++--- src/web_utils.cpp | 1 + 11 files changed, 68 insertions(+), 23 deletions(-) diff --git a/data/igate_conf.json b/data/igate_conf.json index 04a4bda..30c4ec6 100644 --- a/data/igate_conf.json +++ b/data/igate_conf.json @@ -35,7 +35,8 @@ "blacklist": "", "digi": { "mode": 0, - "ecoMode": 0 + "ecoMode": 0, + "beaconOnRxFreq": false }, "lora": { "txFreq": 433775000, diff --git a/data_embed/index.html b/data_embed/index.html index bae333e..1fbdbcf 100644 --- a/data_embed/index.html +++ b/data_embed/index.html @@ -716,6 +716,21 @@ +
+
+ + +
+
diff --git a/data_embed/script.js b/data_embed/script.js index b6bf231..1392ebb 100644 --- a/data_embed/script.js +++ b/data_embed/script.js @@ -134,6 +134,7 @@ function loadSettings(settings) { // Digi document.getElementById("digi.mode").value = settings.digi.mode; document.getElementById("digi.ecoMode").value = settings.digi.ecoMode; + document.getElementById("digi.beaconOnRxFreq").value = settings.digi.beaconOnRxFreq; // LoRa document.getElementById("lora.txFreq").value = settings.lora.txFreq; diff --git a/include/configuration.h b/include/configuration.h index 85e9c4b..4e6043a 100644 --- a/include/configuration.h +++ b/include/configuration.h @@ -68,6 +68,7 @@ class DIGI { public: int mode; int ecoMode; // 0 = Not Active | 1 = Ultra EcoMode | 2 = Not Active (WiFi OFF, Serial ON) + bool beaconOnRxFreq; }; class LoraModule { diff --git a/include/station_utils.h b/include/station_utils.h index 2c49139..af606de 100644 --- a/include/station_utils.h +++ b/include/station_utils.h @@ -23,12 +23,6 @@ #include -struct Packet25SegBuffer { - uint32_t receivedTime; - String station; - String payload; -}; - struct LastHeardStation { uint32_t lastHeardTime; String station; @@ -47,7 +41,7 @@ namespace STATION_Utils { bool check25SegBuffer(const String& station, const String& textMessage); void processOutputPacketBufferUltraEcoMode(); void processOutputPacketBuffer(); - void addToOutputPacketBuffer(const String& packet); + void addToOutputPacketBuffer(const String& packet, bool flag = false); } diff --git a/include/utils.h b/include/utils.h index aef0293..9b69cdb 100644 --- a/include/utils.h +++ b/include/utils.h @@ -35,7 +35,7 @@ namespace Utils { void processStatus(); String getLocalIP(); void setupDisplay(); - void activeStations(); + void showActiveStations(); void checkBeaconInterval(); void checkDisplayInterval(); void validateFreqs(); diff --git a/src/configuration.cpp b/src/configuration.cpp index de31de8..c0b5d0c 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -85,6 +85,7 @@ bool Configuration::writeFile() { #if defined(HAS_A7670) if (digi.ecoMode == 1) data["digi"]["ecoMode"] = 2; #endif + data["digi"]["beaconOnRxFreq"] = digi.beaconOnRxFreq; data["lora"]["rxFreq"] = loramodule.rxFreq; data["lora"]["txFreq"] = loramodule.txFreq; @@ -242,10 +243,12 @@ bool Configuration::readFile() { blacklist = data["blacklist"] | "station callsign"; if (!data["digi"].containsKey("mode") || - !data["digi"].containsKey("ecoMode")) needsRewrite = true; + !data["digi"].containsKey("ecoMode") || + !data["digi"].containsKey("beaconOnRxFreq")) needsRewrite = true; digi.mode = data["digi"]["mode"] | 0; digi.ecoMode = data["digi"]["ecoMode"] | 0; if (digi.ecoMode == 1) shouldSleepStop = false; + digi.beaconOnRxFreq = data["digi"]["beaconOnRxFreq"] | false; #if defined(HAS_A7670) if (digi.ecoMode == 1) digi.ecoMode = 2; @@ -433,6 +436,7 @@ void Configuration::setDefaultValues() { digi.mode = 0; digi.ecoMode = 0; + digi.beaconOnRxFreq = false; loramodule.txFreq = 433775000; loramodule.rxFreq = 433775000; diff --git a/src/lora_utils.cpp b/src/lora_utils.cpp index 164d655..52e6e51 100644 --- a/src/lora_utils.cpp +++ b/src/lora_utils.cpp @@ -30,6 +30,7 @@ extern Configuration Config; extern uint32_t lastRxTime; +extern bool packetIsBeacon; extern std::vector receivedPackets; @@ -143,7 +144,9 @@ namespace LoRa_Utils { if (!Config.loramodule.txActive) return; if (Config.loramodule.txFreq != Config.loramodule.rxFreq) { - changeFreqTx(); + if (!packetIsBeacon || (packetIsBeacon && !Config.digi.beaconOnRxFreq)) { + changeFreqTx(); + } } #ifdef INTERNAL_LED_PIN @@ -165,7 +168,9 @@ namespace LoRa_Utils { if (Config.digi.ecoMode != 1) digitalWrite(INTERNAL_LED_PIN, LOW); // disabled in Ultra Eco Mode #endif if (Config.loramodule.txFreq != Config.loramodule.rxFreq) { - changeFreqRx(); + if (!packetIsBeacon || (packetIsBeacon && !Config.digi.beaconOnRxFreq)) { + changeFreqRx(); + } } } diff --git a/src/station_utils.cpp b/src/station_utils.cpp index 79530eb..86b5eae 100644 --- a/src/station_utils.cpp +++ b/src/station_utils.cpp @@ -33,13 +33,26 @@ extern bool shouldSleepLowVoltage; uint32_t lastTxTime = millis(); std::vector lastHeardStations; -std::vector outputPacketBuffer; -std::vector packet25SegBuffer; std::vector blacklist; std::vector managers; std::vector lastHeardObjects; +struct OutputPacketBuffer { + String packet; + bool isBeacon; +}; +std::vector outputPacketBuffer; + +struct Packet25SegBuffer { + uint32_t receivedTime; + String station; + String payload; +}; +std::vector packet25SegBuffer; + + bool saveNewDigiEcoModeConfig = false; +bool packetIsBeacon = false; namespace STATION_Utils { @@ -138,7 +151,7 @@ namespace STATION_Utils { } } if (!stationHeard) lastHeardStations.emplace_back(LastHeardStation{millis(), station}); - Utils::activeStations(); + Utils::showActiveStations(); } bool wasHeard(const String& station) { @@ -171,7 +184,9 @@ namespace STATION_Utils { size_t currentIndex = 0; while (currentIndex < outputPacketBuffer.size()) { // this sends all packets from output buffer delay(3000); // and cleans buffer to avoid sending packets with time offset - LoRa_Utils::sendNewPacket(outputPacketBuffer[currentIndex]); // next time it wakes up + if (outputPacketBuffer[currentIndex].isBeacon) packetIsBeacon = true; + LoRa_Utils::sendNewPacket(outputPacketBuffer[currentIndex].packet); // next time it wakes up + if (outputPacketBuffer[currentIndex].isBeacon) packetIsBeacon = false; currentIndex++; } outputPacketBuffer.clear(); @@ -190,13 +205,17 @@ namespace STATION_Utils { uint32_t lastRx = millis() - lastRxTime; uint32_t lastTx = millis() - lastTxTime; if (outputPacketBuffer.size() > 0 && lastTx > timeToWait && lastRx > timeToWait) { - LoRa_Utils::sendNewPacket(outputPacketBuffer[0]); + if (outputPacketBuffer[0].isBeacon) packetIsBeacon = true; + LoRa_Utils::sendNewPacket(outputPacketBuffer[0].packet); + if (outputPacketBuffer[0].isBeacon) packetIsBeacon = false; outputPacketBuffer.erase(outputPacketBuffer.begin()); lastTxTime = millis(); } if (shouldSleepLowVoltage) { while (outputPacketBuffer.size() > 0) { - LoRa_Utils::sendNewPacket(outputPacketBuffer[0]); + if (outputPacketBuffer[0].isBeacon) packetIsBeacon = true; + LoRa_Utils::sendNewPacket(outputPacketBuffer[0].packet); + if (outputPacketBuffer[0].isBeacon) packetIsBeacon = false; outputPacketBuffer.erase(outputPacketBuffer.begin()); delay(4000); } @@ -209,8 +228,12 @@ namespace STATION_Utils { } } - void addToOutputPacketBuffer(const String& packet) { - outputPacketBuffer.push_back(packet); + void addToOutputPacketBuffer(const String& packet, bool flag) { + OutputPacketBuffer entry; + entry.packet = packet; + entry.isBeacon = flag; + + outputPacketBuffer.push_back(entry); } } \ No newline at end of file diff --git a/src/utils.cpp b/src/utils.cpp index 1cc1e95..041a842 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -127,7 +127,7 @@ namespace Utils { seventhLine = " listening..."; } - void activeStations() { + void showActiveStations() { char buffer[30]; // Adjust size as needed sprintf(buffer, "Stations (%dmin) = %2d", Config.rememberStationTime, lastHeardStations.size()); fourthLine = buffer; @@ -159,7 +159,7 @@ namespace Utils { STATION_Utils::deleteNotHeard(); - activeStations(); + showActiveStations(); beaconPacket = iGateBeaconPacket; secondaryBeaconPacket = iGateLoRaBeaconPacket; @@ -259,7 +259,7 @@ namespace Utils { Utils::println("-- Sending Beacon to RF --"); displayShow(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING DIGI BEACON", 0); seventhLine = " listening..."; - STATION_Utils::addToOutputPacketBuffer(secondaryBeaconPacket); + STATION_Utils::addToOutputPacketBuffer(secondaryBeaconPacket, true); } lastBeaconTx = millis(); diff --git a/src/web_utils.cpp b/src/web_utils.cpp index 1e32c0d..5283240 100644 --- a/src/web_utils.cpp +++ b/src/web_utils.cpp @@ -196,6 +196,7 @@ namespace WEB_Utils { Config.digi.mode = getParamIntSafe("digi.mode", Config.digi.mode); Config.digi.ecoMode = getParamIntSafe("digi.ecoMode", Config.digi.ecoMode); + Config.digi.beaconOnRxFreq = request->hasParam("digi.beaconOnRxFreq", true); Config.loramodule.txFreq = getParamIntSafe("lora.txFreq", Config.loramodule.txFreq); Config.loramodule.rxFreq = getParamIntSafe("lora.rxFreq", Config.loramodule.rxFreq);