Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update power_utils.cpp #88

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/power_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,20 @@ namespace POWER_Utils {
return (2 * (voltage + 0.1)) * (1 + (lora32BatReadingCorr/100)); // (2 x 100k voltage divider) 2 x voltage divider/+0.1 because ESP32 nonlinearity ~100mV ADC offset/extra correction
#endif
#if defined(HELTEC_V3_GPS) || defined(HELTEC_WIRELESS_TRACKER) || defined(ESP32_C3_DIY_LoRa_GPS)
double inputDivider = (1.0 / (390.0 + 100.0)) * 100.0; // The voltage divider is a 390k + 100k resistor in series, 100k on the low side.
return (voltage / inputDivider) + 0.285; // Yes, this offset is excessive, but the ADC on the ESP32s3 is quite inaccurate and noisy. Adjust to own measurements.
#endif
int adc_value = analogRead(BATTERY_PIN);

// Compute corrected_adc_value using your inputDivider
double inputDivider = (1.0 / (390.0 + 100.0)) * 100.0;
double corrected_adc_value = inputDivider * adc_value;

// Adjusted linear equation coefficients
double slope = 0.0045; // Adjusted slope
double intercept = 3.3; // Adjusted intercept

double voltage = slope * corrected_adc_value + intercept; // Calculate voltage using adjusted linear equation
// Serial.println( String(voltage) + "v ADC: " + String(adc_value));
return voltage;
#endif
#else
return 0.0;
#endif
Expand Down Expand Up @@ -385,4 +396,4 @@ namespace POWER_Utils {
#endif
}

}
}
97 changes: 54 additions & 43 deletions src/station_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,55 +386,66 @@ namespace STATION_Utils {
}

