From 8e85da253ca980e043fe88e89212848380059a00 Mon Sep 17 00:00:00 2001 From: richonguzman Date: Thu, 6 Jul 2023 01:01:10 -0400 Subject: [PATCH] 1.2 --- data/igate_conf.json | 3 ++- src/LoRa_APRS_iGate.cpp | 4 ++-- src/battery_utils.cpp | 10 ++++------ src/battery_utils.h | 2 +- src/configuration.cpp | 1 + src/configuration.h | 1 + src/utils.cpp | 26 ++++++++++++++++++-------- 7 files changed, 29 insertions(+), 18 deletions(-) diff --git a/data/igate_conf.json b/data/igate_conf.json index ac495c2..45380e9 100644 --- a/data/igate_conf.json +++ b/data/igate_conf.json @@ -48,7 +48,8 @@ }, "other": { "beaconInterval": 15, - "rememberStationTime": 30 + "rememberStationTime": 30, + "sendBatteryVoltage": false }, "bme": { "active": false diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 282dafe..51def66 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -20,14 +20,14 @@ Configuration Config; WiFiClient espClient; -String versionDate = "2023.07.05"; +String versionDate = "2023.07.06"; int myWiFiAPIndex = 0; int myWiFiAPSize = Config.wifiAPs.size(); WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex]; int stationMode = Config.stationMode; bool statusAfterBoot = true; -bool beacon_update = true; +bool beaconUpdate = true; uint32_t lastBeaconTx = 0; uint32_t previousWiFiMillis = 0; uint32_t lastScreenOn = millis(); diff --git a/src/battery_utils.cpp b/src/battery_utils.cpp index c259b3e..c5f51f1 100644 --- a/src/battery_utils.cpp +++ b/src/battery_utils.cpp @@ -1,13 +1,12 @@ #include "battery_utils.h" #include "pins_config.h" -extern String batteryVoltage; - -float adcReadingTransformation = (4095/3.3); +float adcReadingTransformation = (3.3/4095); +float voltageDividerCorrection = 0.288; namespace BATTERY_Utils { -String checkVoltages() { +float checkVoltages() { float sample; int sampleSum = 0; for (int i=0; i<100; i++) { @@ -15,8 +14,7 @@ String checkVoltages() { sampleSum += sample; delayMicroseconds(50); } - batteryVoltage = 2.1571 *(sampleSum/100) * adcReadingTransformation; - return String(batteryVoltage); + return (2 * (sampleSum/100) * adcReadingTransformation) + voltageDividerCorrection; } } \ No newline at end of file diff --git a/src/battery_utils.h b/src/battery_utils.h index 78b52a1..58e5df9 100644 --- a/src/battery_utils.h +++ b/src/battery_utils.h @@ -5,7 +5,7 @@ namespace BATTERY_Utils { -String checkVoltages(); +float checkVoltages(); } diff --git a/src/configuration.cpp b/src/configuration.cpp index 4f2ce2a..2d90496 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -36,6 +36,7 @@ void Configuration::readFile(fs::FS &fs, const char *fileName) { iGateComment = data["iGateComment"].as(); beaconInterval = data["other"]["beaconInterval"].as(); rememberStationTime = data["other"]["rememberStationTime"].as(); + sendBatteryVoltage = data["other"]["sendBatteryVoltage"].as(); digi.comment = data["digi"]["comment"].as(); digi.latitude = data["digi"]["latitude"].as(); diff --git a/src/configuration.h b/src/configuration.h index f131524..6d439de 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -66,6 +66,7 @@ public: String iGateComment; int beaconInterval; int rememberStationTime; + bool sendBatteryVoltage; std::vector wifiAPs; DIGI digi; APRS_IS aprs_is; diff --git a/src/utils.cpp b/src/utils.cpp index 1faa598..3fb7f1f 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -5,6 +5,7 @@ #include #include "configuration.h" #include "station_utils.h" +#include "battery_utils.h" #include "syslog_utils.h" #include "pins_config.h" #include "wifi_utils.h" @@ -30,7 +31,7 @@ extern String sixthLine; extern String seventhLine; extern uint32_t lastBeaconTx; extern uint32_t lastScreenOn; -extern bool beacon_update; +extern bool beaconUpdate; extern int stationMode; extern String iGateBeaconPacket; extern std::vector lastHeardStation; @@ -89,10 +90,11 @@ void activeStations() { void checkBeaconInterval() { uint32_t lastTx = millis() - lastBeaconTx; + String beaconPacket; if (lastTx >= Config.beaconInterval*60*1000) { - beacon_update = true; + beaconUpdate = true; } - if (beacon_update) { + if (beaconUpdate) { display_toggle(true); Serial.println("---- Sending iGate Beacon ----"); STATION_Utils::deleteNotHeard(); @@ -106,10 +108,14 @@ void checkBeaconInterval() { show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING iGate BEACON", 1000); seventhLine = " listening..."; if (Config.bme.active) { - espClient.write((iGateBeaconPacket.substring(0,iGateBeaconPacket.indexOf(":=")+20) + "_" + BME_Utils::readDataSensor() + iGateBeaconPacket.substring(iGateBeaconPacket.indexOf(":=")+21) + " + WX" + "\n").c_str()); + beaconPacket = iGateBeaconPacket.substring(0,iGateBeaconPacket.indexOf(":=")+20) + "_" + BME_Utils::readDataSensor() + iGateBeaconPacket.substring(iGateBeaconPacket.indexOf(":=")+21) + " + WX"; } else { - espClient.write((iGateBeaconPacket + "\n").c_str()); + beaconPacket = iGateBeaconPacket; } + if (Config.sendBatteryVoltage) { + beaconPacket += " (Batt=" + String(BATTERY_Utils::checkVoltages(),2) + "V)"; + } + espClient.write((beaconPacket + "\n").c_str()); show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0); } else if (stationMode==3 || stationMode==4) { String Rx = String(Config.loramodule.digirepeaterRxFreq); @@ -128,17 +134,21 @@ void checkBeaconInterval() { LoRa_Utils::changeFreqTx(); } if (Config.bme.active) { - LoRa_Utils::sendNewPacket("APRS",iGateBeaconPacket.substring(0,iGateBeaconPacket.indexOf(":=")+20) + "_" + BME_Utils::readDataSensor() + iGateBeaconPacket.substring(iGateBeaconPacket.indexOf(":=")+21) + " + WX"); + beaconPacket = iGateBeaconPacket.substring(0,iGateBeaconPacket.indexOf(":=")+20) + "_" + BME_Utils::readDataSensor() + iGateBeaconPacket.substring(iGateBeaconPacket.indexOf(":=")+21) + " + WX"; } else { - LoRa_Utils::sendNewPacket("APRS",iGateBeaconPacket); + beaconPacket = iGateBeaconPacket; } + if (Config.sendBatteryVoltage) { + beaconPacket += " (Batt=" + String(BATTERY_Utils::checkVoltages(),2) + "V)"; + } + LoRa_Utils::sendNewPacket("APRS", beaconPacket); if (stationMode == 4) { LoRa_Utils::changeFreqRx(); } } lastBeaconTx = millis(); lastScreenOn = millis(); - beacon_update = false; + beaconUpdate = false; } if (statusAfterBoot) {