2023-06-13 05:36:39 +02:00
|
|
|
#include <WiFiUdp.h>
|
|
|
|
|
#include <WiFi.h>
|
2023-06-12 07:31:18 +02:00
|
|
|
#include "configuration.h"
|
2023-06-12 05:21:52 +02:00
|
|
|
#include "syslog_utils.h"
|
|
|
|
|
#include "gps_utils.h"
|
2023-06-13 05:36:39 +02:00
|
|
|
|
2023-06-12 07:31:18 +02:00
|
|
|
extern Configuration Config;
|
2023-06-13 05:36:39 +02:00
|
|
|
extern int stationMode;
|
|
|
|
|
|
|
|
|
|
WiFiUDP udpClient;
|
2023-06-12 05:21:52 +02:00
|
|
|
|
|
|
|
|
namespace SYSLOG_Utils {
|
|
|
|
|
|
2024-01-03 02:12:10 +01:00
|
|
|
void log(String type, String packet, int rssi, float snr, int freqError) {
|
|
|
|
|
String syslogPacket = "ESP32 LoRa [APRS] - " + Config.callsign + " - ";
|
|
|
|
|
if (Config.syslog.active && (stationMode==1 || stationMode==2 || (stationMode==5 && WiFi.status()==WL_CONNECTED))) {
|
|
|
|
|
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);
|
|
|
|
|
syslogPacket += " / " + String(rssi) + "dBm / " + String(snr) + "dB / " + String(freqError) + "Hz";
|
|
|
|
|
} else if (packet.indexOf(":!") > 10 || packet.indexOf(":=") > 10) {
|
|
|
|
|
syslogPacket += type + " - GPS - " + packet.substring(3,packet.indexOf(">")) + " / ";
|
|
|
|
|
if (packet.indexOf("WIDE1-1") > 10) {
|
|
|
|
|
syslogPacket += packet.substring(packet.indexOf(">")+1,packet.indexOf(",")) + " / WIDE1-1 / ";
|
|
|
|
|
} else {
|
|
|
|
|
syslogPacket += packet.substring(packet.indexOf(">")+1,packet.indexOf(":")) + " / _ / ";
|
|
|
|
|
}
|
|
|
|
|
syslogPacket += String(rssi) + "dBm / " + String(snr) + "dB / " + String(freqError) + "Hz / " + GPS_Utils::getDistance(packet);
|
|
|
|
|
} else if (packet.indexOf(":>") > 10) {
|
|
|
|
|
syslogPacket += type + " - STATUS - " + packet.substring(3,packet.indexOf(">")) + " ---> " + packet.substring(packet.indexOf(":>")+2);
|
|
|
|
|
syslogPacket += " / " + String(rssi) + "dBm / " + String(snr) + "dB / " + String(freqError) + "Hz";
|
|
|
|
|
} else if (packet.indexOf(":`") > 10) {
|
|
|
|
|
syslogPacket += type + " - MIC-E - " + packet.substring(3,packet.indexOf(">")) + " ---> " + packet.substring(packet.indexOf(":`")+2);
|
|
|
|
|
syslogPacket += " / " + String(rssi) + "dBm / " + String(snr) + "dB / " + String(freqError) + "Hz";
|
|
|
|
|
} else if (packet.indexOf(":T#") >= 10 && packet.indexOf(":=/") == -1) {
|
|
|
|
|
syslogPacket += type + " - TELEMETRY - " + packet.substring(3,packet.indexOf(">")) + " ---> " + packet.substring(packet.indexOf(":T#")+3);
|
|
|
|
|
syslogPacket += " / " + String(rssi) + "dBm / " + String(snr) + "dB / " + String(freqError) + "Hz";
|
|
|
|
|
} else if (packet.indexOf(":;") > 10) {
|
|
|
|
|
syslogPacket += type + " - OBJECT - " + packet.substring(3,packet.indexOf(">")) + " ---> " + packet.substring(packet.indexOf(":;")+2);
|
|
|
|
|
syslogPacket += " / " + String(rssi) + "dBm / " + String(snr) + "dB / " + String(freqError) + "Hz";
|
2023-06-13 05:36:39 +02:00
|
|
|
} else {
|
2024-01-03 02:12:10 +01:00
|
|
|
syslogPacket += type + " - " + packet;
|
|
|
|
|
syslogPacket += " / " + String(rssi) + "dBm / " + String(snr) + "dB / " + String(freqError) + "Hz";
|
|
|
|
|
}
|
|
|
|
|
} 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;
|
2023-06-13 05:36:39 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
2024-01-03 02:12:10 +01:00
|
|
|
syslogPacket = "ERROR - Error in Syslog Packet";
|
2023-06-13 05:36:39 +02:00
|
|
|
}
|
2024-01-03 02:12:10 +01:00
|
|
|
udpClient.beginPacket(Config.syslog.server.c_str(), Config.syslog.port);
|
|
|
|
|
udpClient.write((const uint8_t*)syslogPacket.c_str(), syslogPacket.length());
|
|
|
|
|
udpClient.endPacket();
|
2023-06-13 05:36:39 +02:00
|
|
|
}
|
2023-06-12 05:21:52 +02:00
|
|
|
}
|
2023-06-12 07:31:18 +02:00
|
|
|
|
2024-01-03 02:12:10 +01:00
|
|
|
void setup() {
|
|
|
|
|
if (Config.syslog.active && (stationMode==1 || stationMode==2 || (stationMode==5 && WiFi.status()==WL_CONNECTED))) {
|
|
|
|
|
udpClient.begin(WiFi.localIP(), 0);
|
|
|
|
|
Serial.println("init : Syslog Server ... done! (at " + Config.syslog.server + ")");
|
|
|
|
|
}
|
2023-06-12 07:31:18 +02:00
|
|
|
}
|
2023-06-12 05:21:52 +02:00
|
|
|
|
|
|
|
|
}
|