diff --git a/data/igate_conf.json b/data/igate_conf.json index 885111e..d2a74da 100644 --- a/data/igate_conf.json +++ b/data/igate_conf.json @@ -1,5 +1,5 @@ { - "callsign": "CD2RXU-10", + "callsign": "CD2RXU-11", "stationMode": 2, "iGateComment": "LoRa_APRS_iGate", "wifi": { @@ -40,6 +40,11 @@ "alwaysOn": true, "timeout": 4 }, + "syslog": { + "active": true, + "server": "0.0.0.0", + "port": 514 + }, "other": { "beaconInterval": 15, "rememberStationTime": 30 diff --git a/platformio.ini b/platformio.ini index d29d236..1c60d2e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -22,3 +22,4 @@ lib_deps = ayushsharma82/AsyncElegantOTA@^2.2.7 ottowinter/ESPAsyncWebServer-esphome@^3.0.0 esphome/AsyncTCP-esphome@^2.0.0 + mikalhart/TinyGPSPlus @ 1.0.3 diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 62674b5..9c08d0f 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -17,7 +17,7 @@ Configuration Config; WiFiClient espClient; -String versionDate = "2023.06.10"; +String versionDate = "2023.06.11"; int myWiFiAPIndex = 0; int myWiFiAPSize = Config.wifiAPs.size(); WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex]; diff --git a/src/configuration.cpp b/src/configuration.cpp index 664abd7..972078a 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -57,6 +57,10 @@ void Configuration::readFile(fs::FS &fs, const char *fileName) { display.alwaysOn = data["display"]["alwaysOn"].as(); display.timeout = data["display"]["timeout"].as(); + syslog.active = data["syslog"]["active"].as(); + syslog.server = data["syslog"]["server"].as(); + syslog.port = data["syslog"]["port"].as(); + configFile.close(); } diff --git a/src/configuration.h b/src/configuration.h index 9e622ce..82b6738 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -46,6 +46,13 @@ public: int timeout; }; +class SYSLOG { +public: + bool active; + String server; + int port; +}; + class Configuration { public: @@ -59,6 +66,7 @@ public: APRS_IS aprs_is; LoraModule loramodule; Display display; + SYSLOG syslog; Configuration(); diff --git a/src/gps_utils.cpp b/src/gps_utils.cpp index 14eec6f..36c8f71 100644 --- a/src/gps_utils.cpp +++ b/src/gps_utils.cpp @@ -1,3 +1,4 @@ +#include #include "configuration.h" #include "gps_utils.h" @@ -92,4 +93,69 @@ String generateBeacon() { return beaconPacket; } +double calculateDistanceTo(double latitude, double longitude) { + return TinyGPSPlus::distanceBetween(currentWiFi->latitude,currentWiFi->longitude, latitude, longitude) / 1000.0; +} + +String decodeEncodedGPS(String packet) { + String GPSPacket = packet.substring(packet.indexOf(":!/")+3); + String encodedLatitude = GPSPacket.substring(0,4); + String encodedLongtitude = GPSPacket.substring(4,8); + + int Y1 = int(encodedLatitude[0]); + int Y2 = int(encodedLatitude[1]); + int Y3 = int(encodedLatitude[2]); + int Y4 = int(encodedLatitude[3]); + float decodedLatitude = 90.0 - ((((Y1-33) * pow(91,3)) + ((Y2-33) * pow(91,2)) + ((Y3-33) * 91) + Y4-33) / 380926.0); + + int X1 = int(encodedLongtitude[0]); + int X2 = int(encodedLongtitude[1]); + int X3 = int(encodedLongtitude[2]); + int X4 = int(encodedLongtitude[3]); + float decodedLongitude = -180.0 + ((((X1-33) * pow(91,3)) + ((X2-33) * pow(91,2)) + ((X3-33) * 91) + X4-33) / 190463.0); + + return String(decodedLatitude) + "N / " + String(decodedLongitude) + "E / " + String(calculateDistanceTo(decodedLatitude, decodedLongitude)) + "km"; +} + +String getReceivedGPS(String packet) { + String infoGPS; + if (packet.indexOf(":!") > 10) { + infoGPS = packet.substring(packet.indexOf(":!")+2); + } else if (packet.indexOf(":=") > 10) { + infoGPS = packet.substring(packet.indexOf(":=")+2); + } + String Latitude = infoGPS.substring(0,8); + String Longitude = infoGPS.substring(9,18); + + float convertedLatitude, convertedLongitude; + String firstLatPart = Latitude.substring(0,2); + String secondLatPart = Latitude.substring(2,4); + String thirdLatPart = Latitude.substring(Latitude.indexOf(".")+1,Latitude.indexOf(".")+3); + String firstLngPart = Longitude.substring(0,3); + String secondLngPart = Longitude.substring(3,5); + String thirdLngPart = Longitude.substring(Longitude.indexOf(".")+1,Longitude.indexOf(".")+3); + convertedLatitude = firstLatPart.toFloat() + (secondLatPart.toFloat()/60) + (thirdLatPart.toFloat()/(60*100)); + convertedLongitude = firstLngPart.toFloat() + (secondLngPart.toFloat()/60) + (thirdLngPart.toFloat()/(60*100)); + + String LatSign = String(Latitude[7]); + String LngSign = String(Longitude[8]); + if (LatSign == "S") { + convertedLatitude = -convertedLatitude; + } + if (LngSign == "W") { + convertedLongitude = -convertedLongitude; + } + return String(convertedLatitude) + "N / " + String(convertedLongitude) + "E / " + String(calculateDistanceTo(convertedLatitude, convertedLongitude)) + "km"; +} + +String getDistance(String packet) { + if (packet.indexOf(":!/") > 10) { + return decodeEncodedGPS(packet); + } else if (packet.indexOf(":=") > 10 || packet.indexOf(":!") > 10) { + return getReceivedGPS(packet); + } else { + return " _ / _ / _ "; + } +} + } \ No newline at end of file diff --git a/src/gps_utils.h b/src/gps_utils.h index 6df7df8..8dd7390 100644 --- a/src/gps_utils.h +++ b/src/gps_utils.h @@ -9,6 +9,10 @@ String double2string(double n, int ndec); String processLatitudeAPRS(); String processLongitudeAPRS(); String generateBeacon(); +double calculateDistanceCourse(double latitude, double longitude); +String decodeEncodedGPS(String packet); +String getReceivedGPS(String packet); +String getDistance(String packet); } diff --git a/src/lora_utils.cpp b/src/lora_utils.cpp index 4a6253e..95f639a 100644 --- a/src/lora_utils.cpp +++ b/src/lora_utils.cpp @@ -1,6 +1,7 @@ #include #include "configuration.h" #include "pins_config.h" +#include "syslog_utils.h" #include "display.h" extern Configuration Config; @@ -65,6 +66,9 @@ String receivePacket() { int inChar = LoRa.read(); loraPacket += (char)inChar; } + if (Config.syslog.active && (stationMode==1 || stationMode==2)) { + SYSLOG_Utils::processPacket(loraPacket, LoRa.packetRssi(), LoRa.packetSnr(), LoRa.packetFrequencyError()); + } } return loraPacket; } diff --git a/src/syslog_utils.cpp b/src/syslog_utils.cpp new file mode 100644 index 0000000..02367c9 --- /dev/null +++ b/src/syslog_utils.cpp @@ -0,0 +1,20 @@ +#include "syslog_utils.h" +#include "gps_utils.h" + +namespace SYSLOG_Utils { + +void processPacket(String packet, int rssi, float snr, int freqError) { + String syslogPacket; + syslogPacket = packet.substring(3,packet.indexOf(">")) + " / TIME / "; + syslogPacket += packet.substring(packet.indexOf(">")+1,packet.indexOf(",")) + " / "; + if (packet.indexOf("WIDE1-1") > 10) { + syslogPacket += "WIDE1-1 / "; + } else { + syslogPacket += " _ / "; + } + syslogPacket += String(rssi) + "dBm / " + String(snr) + "dB / " + String(freqError) + "Hz / "; + // Callsign / Time / Destination / Path / RSSI / SNR / FreqError /gpsLat / gpsLon / Distance + Serial.println(syslogPacket + GPS_Utils::getDistance(packet)); +} + +} \ No newline at end of file diff --git a/src/syslog_utils.h b/src/syslog_utils.h new file mode 100644 index 0000000..b250ce3 --- /dev/null +++ b/src/syslog_utils.h @@ -0,0 +1,12 @@ +#ifndef SYSLOG_H_ +#define SYSLOG_H_ + +#include + +namespace SYSLOG_Utils { + +void processPacket(String packet, int rssi, float snr, int freqError) ; + +} + +#endif \ No newline at end of file