Skip to content
Merged
Changes from 1 commit
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
12 changes: 8 additions & 4 deletions src/modules/Telemetry/DeviceTelemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,21 @@ meshtastic_Telemetry DeviceTelemetryModule::getDeviceTelemetry()
t.variant.device_metrics.has_air_util_tx = true;
t.variant.device_metrics.has_battery_level = true;
t.variant.device_metrics.has_channel_utilization = true;
t.variant.device_metrics.has_voltage = true;
t.variant.device_metrics.has_uptime_seconds = true;

t.variant.device_metrics.air_util_tx = airTime->utilizationTXPercent();
t.variant.device_metrics.battery_level = (!powerStatus->getHasBattery() || powerStatus->getIsCharging())
? MAGIC_USB_BATTERY_LEVEL
: powerStatus->getBatteryChargePercent();
t.variant.device_metrics.channel_utilization = airTime->channelUtilizationPercent();
t.variant.device_metrics.voltage = powerStatus->getBatteryVoltageMv() / 1000.0;
// Only populate voltage when we actually have a battery reading. Previously this assigned
// -0.001 (from -1 mV / 1000) whenever the ADC returned -1, leaking a sentinel onto the wire
// that clients then displayed as a real negative voltage. See GH #7958.
uint16_t batteryMv = powerStatus->getBatteryVoltageMv();
if (powerStatus->getHasBattery() && batteryMv > 0) {
t.variant.device_metrics.has_voltage = true;
t.variant.device_metrics.voltage = batteryMv / 1000.0f;
}

Copilot AI Apr 21, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

powerStatus->getBatteryVoltageMv() returns an int (and can be -1 per PowerStatus ctor default). Storing it in a uint16_t will wrap -1 to 65535, making batteryMv > 0 true and causing has_voltage to be set with an incorrect ~65.5V reading. Use a signed type (e.g., int batteryMv) and gate on batteryMv > 0 (optionally also sanity-check an upper bound) before setting has_voltage/voltage.

Copilot uses AI. Check for mistakes.
t.variant.device_metrics.uptime_seconds = getUptimeSeconds();

return t;
}

Expand Down
Loading