This commit is contained in:
richonguzman
2023-06-12 23:36:39 -04:00
parent e433e375e5
commit b7ba17d871
7 changed files with 52 additions and 28 deletions
+43 -16
View File
@@ -1,31 +1,58 @@
#include <WiFiUdp.h>
#include <WiFi.h>
#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");
}
}