diff --git a/data/igate_conf.json b/data/igate_conf.json index 66fff4b..3393aa6 100644 --- a/data/igate_conf.json +++ b/data/igate_conf.json @@ -1,6 +1,6 @@ { "callsign": "CD2RXU-10", - "stationMode": 2, + "stationMode": 4, "iGateComment": "LoRa_APRS_iGate", "digirepeaterComment": "LoRa_APRS_Digirepeater" , "wifi": { @@ -27,8 +27,9 @@ "reportingDistance": 30 }, "lora": { - "frequencyTx": 433900000, - "frequencyRx": 433775000, + "iGateFreq": 433775000, + "digirepeaterTxFreq": 433900000, + "digirepeaterRxFreq": 433775000, "spreadingFactor": 12, "signalBandwidth": 125000, "codingRate4": 5, diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 0510df3..612d0ff 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -45,9 +45,11 @@ void setup() { utils::setupDiplay(); Serial.println("\nStarting iGate: " + Config.callsign + " Version: " + String(VERSION)); show_display(" LoRa APRS iGate", " Richonguzman", " -- CD2RXU --", " " VERSION, 4000); - WIFI_Utils::validateMode(stationMode); - iGateBeaconPacket = GPS_Utils::generateBeacon(); + WIFI_Utils::setup(); LoRa_Utils::setup(); + utils::validateDigiFreqs(); + iGateBeaconPacket = GPS_Utils::generateBeacon(); + /*server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) { request->send(200, "text/plain", "Hi! I am ESP32."); }); @@ -62,9 +64,9 @@ void loop() { utils::checkBeaconInterval(); show_display(firstLine, secondLine, thirdLine, fourthLine, 0); DIGI_Utils::processPacket(LoRa_Utils::receivePacket()); - if (statusAfterBoot) { + /*if (statusAfterBoot) { utils::processStatus(); - } + }*/ } else if (stationMode==1 || stationMode==2 ) { // iGate (1 Only Rx / 2 Rx+Tx) unsigned long currentWiFiMillis = millis(); if ((WiFi.status() != WL_CONNECTED) && (currentWiFiMillis - previousWiFiMillis >= currentWiFi->checkInterval*1000)) { @@ -139,13 +141,9 @@ void loop() { } } } - if (statusAfterBoot) { + /*if (statusAfterBoot) { utils::processStatus(); - } + }*/ } - } else { - Serial.println(stationMode); - // stationMode = 5 - // this mode is only for when iGate loses Wifi and transforms into Digirepeater } } \ No newline at end of file diff --git a/src/configuration.cpp b/src/configuration.cpp index f1febf3..b4618d4 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -46,8 +46,9 @@ void Configuration::readFile(fs::FS &fs, const char *fileName) { aprs_is.softwareVersion = data["aprs_is"]["softwareVersion"].as(); aprs_is.reportingDistance = data["aprs_is"]["reportingDistance"].as(); - loramodule.frequencyTx = data["lora"]["frequencyTx"].as(); - loramodule.frequencyRx = data["lora"]["frequencyRx"].as(); + loramodule.iGateFreq = data["lora"]["iGateFreq"].as(); + loramodule.digirepeaterTxFreq = data["lora"]["digirepeaterTxFreq"].as(); + loramodule.digirepeaterRxFreq = data["lora"]["digirepeaterRxFreq"].as(); loramodule.spreadingFactor = data["lora"]["spreadingFactor"].as(); loramodule.signalBandwidth = data["lora"]["signalBandwidth"].as(); loramodule.codingRate4 = data["lora"]["codingRate4"].as(); diff --git a/src/configuration.h b/src/configuration.h index a1a6ca6..5deef77 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -29,8 +29,9 @@ public: class LoraModule { public: - long frequencyTx; - long frequencyRx; + long iGateFreq; + long digirepeaterTxFreq; + long digirepeaterRxFreq; int spreadingFactor; long signalBandwidth; int codingRate4; diff --git a/src/digi_utils.cpp b/src/digi_utils.cpp index 2957ddd..2f30450 100644 --- a/src/digi_utils.cpp +++ b/src/digi_utils.cpp @@ -37,7 +37,7 @@ void processPacket(String packet) { typeOfPacket(packet); firstPart = packet.substring(3,packet.indexOf(",")+1); lastPart = packet.substring(packet.indexOf(":")); - Serial.println(firstPart + Config.callsign + lastPart); + Serial.println(firstPart + Config.callsign + "*" + lastPart); delay(500); if (stationMode == 4) { // Digirepeating with Freq Rx != Tx LoRa_Utils::changeFreqTx(); diff --git a/src/lora_utils.cpp b/src/lora_utils.cpp index e1f6c51..5674a42 100644 --- a/src/lora_utils.cpp +++ b/src/lora_utils.cpp @@ -2,14 +2,21 @@ #include "configuration.h" #include "display.h" -extern Configuration Config; +extern Configuration Config; +extern int stationMode; namespace LoRa_Utils { void setup() { SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS); LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ); - if (!LoRa.begin(Config.loramodule.frequencyRx)) { + long freq; + if (stationMode == 1 || stationMode == 2) { + freq = Config.loramodule.iGateFreq; + } else { + freq = Config.loramodule.digirepeaterTxFreq; + } + if (!LoRa.begin(freq)) { Serial.println("Starting LoRa failed!"); show_display("ERROR", "Starting LoRa failed!"); while (true) { @@ -61,14 +68,12 @@ String receivePacket() { void changeFreqTx() { delay(500); - LoRa.setFrequency(Config.loramodule.frequencyTx); - //Serial.println("changing LoRa Freq to " + String(Config.loramodule.frequencyTx)); + LoRa.setFrequency(Config.loramodule.digirepeaterTxFreq); } void changeFreqRx() { delay(500); - LoRa.setFrequency(Config.loramodule.frequencyRx); - //Serial.println("changing LoRa Freq to = " + String(Config.loramodule.frequencyRx)); + LoRa.setFrequency(Config.loramodule.digirepeaterRxFreq); } } \ No newline at end of file diff --git a/src/utils.cpp b/src/utils.cpp index 8ee293b..b5b0c9b 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -29,7 +29,13 @@ void processStatus() { } else { delay(5000); status += ":>" + Config.defaultStatus; + if (stationMode == 4) { // Digirepeating with Freq Rx != Tx + LoRa_Utils::changeFreqTx(); + } LoRa_Utils::sendNewPacket("APRS", status); + if (stationMode == 4) { + LoRa_Utils::changeFreqRx(); + } } statusAfterBoot = false; } @@ -55,20 +61,29 @@ void checkBeaconInterval() { display_toggle(true); thirdLine = ""; Serial.println("---- Sending iGate Beacon ----"); - if (stationMode==3 || stationMode==4) { - show_display(firstLine, secondLine, thirdLine, "SENDING iGate BEACON", 0); - fourthLine = " listening..."; - LoRa_Utils::sendNewPacket("APRS",iGateBeaconPacket); - } else if (stationMode==1 || stationMode==2) { + if (stationMode==1 || stationMode==2) { show_display(firstLine, secondLine, thirdLine, "SENDING iGate BEACON", 1000); fourthLine = " listening..."; espClient.write((iGateBeaconPacket + "\n").c_str()); show_display(firstLine, secondLine, thirdLine, fourthLine, 0); + } else if (stationMode==3 || stationMode==4) { + show_display(firstLine, secondLine, thirdLine, "SENDING iGate BEACON", 0); + fourthLine = " listening..."; + if (stationMode == 4) { // Digirepeating with Freq Rx != Tx + LoRa_Utils::changeFreqTx(); + } + LoRa_Utils::sendNewPacket("APRS",iGateBeaconPacket); + if (stationMode == 4) { + LoRa_Utils::changeFreqRx(); + } } lastBeaconTx = millis(); lastScreenOn = millis(); beacon_update = false; } + if (statusAfterBoot) { + processStatus(); + } } void checkDisplayInterval() { @@ -80,4 +95,14 @@ void checkDisplayInterval() { } } +void validateDigiFreqs() { + if (stationMode == 4) { + if (abs(Config.loramodule.digirepeaterTxFreq - Config.loramodule.digirepeaterRxFreq) < 125000) { + Serial.println("Tx Freq less than 125kHz from Rx Freq ---> NOT VALID, check 'data/igate_conf.json'"); + show_display("Tx Freq is less than ", "125kHz from Rx Freq", "change it on : /data/", "igate_conf.json", 0); + while (1); + } + } +} + } \ No newline at end of file diff --git a/src/utils.h b/src/utils.h index 58491a6..f2ce568 100644 --- a/src/utils.h +++ b/src/utils.h @@ -9,6 +9,7 @@ void processStatus(); void setupDiplay(); void checkBeaconInterval(); void checkDisplayInterval(); +void validateDigiFreqs(); } diff --git a/src/wifi_utils.cpp b/src/wifi_utils.cpp index 98602ae..072709d 100644 --- a/src/wifi_utils.cpp +++ b/src/wifi_utils.cpp @@ -7,10 +7,11 @@ extern Configuration Config; extern WiFi_AP *currentWiFi; extern int myWiFiAPIndex; extern int myWiFiAPSize; +extern int stationMode; namespace WIFI_Utils { -void setupWiFi() { +void startWiFi() { int status = WL_IDLE_STATUS; WiFi.mode(WIFI_STA); WiFi.disconnect(); @@ -39,21 +40,26 @@ void setupWiFi() { Serial.println(WiFi.localIP()); } -void validateMode(int mode) { - if (mode == 1 || mode == 2 || mode == 5) { - if (mode==1) { +void setup() { + if (stationMode == 1 || stationMode == 2) { + if (stationMode==1) { Serial.println("stationMode ---> iGate (only Rx)"); } else { Serial.println("stationMode ---> iGate (Rx + Tx)"); } - setupWiFi(); + startWiFi(); + btStop(); + } else if (stationMode == 3 || stationMode == 4) { + if (stationMode == 3) { + Serial.println("stationMode ---> DigiRepeater (Rx freq == Tx freq)"); + } else { + Serial.println("stationMode ---> DigiRepeater (Rx freq != Tx freq)"); + } + WiFi.mode(WIFI_OFF); btStop(); - } else if (mode == 3) { - Serial.println("stationMode ---> DigiRepeater (Rx freq == Tx freq)"); - } else if (mode == 4) { - Serial.println("stationMode ---> DigiRepeater (Rx freq != Tx freq)"); } else { - Serial.println("stationMode ---> NOT VALID, check 'data/igate_conf.json'"); + Serial.println("stationMode ---> NOT VALID, check '/data/igate_conf.json'"); + show_display("stationMode Not Valid", "change it on : /data/", "igate_conf.json", 0); while (1); } } diff --git a/src/wifi_utils.h b/src/wifi_utils.h index aaa9449..5615562 100644 --- a/src/wifi_utils.h +++ b/src/wifi_utils.h @@ -5,8 +5,8 @@ namespace WIFI_Utils { -void setupWiFi(); -void validateMode(int mode); +void startWiFi(); +void setup(); }