fix(bot): !temp and {temp} fall back to the chip's temperature

Same gap as the screens had: the bot reply, a typed message's {temp} and
the placeholder lists read only the sensors, so a board without one (the
L1) answered !temp with n/a while its telemetry carried a temperature.
The fallback moves to LocalSensors.h, shared by the screens, expandMsg()
and sensorPlaceholders(); the latter now takes the chip's temperature.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jakub
2026-10-23 22:55:19 +02:00
co-authored by Claude Opus 5.5
parent 21feec0972
commit 24156769f0
11 changed files with 43 additions and 36 deletions
@@ -35,11 +35,11 @@ static void seedQuick(NodePrefs* p) {
// ── Placeholders ──────────────────────────────────────────────────────────────
// The sensor readings this device has right now, as placeholders ({temp},
// {hum}, ...; {batt} only from a voltage sensor).
static void sensorPlaceholders(SensorManager* sm, void (*add)(const char* ph, void* ctx), void* ctx) {
// {hum}, ...; {batt} only from a voltage sensor; {temp} also from the chip, mcu_temp).
static void sensorPlaceholders(SensorManager* sm, float mcu_temp, void (*add)(const char* ph, void* ctx), void* ctx) {
if (!sm) return;
CayenneLPP lpp(100);
sm->querySensors(0xFF, lpp);
queryLocalSensors(*sm, mcu_temp, lpp);
uint8_t present[16];
int pc = 0;
LPPReader r(lpp.getBuffer(), lpp.getSize());
@@ -62,12 +62,12 @@ static void sensorPlaceholders(SensorManager* sm, void (*add)(const char* ph, vo
// Everything a message can carry here: {loc}, {time}, {batt} (the board's
// voltage), then the sensors'.
static void placeholders(SensorManager* sm, void (*add)(const char* ph, void* ctx), void* ctx) {
static void placeholders(SensorManager* sm, float mcu_temp, void (*add)(const char* ph, void* ctx), void* ctx) {
add("{loc}", ctx);
add("{time}", ctx);
add("{batt}", ctx);
struct Skip { void (*add)(const char*, void*); void* ctx; } skip = { add, ctx };
sensorPlaceholders(sm, [](const char* ph, void* c) {
sensorPlaceholders(sm, mcu_temp, [](const char* ph, void* c) {
Skip* s = (Skip*)c;
if (strcmp(ph, "{batt}") != 0) s->add(ph, s->ctx); // already there
}, &skip);
@@ -89,7 +89,7 @@ static void expand(const char* tmpl, char* out, int n, const NodePrefs* p) {
#endif
float batt = (float)board.getBattMilliVolts() / 1000.0f;
::expandMsg(tmpl, out, n, lat, lon, gps_valid, rtc_clock.getCurrentTime(),
p ? p->tz_offset_hours : 0, &sensors, batt);
p ? p->tz_offset_hours : 0, &sensors, batt, nullptr, -1, board.getMCUTemperature());
}
// A typed message: a reply's leading "@[nick] " stays as it is (a nick may
@@ -7,8 +7,6 @@
#include <stdint.h>
#include <stdio.h>
#include <math.h>
#include <helpers/SensorManager.h>
#include <helpers/sensors/LPPDataHelpers.h>
#include <helpers/sensors/LocationProvider.h>
#include "Battery.h"
@@ -66,21 +64,6 @@ static uint8_t lppType(uint8_t f) {
// Read from the sensors, not the radio or GPS.
static bool isSensor(uint8_t f) { return lppType(f) != 0; }
// The sensors' readings, plus the chip's own temperature (NaN where a board has
// none) when no sensor reads one: the telemetry reply sends it too, so a board
// without a temperature sensor shows on screen what the app shows.
static void querySensors(SensorManager& sm, float mcu_temp, CayenneLPP& lpp) {
sm.querySensors(0xFF, lpp);
if (isnan(mcu_temp)) return;
LPPReader r(lpp.getBuffer(), lpp.getSize());
uint8_t ch, type;
while (r.readHeader(ch, type)) {
if (type == LPP_TEMPERATURE) return;
r.skipData(type);
}
lpp.addTemperature(TELEM_CHANNEL_SELF, mcu_temp);
}
// Altitude always in the small unit (never km / mi).
static void altText(float m, bool imperial, const Style& st, char* v, int n) {
snprintf(v, n, "%.0f%s%s", imperial ? m * 3.28084f : m, st.spaced ? " " : "", imperial ? "ft" : "m");