first beta Syslog: adding rssi snr freq error

This commit is contained in:
richonguzman
2023-06-11 23:21:52 -04:00
parent 9a76249fe5
commit 3858d39e8a
10 changed files with 126 additions and 2 deletions
+6 -1
View File
@@ -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
+1
View File
@@ -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
+1 -1
View File
@@ -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];
+4
View File
@@ -57,6 +57,10 @@ void Configuration::readFile(fs::FS &fs, const char *fileName) {
display.alwaysOn = data["display"]["alwaysOn"].as<bool>();
display.timeout = data["display"]["timeout"].as<int>();
syslog.active = data["syslog"]["active"].as<bool>();
syslog.server = data["syslog"]["server"].as<String>();
syslog.port = data["syslog"]["port"].as<int>();
configFile.close();
}
+8
View File
@@ -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();
+66
View File
@@ -1,3 +1,4 @@
#include <TinyGPS++.h>
#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 " _ / _ / _ ";
}
}
}
+4
View File
@@ -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);
}
+4
View File
@@ -1,6 +1,7 @@
#include <LoRa.h>
#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;
}
+20
View File
@@ -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));
}
}
+12
View File
@@ -0,0 +1,12 @@
#ifndef SYSLOG_H_
#define SYSLOG_H_
#include <Arduino.h>
namespace SYSLOG_Utils {
void processPacket(String packet, int rssi, float snr, int freqError) ;
}
#endif