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
|
|
|
|
|
|
|
|
WiFiUDP udpClient;
|
2023-06-12 05:21:52 +02:00
|
|
|
|
2024-02-25 16:00:44 +01:00
|
|
|
|
2023-06-12 05:21:52 +02:00
|
|
|
namespace SYSLOG_Utils {
|
|
|
|
|
|
2024-06-06 05:49:16 +02:00
|
|
|
void log(const uint8_t type, const String& packet, const int rssi, const float snr, const int freqError) {
|
2024-03-07 17:46:38 +01:00
|
|
|
if (Config.syslog.active && WiFi.status() == WL_CONNECTED) {
|
2024-05-30 21:12:34 +02:00
|
|
|
String syslogPacket = "<165>1 - ";
|
|
|
|
|
syslogPacket.concat(Config.callsign);
|
|
|
|
|
syslogPacket.concat(" CA2RXU_LoRa_iGate_1.3 - - - "); //RFC5424 The Syslog Protocol
|
|
|
|
|
|
|
|
|
|
char signalData[35];
|
|
|
|
|
snprintf(signalData, sizeof(signalData), " / %ddBm / %.2fdB / %dHz", rssi, snr, freqError);
|
|
|
|
|
|
2025-02-12 19:28:48 +01:00
|
|
|
int colonIndex = packet.indexOf(":");
|
|
|
|
|
char nextChar = packet[colonIndex + 1];
|
|
|
|
|
String sender = packet.substring(3, packet.indexOf(">"));
|
|
|
|
|
|
2024-05-15 23:47:29 +02:00
|
|
|
switch (type) {
|
|
|
|
|
case 0: // CRC
|
2024-05-30 21:12:34 +02:00
|
|
|
syslogPacket.concat("CRC / CRC-ERROR / ");
|
|
|
|
|
syslogPacket.concat(packet);
|
|
|
|
|
syslogPacket.concat(signalData);
|
2024-05-15 23:47:29 +02:00
|
|
|
break;
|
|
|
|
|
case 1: // RX
|
2024-05-30 21:12:34 +02:00
|
|
|
syslogPacket.concat("RX / ");
|
2025-02-12 19:28:48 +01:00
|
|
|
if (nextChar == ':') {
|
2024-05-30 21:12:34 +02:00
|
|
|
syslogPacket.concat("MESSAGE / ");
|
2025-02-12 19:28:48 +01:00
|
|
|
syslogPacket.concat(sender);
|
|
|
|
|
syslogPacket.concat(" ---> ");
|
|
|
|
|
syslogPacket.concat(packet.substring(colonIndex + 2));
|
|
|
|
|
} else if (nextChar == '!' || nextChar == '=') {
|
2024-05-30 21:12:34 +02:00
|
|
|
syslogPacket.concat("GPS / ");
|
2025-02-12 19:28:48 +01:00
|
|
|
syslogPacket.concat(sender);
|
2024-05-30 21:12:34 +02:00
|
|
|
syslogPacket.concat(" / ");
|
2024-05-15 23:47:29 +02:00
|
|
|
if (packet.indexOf("WIDE1-1") > 10) {
|
2024-05-30 21:12:34 +02:00
|
|
|
syslogPacket.concat(packet.substring(packet.indexOf(">") + 1, packet.indexOf(",")));
|
|
|
|
|
syslogPacket.concat(" / WIDE1-1");
|
2024-05-15 23:47:29 +02:00
|
|
|
} else {
|
2025-02-12 19:28:48 +01:00
|
|
|
syslogPacket.concat(packet.substring(packet.indexOf(">") + 1, colonIndex));
|
2024-05-30 21:12:34 +02:00
|
|
|
syslogPacket.concat(" / -");
|
2024-05-15 23:47:29 +02:00
|
|
|
}
|
2025-02-12 19:28:48 +01:00
|
|
|
} else if (nextChar == '>') {
|
2024-05-30 21:12:34 +02:00
|
|
|
syslogPacket.concat("STATUS / ");
|
2025-02-12 19:28:48 +01:00
|
|
|
syslogPacket.concat(sender);
|
2024-05-30 21:12:34 +02:00
|
|
|
syslogPacket.concat(" ---> ");
|
2025-02-12 19:28:48 +01:00
|
|
|
syslogPacket.concat(packet.substring(colonIndex + 2));
|
|
|
|
|
} else if (nextChar == '`') {
|
2024-05-30 21:12:34 +02:00
|
|
|
syslogPacket.concat("MIC-E / ");
|
2025-02-12 19:28:48 +01:00
|
|
|
syslogPacket.concat(sender);
|
2024-05-30 21:12:34 +02:00
|
|
|
syslogPacket.concat(" ---> ");
|
2025-02-12 19:28:48 +01:00
|
|
|
syslogPacket.concat(packet.substring(colonIndex + 2));
|
|
|
|
|
} else if (nextChar == ';') {
|
|
|
|
|
syslogPacket.concat("OBJECT / ");
|
|
|
|
|
syslogPacket.concat(sender);
|
|
|
|
|
syslogPacket.concat(" ---> ");
|
|
|
|
|
syslogPacket.concat(packet.substring(colonIndex + 2));
|
2024-05-15 23:47:29 +02:00
|
|
|
} else if (packet.indexOf(":T#") >= 10 && packet.indexOf(":=/") == -1) {
|
2024-05-30 21:12:34 +02:00
|
|
|
syslogPacket.concat("TELEMETRY / ");
|
2025-02-12 19:28:48 +01:00
|
|
|
syslogPacket.concat(sender);
|
2024-05-30 21:12:34 +02:00
|
|
|
syslogPacket.concat(" ---> ");
|
|
|
|
|
syslogPacket.concat(packet.substring(packet.indexOf(":T#") + 3));
|
2024-01-03 02:12:10 +01:00
|
|
|
} else {
|
2024-05-30 21:12:34 +02:00
|
|
|
syslogPacket.concat(packet);
|
2025-02-12 19:28:48 +01:00
|
|
|
}
|
|
|
|
|
syslogPacket.concat(signalData);
|
|
|
|
|
if (nextChar == '!' || nextChar == '=') {
|
|
|
|
|
syslogPacket.concat(" / ");
|
|
|
|
|
syslogPacket.concat(GPS_Utils::getDistanceAndComment(packet));
|
2024-01-03 02:12:10 +01:00
|
|
|
}
|
2024-05-15 23:47:29 +02:00
|
|
|
break;
|
|
|
|
|
case 2: // APRSIS TX
|
2024-05-30 21:12:34 +02:00
|
|
|
syslogPacket.concat("APRSIS TX / ");
|
2025-02-12 19:28:48 +01:00
|
|
|
if (nextChar == '>') {
|
2024-05-30 21:12:34 +02:00
|
|
|
syslogPacket.concat("StartUp_Status / ");
|
2025-02-12 19:28:48 +01:00
|
|
|
syslogPacket.concat(packet.substring(colonIndex + 2));
|
2024-05-15 23:47:29 +02:00
|
|
|
} else {
|
2024-05-30 21:12:34 +02:00
|
|
|
syslogPacket.concat("QUERY / ");
|
|
|
|
|
syslogPacket.concat(packet);
|
2024-05-15 23:47:29 +02:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 3: // TX
|
2024-05-30 21:12:34 +02:00
|
|
|
syslogPacket.concat("TX / ");
|
2024-05-15 23:47:29 +02:00
|
|
|
if (packet.indexOf("RFONLY") > 10) {
|
2024-05-30 21:12:34 +02:00
|
|
|
syslogPacket.concat("RFONLY / ");
|
|
|
|
|
syslogPacket.concat(packet);
|
2025-02-12 19:28:48 +01:00
|
|
|
} else if (nextChar == ':') {
|
2024-05-30 21:12:34 +02:00
|
|
|
syslogPacket.concat("MESSAGE / ");
|
2025-02-12 19:28:48 +01:00
|
|
|
syslogPacket.concat(sender);
|
2024-05-30 21:12:34 +02:00
|
|
|
syslogPacket.concat(" ---> ");
|
2025-02-12 19:28:48 +01:00
|
|
|
syslogPacket.concat(packet.substring(colonIndex + 2));
|
2024-05-15 23:47:29 +02:00
|
|
|
} else {
|
2024-05-30 21:12:34 +02:00
|
|
|
syslogPacket.concat(packet);
|
2024-05-15 23:47:29 +02:00
|
|
|
}
|
2024-05-30 21:12:34 +02:00
|
|
|
break;
|
2024-05-15 23:47:29 +02:00
|
|
|
default:
|
|
|
|
|
syslogPacket = "<165>1 - ERROR LoRa - - - ERROR / Error in Syslog Packet"; //RFC5424 The Syslog Protocol
|
|
|
|
|
break;
|
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() {
|
2024-03-07 17:46:38 +01:00
|
|
|
if (Config.syslog.active && WiFi.status() == WL_CONNECTED) {
|
2024-01-03 02:12:10 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
}
|