diff --git a/data/igate_conf.json b/data/igate_conf.json index 767bb1c..805a986 100644 --- a/data/igate_conf.json +++ b/data/igate_conf.json @@ -1,7 +1,8 @@ { "callsign": "CD2RXU-10", - "stationMode": 1, - "comment": "LoRa_APRS_iGate", + "stationMode": 3, + "iGateComment": "LoRa_APRS_iGate", + "digirepeaterComment": "LoRa_APRS_Digirepeater" , "wifi": { "AP": [ { "SSID": "Richon", @@ -26,7 +27,7 @@ "reportingDistance": 30 }, "lora": { - "frequencyTx": 433775000, + "frequencyTx": 433900000, "frequencyRx": 433775000, "spreadingFactor": 12, "signalBandwidth": 125000, diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index d603326..c83f4a2 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -102,7 +102,7 @@ void checkReceivedPacket(String packet) { } } } else { - Serial.println(" ---> LoRa Packet Ignored (by first 3 bytes of by TCPIP/NOGATE/RFONLY)\n"); + Serial.println(" ---> LoRa Packet Ignored (first 3 bytes or TCPIP/NOGATE/RFONLY)\n"); } } @@ -112,7 +112,7 @@ void setup() { setup_display(); Serial.println("\nStarting iGate: " + Config.callsign + " Version: " + String(VERSION)); show_display(" LoRa APRS iGate", " Richonguzman", " -- CD2RXU --", " " VERSION, 4000); - utils::validateMode(stationMode); + WIFI_Utils::validateMode(stationMode); iGateBeaconPacket = GPS_Utils::generateBeacon(); LoRa_Utils::setup(); @@ -133,6 +133,20 @@ void setup() { void loop() { if (stationMode==3 || stationMode==4) { // DigiRepeater Mode / No backUpMode secondLine = ""; + uint32_t lastBeaconTx = millis() - lastTxTime; + if (lastBeaconTx >= Config.beaconInterval*60*1000) { + beacon_update = true; + } + if (beacon_update) { + thirdLine = ""; + show_display(firstLine, secondLine, thirdLine, "SENDING iGate BEACON", 0); + fourthLine = " listening..."; + Serial.println("---- Sending iGate Beacon ----"); + //Serial.println(iGateBeaconPacket); + //LoRa_Utils::sendNewPacket("APRS",iGateBeaconPacket); + lastTxTime = millis(); + beacon_update = false; + } show_display(firstLine, secondLine, thirdLine, fourthLine, 0); DIGI_Utils::process(LoRa_Utils::receivePacket()); } else if (stationMode==1 || stationMode==2 ) { // standard iGate Mode (No DigiRepeater) @@ -157,8 +171,6 @@ void loop() { display_toggle(false); } } - thirdLine = ""; - fourthLine = ""; if (!Config.display.keepLastPacketOnScreen) { show_display(firstLine, secondLine, thirdLine, fourthLine, 0); } @@ -175,6 +187,8 @@ void loop() { lastTxTime = millis(); lastRxTxTime = millis(); show_display(firstLine, secondLine, thirdLine, "SENDING iGate BEACON", 1000); + thirdLine = ""; + fourthLine = " listening..."; show_display(firstLine, secondLine, thirdLine, fourthLine, 0); beacon_update = false; } diff --git a/src/configuration.cpp b/src/configuration.cpp index c802f64..bdfc1ed 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -31,7 +31,8 @@ void Configuration::readFile(fs::FS &fs, const char *fileName) { callsign = data["callsign"].as(); stationMode = data["stationMode"].as(); - comment = data["comment"].as(); + iGateComment = data["iGateComment"].as(); + digirepeaterComment = data["digirepeaterComment"].as(); beaconInterval = data["other"]["beaconInterval"].as(); rememberStationTime = data["other"]["rememberStationTime"].as(); statusAfterBoot = data["other"]["statusAfterBoot"].as(); diff --git a/src/configuration.h b/src/configuration.h index 6237e75..27f93d6 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -49,7 +49,8 @@ public: String callsign; int stationMode; - String comment; + String iGateComment; + String digirepeaterComment; int beaconInterval; int rememberStationTime; bool statusAfterBoot; diff --git a/src/digi_utils.cpp b/src/digi_utils.cpp index 8525803..4b3037b 100644 --- a/src/digi_utils.cpp +++ b/src/digi_utils.cpp @@ -1,8 +1,7 @@ #include "digi_utils.h" #include "configuration.h" -/*#include +#include "lora_utils.h" -#include "display.h"*/ extern Configuration Config; extern String thirdLine; @@ -31,29 +30,27 @@ void typeOfPacket(String packet) { void process(String packet) { String firstPart, lastPart; if (packet != "") { - Serial.println("Received Lora Packet : " + String(packet)); - if (packet.substring(0, 3) == "\x3c\xff\x01") { - if ((packet.indexOf("TCPIP") == -1) && (packet.indexOf("NOGATE") == -1) && (packet.indexOf("RFONLY") == -1) && (packet.indexOf("WIDE1-1") > 10)) { - Serial.println("---> APRS LoRa Packet: Tracker --> iGate"); - typeOfPacket(packet); - firstPart = packet.substring(0,packet.indexOf(",")+1); - lastPart = packet.substring(packet.indexOf(":")); - - //Serial.println(firstPart); - //Serial.println(lastPart); - Serial.println(firstPart + Config.callsign + lastPart); - - } else if ((packet.indexOf("TCPIP") == -1) && (packet.indexOf("NOGATE") == -1) && (packet.indexOf("RFONLY") > 10)) { - Serial.println("---> APRS LoRa Packet: iGate --> Tracker"); - typeOfPacket(packet); - } else if ((packet.indexOf("TCPIP") > 5) && (packet.indexOf("NOGATE") == -1) && (packet.indexOf("RFONLY") == -1)) { - Serial.println("---> APRS LoRa Packet: APRSIS (iGate) --> Tracker"); - typeOfPacket(packet); - } else { - Serial.println("Packet ignored because iGate Configuration(.json)"); + Serial.print("Received Lora Packet : " + String(packet)); + if ((packet.substring(0, 3) == "\x3c\xff\x01") && (packet.indexOf("NOGATE") == -1) && (packet.indexOf("WIDE1-1") > 10)) { // confirmar lo de WIDE1-1 !!! + Serial.println(" ---> APRS LoRa Packet"); + typeOfPacket(packet); + firstPart = packet.substring(3,packet.indexOf(",")+1); + lastPart = packet.substring(packet.indexOf(":")); + Serial.println(firstPart + Config.callsign + lastPart); + if (stationMode == 3) { + delay(8000);// quizas no es necesario esperar tanto? + //LoRa_Utils::sendNewPacket("APRS", firstPart + Config.callsign + lastPart); + Serial.print("repitiendo/Tx mensaje truncado"); + LoRa_Utils::sendNewPacket("APRS", firstPart + Config.callsign + lastPart + Config.iGateComment); // test porque esta truncado + } else { // enviar con != freq + delay(8000); + Serial.print("repitiendo/Tx mensaje otra frecuencia"); + LoRa_Utils::changeFreqTx(); + LoRa_Utils::sendNewPacket("APRS", firstPart + Config.callsign + lastPart + "1"); + LoRa_Utils::changeFreqRx(); } } else { - Serial.println("---> Not APRS Packet (Ignore)\n"); + Serial.println(" ---> LoRa Packet Ignored (first 3 bytes or NOGATE)\n"); } } /*void checkReceivedPacket(String packet) { diff --git a/src/gps_utils.cpp b/src/gps_utils.cpp index f2f8235..f7faf2e 100644 --- a/src/gps_utils.cpp +++ b/src/gps_utils.cpp @@ -75,15 +75,17 @@ String processLongitudeAPRS() { String generateBeacon() { String iGateLat = processLatitudeAPRS(); String iGateLon = processLongitudeAPRS(); - String beaconPacket = Config.callsign + ">APLRG1,qAC:="; + String beaconPacket = Config.callsign + ">APLRG1"; if (stationMode == 1) { - beaconPacket += iGateLat + "L" + iGateLon + "&"; + beaconPacket += ",qAC:=" +iGateLat + "L" + iGateLon + "&"; + beaconPacket += Config.iGateComment; } else if (stationMode == 2 || stationMode == 5) { - beaconPacket += iGateLat + "L" + iGateLon + "a"; - } else if (stationMode >=3 && stationMode <= 4) { - beaconPacket += iGateLat + "L" + iGateLon + "#"; + beaconPacket += ",qAC:=" + iGateLat + "L" + iGateLon + "a"; + beaconPacket += Config.iGateComment; + } else if (stationMode ==3 || stationMode == 4) { + beaconPacket += ":=" + iGateLat + "L" + iGateLon + "#"; + beaconPacket += Config.digirepeaterComment; } - beaconPacket += Config.comment; return beaconPacket; } diff --git a/src/lora_utils.cpp b/src/lora_utils.cpp index 6097833..f3e9acd 100644 --- a/src/lora_utils.cpp +++ b/src/lora_utils.cpp @@ -9,7 +9,7 @@ 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.frequencyTx)) { + if (!LoRa.begin(Config.loramodule.frequencyRx)) { Serial.println("Starting LoRa failed!"); show_display("ERROR", "Starting LoRa failed!"); while (true) { @@ -59,4 +59,28 @@ String receivePacket() { return loraPacket; } +void changeFreqTx() { + if (!LoRa.begin(Config.loramodule.frequencyTx)) { + Serial.println("Starting LoRa failed!"); + show_display("ERROR", "Starting LoRa failed!"); + while (true) { + delay(1000); + } + } else { + Serial.println("cambiando frecuencia Tx = " + String(Config.loramodule.frequencyTx)); + } +} + +void changeFreqRx() { + if (!LoRa.begin(Config.loramodule.frequencyRx)) { + Serial.println("Starting LoRa failed!"); + show_display("ERROR", "Starting LoRa failed!"); + while (true) { + delay(1000); + } + } else { + Serial.println("cambiando frecuencia Rx = " + String(Config.loramodule.frequencyRx)); + } +} + } \ No newline at end of file diff --git a/src/lora_utils.h b/src/lora_utils.h index 5b3b347..b404b3b 100644 --- a/src/lora_utils.h +++ b/src/lora_utils.h @@ -9,6 +9,8 @@ void setup(); void sendNewPacket(const String &typeOfMessage, const String &newPacket); String generatePacket(String aprsisPacket); String receivePacket(); +void changeFreqTx(); +void changeFreqRx(); } diff --git a/src/utils.cpp b/src/utils.cpp index e0b0085..8f9f835 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -10,30 +10,9 @@ extern bool statusAfterBoot; namespace utils { -void validateMode(int mode) { - if (mode == 1 || mode == 2 || mode == 5) { - if (mode==1) { - Serial.println("stationMode ---> iGate (only Rx)"); - } else { - Serial.println("stationMode ---> iGate (Rx + Tx)"); - } - WIFI_Utils::setup(); - 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'"); - while (1); - } -} - - void processStatus() { delay(1000); - String startupStatus = Config.callsign + ">APLRG1,qAC:>" + Config.defaultStatus; - espClient.write((startupStatus + "\n").c_str()); + espClient.write((Config.callsign + ">APLRG1,qAC:>" + Config.defaultStatus + "\n").c_str()); statusAfterBoot = false; } diff --git a/src/utils.h b/src/utils.h index 4a8fd33..b29bd57 100644 --- a/src/utils.h +++ b/src/utils.h @@ -5,7 +5,6 @@ namespace utils { -void validateMode(int mode); void processStatus(); } diff --git a/src/wifi_utils.cpp b/src/wifi_utils.cpp index 4244428..fd7d3bf 100644 --- a/src/wifi_utils.cpp +++ b/src/wifi_utils.cpp @@ -10,7 +10,7 @@ extern int myWiFiAPSize; namespace WIFI_Utils { -void setup() { +void setupWiFi() { int status = WL_IDLE_STATUS; WiFi.mode(WIFI_STA); WiFi.disconnect(); @@ -39,4 +39,23 @@ void setup() { Serial.println(WiFi.localIP()); } +void validateMode(int mode) { + if (mode == 1 || mode == 2 || mode == 5) { + if (mode==1) { + Serial.println("stationMode ---> iGate (only Rx)"); + } else { + Serial.println("stationMode ---> iGate (Rx + Tx)"); + } + setupWiFi(); + 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'"); + while (1); + } +} + } \ No newline at end of file diff --git a/src/wifi_utils.h b/src/wifi_utils.h index 235c84a..aaa9449 100644 --- a/src/wifi_utils.h +++ b/src/wifi_utils.h @@ -5,7 +5,8 @@ namespace WIFI_Utils { -void setup(); +void setupWiFi(); +void validateMode(int mode); }