void sendBeacon(String type) {
String packet;
if (Config.bme.sendTelemetry && type == "Wx") {
if (miceActive) {
packet = APRSPacketLib::generateMiceGPSBeacon(currentBeacon->micE, currentBeacon->callsign,"_", currentBeacon->overlay, Config.path, gps.location.lat(), gps.location.lng(), gps.course.deg(), gps.speed.knots(), gps.altitude.meters());
if (lastTxTime <= (millis() - 5000)) {
String packet;
if (Config.bme.sendTelemetry && type == "Wx") {
if (miceActive) {
packet = APRSPacketLib::generateMiceGPSBeacon(currentBeacon->micE, currentBeacon->callsign,"_", currentBeacon->overlay, Config.path, gps.location.lat(), gps.location.lng(), gps.course.deg(), gps.speed.knots(), gps.altitude.meters());
} else {
packet = APRSPacketLib::generateGPSBeaconPacket(currentBeacon->callsign, "APLRT1", Config.path, "/", APRSPacketLib::encodeGPS(gps.location.lat(),gps.location.lng(), gps.course.deg(), gps.speed.knots(), currentBeacon->symbol, Config.sendAltitude, gps.altitude.feet(), sendStandingUpdate, "Wx"));
}
packet += BME_Utils::readDataSensor("APRS");
} else {
packet = APRSPacketLib::generateGPSBeaconPacket(currentBeacon->callsign, "APLRT1", Config.path, "/", APRSPacketLib::encodeGPS(gps.location.lat(),gps.location.lng(), gps.course.deg(), gps.speed.knots(), currentBeacon->symbol, Config.sendAltitude, gps.altitude.feet(), sendStandingUpdate, "Wx"));
if (miceActive) {
packet = APRSPacketLib::generateMiceGPSBeacon(currentBeacon->micE, currentBeacon->callsign, currentBeacon->symbol, currentBeacon->overlay, Config.path, gps.location.lat(), gps.location.lng(), gps.course.deg(), gps.speed.knots(), gps.altitude.meters());
} else {
packet = APRSPacketLib::generateGPSBeaconPacket(currentBeacon->callsign, "APLRT1", Config.path, currentBeacon->overlay, APRSPacketLib::encodeGPS(gps.location.lat(),gps.location.lng(), gps.course.deg(), gps.speed.knots(), currentBeacon->symbol, Config.sendAltitude, gps.altitude.feet(), sendStandingUpdate, "GPS"));
}
}
packet += BME_Utils::readDataSensor("APRS");
} else {
if (miceActive) {
packet = APRSPacketLib::generateMiceGPSBeacon(currentBeacon->micE, currentBeacon->callsign, currentBeacon->symbol, currentBeacon->overlay, Config.path, gps.location.lat(), gps.location.lng(), gps.course.deg(), gps.speed.knots(), gps.altitude.meters());
} else {
packet = APRSPacketLib::generateGPSBeaconPacket(currentBeacon->callsign, "APLRT1", Config.path, currentBeacon->overlay, APRSPacketLib::encodeGPS(gps.location.lat(),gps.location.lng(), gps.course.deg(), gps.speed.knots(), currentBeacon->symbol, Config.sendAltitude, gps.altitude.feet(), sendStandingUpdate, "GPS"));
if (currentBeacon->comment != "") {
updateCounter++;
if (updateCounter >= Config.sendCommentAfterXBeacons) {
packet += currentBeacon->comment;
updateCounter = 0;
}
}
}
if (currentBeacon->comment != "") {
updateCounter++;
if (updateCounter >= Config.sendCommentAfterXBeacons) {
packet += currentBeacon->comment;
updateCounter = 0;
}
}
if (Config.sendBatteryInfo) {
String batteryVoltage = POWER_Utils::getBatteryInfoVoltage();
String batteryChargeCurrent = POWER_Utils::getBatteryInfoCurrent();
#if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_0_SX1268)
packet += " Bat=" + batteryVoltage + "V (" + batteryChargeCurrent + "mA)";
#endif
#if defined(TTGO_T_Beam_V1_2) || defined(TTGO_T_Beam_V1_2_SX1262)
packet += " Bat=" + String(batteryVoltage.toFloat()/1000,2) + "V (" + batteryChargeCurrent + "%)";
if (Config.sendBatteryInfo) {
String batteryVoltage = POWER_Utils::getBatteryInfoVoltage();
String batteryChargeCurrent = POWER_Utils::getBatteryInfoCurrent();
TelemetryCounter++;
if (TelemetryCounter >= 1000) {
TelemetryCounter = 0;
}

#if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_0_SX1268)
packet += " Bat=" + batteryVoltage + "V (" + batteryChargeCurrent + "mA)";
#endif
#if defined(TTGO_T_Beam_V1_2) || defined(TTGO_T_Beam_V1_2_SX1262)
packet += " Bat=" + String(batteryVoltage.toFloat()/1000,2) + "V (" + batteryChargeCurrent + "%)";
#endif
#if defined(HELTEC_V3_GPS)
packet += " Bat=" + String(batteryVoltage.toFloat(),2) + "V";
#endif
}
#ifdef HAS_TFT
cleanTFT();
#endif
#if defined(HELTEC_V3_GPS)
packet += " Bat=" + String(batteryVoltage.toFloat(),2) + "V";
show_display("<<< TX >>>", "", packet,100);
LoRa_Utils::sendNewPacket(packet);
#ifdef HAS_TFT
cleanTFT();

#endif
}
#ifdef HAS_TFT
cleanTFT();
#endif
show_display("<<< TX >>>", "", packet,100);
LoRa_Utils::sendNewPacket(packet);

if (smartBeaconValue) {
lastTxLat = gps.location.lat();
lastTxLng = gps.location.lng();
previousHeading = currentHeading;
lastTxDistance = 0.0;
if (smartBeaconValue) {
lastTxLat = gps.location.lat();
lastTxLng = gps.location.lng();
previousHeading = currentHeading;
lastTxDistance = 0.0;
}
lastTxTime = millis();
sendUpdate = false;
}
lastTxTime = millis();
sendUpdate = false;
}

void checkTelemetryTx() {
Expand Down Expand Up @@ -495,4 +506,4 @@ namespace STATION_Utils {
}
}

}
}