From b7ba17d871b359e9efa57c07f7e2d32e75d52428 Mon Sep 17 00:00:00 2001 From: richonguzman Date: Mon, 12 Jun 2023 23:36:39 -0400 Subject: [PATCH] test1 --- data/igate_conf.json | 2 +- platformio.ini | 3 +-- src/LoRa_APRS_iGate.cpp | 7 +---- src/lora_utils.cpp | 3 ++- src/syslog_utils.cpp | 59 ++++++++++++++++++++++++++++++----------- src/syslog_utils.h | 2 +- src/utils.cpp | 4 ++- 7 files changed, 52 insertions(+), 28 deletions(-) diff --git a/data/igate_conf.json b/data/igate_conf.json index 4f628d9..cc1a993 100644 --- a/data/igate_conf.json +++ b/data/igate_conf.json @@ -1,6 +1,6 @@ { "callsign": "CD2RXU-11", - "stationMode": 4, + "stationMode": 2, "iGateComment": "LoRa_APRS_iGate", "wifi": { "AP": [ diff --git a/platformio.ini b/platformio.ini index a0810df..3f38ed4 100644 --- a/platformio.ini +++ b/platformio.ini @@ -21,5 +21,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 - peterus/esp-logger @ 1.0.0 \ No newline at end of file + mikalhart/TinyGPSPlus @ 1.0.3 \ No newline at end of file diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index a06bc2e..0c4424d 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -13,16 +13,13 @@ #include "digi_utils.h" #include "gps_utils.h" #include "display.h" -#include "logger.h" #include "utils.h" Configuration Config; WiFiClient espClient; -logging::Logger logger; - -String versionDate = "2023.06.12"; +String versionDate = "2023.06.13"; int myWiFiAPIndex = 0; int myWiFiAPSize = Config.wifiAPs.size(); WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex]; @@ -39,8 +36,6 @@ std::vector lastHeardStation_temp; String firstLine, secondLine, thirdLine, fourthLine, iGateBeaconPacket; -// agregar automatic restart cada X horas? - void setup() { Serial.begin(115200); pinMode(greenLed, OUTPUT); diff --git a/src/lora_utils.cpp b/src/lora_utils.cpp index 95f639a..68a78fe 100644 --- a/src/lora_utils.cpp +++ b/src/lora_utils.cpp @@ -46,6 +46,7 @@ void sendNewPacket(const String &typeOfMessage, const String &newPacket) { LoRa.write((const uint8_t *)newPacket.c_str(), newPacket.length()); LoRa.endPacket(); digitalWrite(greenLed,LOW); + SYSLOG_Utils::log("LoRa Tx", newPacket,0,0,0); Serial.print("---> LoRa Packet Tx : "); Serial.println(newPacket); } @@ -67,7 +68,7 @@ String receivePacket() { loraPacket += (char)inChar; } if (Config.syslog.active && (stationMode==1 || stationMode==2)) { - SYSLOG_Utils::processPacket(loraPacket, LoRa.packetRssi(), LoRa.packetSnr(), LoRa.packetFrequencyError()); + SYSLOG_Utils::log("LoRa Rx", loraPacket, LoRa.packetRssi(), LoRa.packetSnr(), LoRa.packetFrequencyError()); } } return loraPacket; diff --git a/src/syslog_utils.cpp b/src/syslog_utils.cpp index 28cc0e3..1c9bc87 100644 --- a/src/syslog_utils.cpp +++ b/src/syslog_utils.cpp @@ -1,31 +1,58 @@ +#include +#include #include "configuration.h" #include "syslog_utils.h" #include "gps_utils.h" -#include "logger.h" + extern Configuration Config; -extern logging::Logger logger; +extern int stationMode; + +WiFiUDP udpClient; 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 += " _ / "; +void log(String type, String packet, int rssi, float snr, int freqError) { + String syslogPacket = "ESP32 LoRa [APRS] - "; + if (Config.syslog.active && (stationMode==1 || stationMode==2)) { + if (type == "APRSIS Tx") { + if (packet.indexOf(":>") > 10) { + syslogPacket += type + " - StartUp STATUS - " + packet.substring(packet.indexOf(":>")+2); + } + } else if (type == "LoRa Rx") { + if (packet.indexOf("::") > 10) { + syslogPacket += type + " - MESSAGE - " + packet.substring(3,packet.indexOf(">")) + " ---> " + packet.substring(packet.indexOf("::")+2); + } else if (packet.indexOf(":!") > 10 || packet.indexOf(":=") > 10) { + syslogPacket += type + " - GPS - " + packet.substring(3,packet.indexOf(">")) + " / " + 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 / " + GPS_Utils::getDistance(packet); + } else { + syslogPacket += type + " - " + packet; + } + } else if (type == "LoRa Tx") { + if (packet.indexOf("RFONLY") > 10) { + syslogPacket += type + " - RFONLY - " + packet.substring(packet.indexOf("::")+2); + } else if (packet.indexOf("::") > 10) { + syslogPacket += type + " - MESSAGE - " + packet.substring(0,packet.indexOf(">")) + " ---> " + packet.substring(packet.indexOf("::")+2); + } else { + syslogPacket += type + " - " + packet; + } + } else { + syslogPacket = "ERROR - Error in Syslog Packet"; + } + udpClient.beginPacket(Config.syslog.server.c_str(), Config.syslog.port); + udpClient.write((const uint8_t*)syslogPacket.c_str(), syslogPacket.length()); + udpClient.endPacket(); } - syslogPacket += String(rssi) + "dBm / " + String(snr) + "dB / " + String(freqError) + "Hz / "; - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", (syslogPacket + GPS_Utils::getDistance(packet)).c_str()); } void setup() { - - // ver hostname "ESP32 LoRa APRS iGate" ? - if (Config.syslog.active) { - logger.setSyslogServer(Config.syslog.server, Config.syslog.port, "ESP32 LoRa APRS iGate"); + if (Config.syslog.active && (stationMode==1 || stationMode==2)) { + udpClient.begin(WiFi.localIP(), 0); Serial.println("Syslog Server (" + Config.syslog.server + ") connected!\n"); } } diff --git a/src/syslog_utils.h b/src/syslog_utils.h index 5949fc3..91fafa8 100644 --- a/src/syslog_utils.h +++ b/src/syslog_utils.h @@ -5,7 +5,7 @@ namespace SYSLOG_Utils { -void processPacket(String packet, int rssi, float snr, int freqError) ; +void log(String type ,String packet, int rssi, float snr, int freqError); void setup(); } diff --git a/src/utils.cpp b/src/utils.cpp index db55450..a02964f 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -4,6 +4,7 @@ #include #include #include "configuration.h" +#include "syslog_utils.h" #include "pins_config.h" #include "wifi_utils.h" #include "lora_utils.h" @@ -34,7 +35,8 @@ void processStatus() { if (stationMode==1 || stationMode==2) { delay(1000); status += ",qAC:>https://github.com/richonguzman/LoRa_APRS_iGate"; - espClient.write((status + "\n").c_str()); + espClient.write((status + "\n").c_str()); + SYSLOG_Utils::log("APRSIS Tx", status,0,0,0); } else { delay(5000); status += ":>https://github.com/richonguzman/LoRa_APRS_iGate";