From af0626de82f527afeb7e9f737096e3bf72a32477 Mon Sep 17 00:00:00 2001 From: richonguzman Date: Mon, 19 Jun 2023 19:44:55 -0400 Subject: [PATCH] ready for testing --- data/igate_conf.json | 4 ++-- src/gps_utils.cpp | 8 +++++--- src/lora_utils.cpp | 8 +++++++- src/utils.cpp | 20 ++++++++++++++++---- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/data/igate_conf.json b/data/igate_conf.json index f8a8a53..e4cd75c 100644 --- a/data/igate_conf.json +++ b/data/igate_conf.json @@ -6,8 +6,8 @@ "AP": [ { "ssid": "Richon", "password": "k4fPnmg5qnyf", - "latitude": -33.0338131, - "longitude": -71.5737237 + "latitude": -33.0468601, + "longitude": -71.6270988 }, { "ssid": "Jimenita", "password": "mg6wyMhqRnxk", diff --git a/src/gps_utils.cpp b/src/gps_utils.cpp index 36c8f71..b5b1d76 100644 --- a/src/gps_utils.cpp +++ b/src/gps_utils.cpp @@ -5,6 +5,7 @@ extern Configuration Config; extern WiFi_AP *currentWiFi; extern int stationMode; +String distance; namespace GPS_Utils { @@ -113,8 +114,8 @@ String decodeEncodedGPS(String packet) { 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"; + distance = String(calculateDistanceTo(decodedLatitude, decodedLongitude),1); + return String(decodedLatitude) + "N / " + String(decodedLongitude) + "E / " + distance + "km"; } String getReceivedGPS(String packet) { @@ -145,7 +146,8 @@ String getReceivedGPS(String packet) { if (LngSign == "W") { convertedLongitude = -convertedLongitude; } - return String(convertedLatitude) + "N / " + String(convertedLongitude) + "E / " + String(calculateDistanceTo(convertedLatitude, convertedLongitude)) + "km"; + distance = String(calculateDistanceTo(convertedLatitude, convertedLongitude),1); + return String(convertedLatitude) + "N / " + String(convertedLongitude) + "E / " + distance + "km"; } String getDistance(String packet) { diff --git a/src/lora_utils.cpp b/src/lora_utils.cpp index b5e40ef..e49b570 100644 --- a/src/lora_utils.cpp +++ b/src/lora_utils.cpp @@ -7,6 +7,9 @@ extern Configuration Config; extern int stationMode; +int rssi, freqError; +float snr; + namespace LoRa_Utils { void setup() { @@ -67,8 +70,11 @@ String receivePacket() { int inChar = LoRa.read(); loraPacket += (char)inChar; } + rssi = LoRa.packetRssi(); + snr = LoRa.packetSnr(); + freqError = LoRa.packetFrequencyError(); if (Config.syslog.active && (stationMode==1 || stationMode==2)) { - SYSLOG_Utils::log("LoRa Rx", loraPacket, LoRa.packetRssi(), LoRa.packetSnr(), LoRa.packetFrequencyError()); + SYSLOG_Utils::log("LoRa Rx", loraPacket, rssi, snr, freqError); } } return loraPacket; diff --git a/src/utils.cpp b/src/utils.cpp index 821c9af..6c876f4 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -9,6 +9,7 @@ #include "pins_config.h" #include "wifi_utils.h" #include "lora_utils.h" +#include "gps_utils.h" #include "bme_utils.h" #include "display.h" #include "utils.h" @@ -33,6 +34,10 @@ extern bool beacon_update; extern int stationMode; extern String iGateBeaconPacket; extern std::vector lastHeardStation; +extern int rssi; +extern float snr; +extern int freqError; +extern String distance; namespace Utils { @@ -185,16 +190,23 @@ void typeOfPacket(String packet, String packetType) { } else { sixthLine = sender + "> MESSAGE"; } - seventhLine = "RSSI: 38dBm SNR: 6dBm"; + seventhLine = "RSSI:" + String(rssi) + "dBm SNR: " + String(snr) + "dBm"; } else if (packet.indexOf(":>") >= 10) { sixthLine = sender + "> NEW STATUS"; - seventhLine = "RSSI: 38dBm SNR: 6dBm"; + seventhLine = "RSSI:" + String(rssi) + "dBm SNR: " + String(snr) + "dBm"; } else if (packet.indexOf(":!") >= 10 || packet.indexOf(":=") >= 10) { sixthLine = sender + "> GPS BEACON"; - seventhLine = "RSSI:38dBm D: 25.6km"; + GPS_Utils::getDistance(packet); + seventhLine = "RSSI:" + String(rssi) + "dBm "; + if (distance.indexOf(".") == 2) { + seventhLine += " "; + } else if (distance.indexOf(".") == 1) { + seventhLine += " "; + } + seventhLine += "D:" + distance + "km"; } else { sixthLine = sender + "> ??????????"; - seventhLine = "RSSI: 38dBm SNR: 6dBm"; + seventhLine = "RSSI:" + String(rssi) + "dBm SNR: " + String(snr) + "dBm"; } }