Skip to content

Commit

Permalink
primera mejora Telemetria
Browse files Browse the repository at this point in the history
  • Loading branch information
richonguzman committed Sep 22, 2024
1 parent dd12330 commit 0e46c64
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 26 deletions.
3 changes: 2 additions & 1 deletion data/igate_conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"monitorExternalVoltage": false,
"externalSleepVoltage": 10.9,
"voltageDividerR1": 100.0,
"voltageDividerR2": 27.0
"voltageDividerR2": 27.0,
"sendVoltageAsTelemetry": true
},
"bme": {
"active": false,
Expand Down
13 changes: 13 additions & 0 deletions data_embed/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,19 @@ <h5>
<div class="col-9 mt-2">
<div class="row mt-2">
<div class="col-6">
<div class="form-check form-switch">
<input
type="checkbox"
name="battery.sendVoltageAsTelemetry"
id="battery.sendVoltageAsTelemetry"
class="form-check-input"
/>
<label
for="battery.sendVoltageAsTelemetry"
class="form-label"
>Send Voltage As Telemetry</label
>
</div>
<div class="form-check form-switch">
<input
type="checkbox"
Expand Down
5 changes: 3 additions & 2 deletions data_embed/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ function loadSettings(settings) {
document.getElementById("battery.internalSleepVoltage").value = settings.battery.internalSleepVoltage.toFixed(1);
document.getElementById("battery.sendExternalVoltage").checked = settings.battery.sendExternalVoltage;
document.getElementById("battery.externalVoltagePin").value = settings.battery.externalVoltagePin;
document.getElementById("battery.voltageDividerR1").value = settings.battery.voltageDividerR1.toFixed(1);
document.getElementById("battery.voltageDividerR2").value = settings.battery.voltageDividerR2.toFixed(1);
document.getElementById("battery.voltageDividerR1").value = settings.battery.voltageDividerR1.toFixed(1);
document.getElementById("battery.voltageDividerR2").value = settings.battery.voltageDividerR2.toFixed(1);
document.getElementById("battery.monitorExternalVoltage").checked = settings.battery.monitorExternalVoltage;
document.getElementById("battery.externalSleepVoltage").value = settings.battery.externalSleepVoltage.toFixed(1);
document.getElementById("battery.sendVoltageAsTelemetry").checked = settings.battery.sendVoltageAsTelemetry;

// TELEMETRY BME/WX
document.getElementById("bme.active").checked = settings.bme.active;
Expand Down
2 changes: 1 addition & 1 deletion src/LoRa_APRS_iGate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ________________________________________________________________________________
#include "A7670_utils.h"
#endif

String versionDate = "2024.09.17";
String versionDate = "2024.09.22";
Configuration Config;
WiFiClient espClient;

Expand Down
2 changes: 1 addition & 1 deletion src/aprs_is_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ namespace APRS_IS_Utils {
A7670_Utils::uploadToAPRSIS(queryAnswer);
#else
upload(queryAnswer);
#endif
#endif
SYSLOG_Utils::log(2, queryAnswer, 0, 0.0, 0); // APRSIS TX
fifthLine = "APRS-IS ----> APRS-IS";
sixthLine = Config.callsign;
Expand Down
45 changes: 45 additions & 0 deletions src/battery_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ float multiplyCorrection = 0.035;

float voltageDividerTransformation = 0.0;

int telemetryCounter = random(1,999);


#ifdef HAS_ADC_CALIBRATION
#include <esp_adc_cal.h>
Expand Down Expand Up @@ -220,4 +222,47 @@ namespace BATTERY_Utils {
}
}


String generateEncodedTelemetryBytes(float value, bool firstBytes, byte voltageType) { // 0 = internal battery(0-4,2V) , 1 = external battery(0-15V)
String encodedBytes;
int tempValue;

if (firstBytes) {
tempValue = value;
} else {
switch (voltageType) {
case 0:
tempValue = value * 100; // Internal voltage calculation
break;
case 1:
tempValue = (value * 100) / 2; // External voltage calculation
break;
default:
tempValue = value;
break;
}
}

int firstByte = tempValue / 91;
tempValue -= firstByte * 91;

encodedBytes = char(firstByte + 33);
encodedBytes += char(tempValue + 33);
return encodedBytes;
}


String generateEncodedTelemetry() {
String telemetry = "|";
telemetry += generateEncodedTelemetryBytes(telemetryCounter, true, 0);
telemetryCounter++;
if (telemetryCounter == 1000) {
telemetryCounter = 0;
}
if (Config.battery.sendInternalVoltage) telemetry += generateEncodedTelemetryBytes(3.987/*checkInternalVoltage()*/, false, 0);
if (Config.battery.sendExternalVoltage) telemetry += generateEncodedTelemetryBytes(12.123/*checkExternalVoltage()*/, false, 1);
telemetry += "|";
return telemetry;
}

}
3 changes: 3 additions & 0 deletions src/battery_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ namespace BATTERY_Utils {
void checkIfShouldSleep(); // ????
void startupBatteryHealth();

String generateEncodedTelemetryBytes(float value, bool firstBytes, byte voltageType);
String generateEncodedTelemetry();

}

#endif
6 changes: 6 additions & 0 deletions src/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ void Configuration::writeFile() {
data["battery"]["externalSleepVoltage"] = battery.externalSleepVoltage;
data["battery"]["voltageDividerR1"] = battery.voltageDividerR1;
data["battery"]["voltageDividerR2"] = battery.voltageDividerR2;

data["battery"]["sendVoltageAsTelemetry"] = battery.sendVoltageAsTelemetry;

data["bme"]["active"] = bme.active;
data["bme"]["heightCorrection"] = bme.heightCorrection;
Expand Down Expand Up @@ -176,6 +178,8 @@ bool Configuration::readFile() {
battery.voltageDividerR1 = data["battery"]["voltageDividerR1"] | 100.0;
battery.voltageDividerR2 = data["battery"]["voltageDividerR2"] | 27.0;

battery.sendVoltageAsTelemetry = data["battery"]["sendVoltageAsTelemetry"] | true;

bme.active = data["bme"]["active"] | false;
bme.heightCorrection = data["bme"]["heightCorrection"] | 0;
bme.temperatureCorrection = data["bme"]["temperatureCorrection"] | 0.0;
Expand Down Expand Up @@ -295,6 +299,8 @@ void Configuration::init() {
battery.voltageDividerR1 = 100.0;
battery.voltageDividerR2 = 27.0;

battery.sendVoltageAsTelemetry = true;

lowPowerMode = false;
lowVoltageCutOff = 0;

Expand Down
1 change: 1 addition & 0 deletions src/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class BATTERY {
float externalSleepVoltage;
float voltageDividerR1;
float voltageDividerR2;
bool sendVoltageAsTelemetry;
};

class BME {
Expand Down
2 changes: 1 addition & 1 deletion src/gps_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace GPS_Utils {
encodedData += helper_base91[i];
}
encodedData += symbol;
encodedData += " x";
encodedData += " ";
encodedData += "\x47";
return encodedData;
}
Expand Down
127 changes: 107 additions & 20 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ extern bool transmitFlag;
extern std::vector<LastHeardStation> lastHeardStations;

bool statusAfterBoot = true;
bool sendStartTelemetry = true;
bool beaconUpdate = true;
uint32_t lastBeaconTx = 0;
uint32_t lastScreenOn = millis();
Expand Down Expand Up @@ -102,6 +103,76 @@ namespace Utils {
fourthLine.concat(String(lastHeardStations.size()));
}


void sendInitialTelemetryPackets() {
String sender = Config.callsign;
for (int i = sender.length(); i < 9; i++) {
sender += ' ';
}
String baseAPRSISTelemetryPacket = Config.callsign;
baseAPRSISTelemetryPacket += ">APLRG1,TCPIP,qAC::";
baseAPRSISTelemetryPacket += sender;
baseAPRSISTelemetryPacket += ":";

String baseRFTelemetryPacket = Config.callsign;
baseRFTelemetryPacket += ">APLRG1,WIDE1-1::";
baseRFTelemetryPacket += sender;
baseRFTelemetryPacket += ":";


String telemetryPacket1 = "EQNS.";
if (Config.battery.sendInternalVoltage) {
telemetryPacket1 += "0,0.01,0";
}
if (Config.battery.sendExternalVoltage) {
telemetryPacket1 += String(Config.battery.sendInternalVoltage ? "," : "") + "0,0.02,0";
}

String telemetryPacket2 = "UNIT.";
if (Config.battery.sendInternalVoltage) {
telemetryPacket2 += "VDC";
}
if (Config.battery.sendExternalVoltage) {
telemetryPacket2 += String(Config.battery.sendInternalVoltage ? "," : "") + "VDC";
}

String telemetryPacket3 = "PARM.";
if (Config.battery.sendInternalVoltage) {
telemetryPacket3 += "V_Batt";
}
if (Config.battery.sendExternalVoltage) {
telemetryPacket3 += String(Config.battery.sendInternalVoltage ? "," : "") + "V_Ext";
}

if (Config.beacon.sendViaAPRSIS) {
#ifdef HAS_A7670
A7670_Utils::uploadToAPRSIS(baseAPRSISTelemetryPacket + telemetryPacket1);
delay(300);
A7670_Utils::uploadToAPRSIS(baseAPRSISTelemetryPacket + telemetryPacket2);
delay(300);
A7670_Utils::uploadToAPRSIS(baseAPRSISTelemetryPacket + telemetryPacket3);
delay(300);
#else
APRS_IS_Utils::upload(baseAPRSISTelemetryPacket + telemetryPacket1);
delay(300);
APRS_IS_Utils::upload(baseAPRSISTelemetryPacket + telemetryPacket2);
delay(300);
APRS_IS_Utils::upload(baseAPRSISTelemetryPacket + telemetryPacket3);
delay(300);
#endif
delay(300);
} else if (Config.beacon.sendViaRF) {
LoRa_Utils::sendNewPacket(baseRFTelemetryPacket + telemetryPacket1);
delay(3000);
LoRa_Utils::sendNewPacket(baseRFTelemetryPacket + telemetryPacket2);
delay(3000);
LoRa_Utils::sendNewPacket(baseRFTelemetryPacket + telemetryPacket3);
delay(3000);
}
sendStartTelemetry = false;
}


void checkBeaconInterval() {
uint32_t lastTx = millis() - lastBeaconTx;
if (lastBeaconTx == 0 || lastTx >= Config.beacon.interval * 60 * 1000) {
Expand All @@ -112,6 +183,10 @@ namespace Utils {
if (!Config.display.alwaysOn && Config.display.timeout != 0) {
displayToggle(true);
}

if (sendStartTelemetry && Config.battery.sendVoltageAsTelemetry && !Config.bme.active && (Config.battery.sendInternalVoltage || Config.battery.sendExternalVoltage)) {
sendInitialTelemetryPackets();
}

STATION_Utils::deleteNotHeard();

Expand All @@ -133,45 +208,57 @@ namespace Utils {
#if defined(BATTERY_PIN) || defined(HAS_AXP192) || defined(HAS_AXP2101)
if (Config.battery.sendInternalVoltage || Config.battery.monitorInternalVoltage) {
float internalVoltage = BATTERY_Utils::checkInternalVoltage();
if (Config.battery.monitorInternalVoltage && internalVoltage < Config.battery.internalSleepVoltage) {
beaconPacket += " **IntBatWarning:SLEEP**";
secondaryBeaconPacket += " **IntBatWarning:SLEEP**";
shouldSleepLowVoltage = true;
}

String internalVoltageInfo = String(internalVoltage,2) + "V";
if (Config.battery.sendInternalVoltage) {
beaconPacket += " Batt=";
beaconPacket += internalVoltageInfo;
secondaryBeaconPacket += " Batt=";
secondaryBeaconPacket += internalVoltageInfo;
sixthLine = " (Batt=";
sixthLine += internalVoltageInfo;
sixthLine += ")";
}
if (Config.battery.monitorInternalVoltage && internalVoltage < Config.battery.internalSleepVoltage) {
beaconPacket += " **IntBatWarning:SLEEP**";
secondaryBeaconPacket += " **IntBatWarning:SLEEP**";
shouldSleepLowVoltage = true;
}
if (!Config.battery.sendVoltageAsTelemetry) {
beaconPacket += " Batt=";
beaconPacket += internalVoltageInfo;
secondaryBeaconPacket += " Batt=";
secondaryBeaconPacket += internalVoltageInfo;
}
}
}
#endif

#ifndef HELTEC_WP
if (Config.battery.sendExternalVoltage || Config.battery.monitorExternalVoltage) {
float externalVoltage = BATTERY_Utils::checkExternalVoltage();
String externalVoltageInfo = String(externalVoltage,2) + "V";
if (Config.battery.sendExternalVoltage) {
beaconPacket += " Ext=";
beaconPacket += externalVoltageInfo;
secondaryBeaconPacket += " Ext=";
secondaryBeaconPacket += externalVoltageInfo;
sixthLine = " (Ext V=";
sixthLine += externalVoltageInfo;
sixthLine += ")";
}
if (Config.battery.monitorExternalVoltage && externalVoltage < Config.battery.externalSleepVoltage) {
beaconPacket += " **ExtBatWarning:SLEEP**";
secondaryBeaconPacket += " **ExtBatWarning:SLEEP**";
shouldSleepLowVoltage = true;
}

String externalVoltageInfo = String(externalVoltage,2) + "V";
if (Config.battery.sendExternalVoltage) {
sixthLine = " (Ext V=";
sixthLine += externalVoltageInfo;
sixthLine += ")";
if (!Config.battery.sendVoltageAsTelemetry) {
beaconPacket += " Ext=";
beaconPacket += externalVoltageInfo;
secondaryBeaconPacket += " Ext=";
secondaryBeaconPacket += externalVoltageInfo;
}
}
}
#endif

if (Config.battery.sendVoltageAsTelemetry && !Config.bme.active){
String encodedTelemetry = BATTERY_Utils::generateEncodedTelemetry();
beaconPacket += encodedTelemetry;
secondaryBeaconPacket += encodedTelemetry;
}

if (Config.aprs_is.active && Config.beacon.sendViaAPRSIS && !backUpDigiMode) {
Utils::println("-- Sending Beacon to APRSIS --");
displayShow(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING IGATE BEACON", 0);
Expand Down
2 changes: 2 additions & 0 deletions src/web_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ namespace WEB_Utils {
}
Config.battery.monitorExternalVoltage = request->hasParam("battery.monitorExternalVoltage", true);
Config.battery.externalSleepVoltage = request->getParam("battery.externalSleepVoltage", true)->value().toFloat();

Config.battery.sendVoltageAsTelemetry = request->hasParam("battery.sendVoltageAsTelemetry", true);

Config.bme.active = request->hasParam("bme.active", true);
Config.bme.heightCorrection = request->getParam("bme.heightCorrection", true)->value().toInt();
Expand Down

0 comments on commit 0e46c64

Please sign in to comment.