sensor/budka: každý měřák na vlastním LPP kanálu

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5.5 committed 2026-10-13 02:32:03 +02:00
1 parent 560bf24fc2
commit a6a5dc7dfc
2 files changed
+39 -23

No files matched your search

+27 -20
View File
@@ -74,14 +74,20 @@ void BudkaLinkSensorManager::handleLine() {
if (!strcmp(k, "t")) dst = &t;
else if (!strcmp(k, "h")) dst = &h;
else if (!strcmp(k, "p")) dst = &p;
else if (!strcmp(k, "v")) dst = &volt;
else if (!strcmp(k, "i")) dst = &amp;
else if (!strcmp(k, "w")) dst = &watt;
else if (!strcmp(k, "wh")) dst = &wh;
else if (!strcmp(k, "mot")) {
mot = strtoul(v, NULL, 10);
mot_valid = true;
mot_at = now;
} else {
// Meter fields: v<k> i<k> w<k> wh<k>, k = 1..BUDKA_LINK_METERS.
size_t kl = strlen(k);
int idx = (kl >= 2) ? k[kl - 1] - '1' : -1;
if (idx >= 0 && idx < BUDKA_LINK_METERS) {
if (kl == 2 && k[0] == 'v') dst = &volt[idx];
else if (kl == 2 && k[0] == 'i') dst = &amp[idx];
else if (kl == 2 && k[0] == 'w') dst = &watt[idx];
else if (kl == 3 && k[0] == 'w' && k[1] == 'h') dst = &wh[idx];
}
}
if (dst) {
dst->v = strtof(v, NULL);
@@ -95,24 +101,25 @@ bool BudkaLinkSensorManager::querySensors(uint8_t requester_permissions, Cayenne
EnvironmentSensorManager::querySensors(requester_permissions, telemetry);
if (!(requester_permissions & TELEM_PERM_ENVIRONMENT)) return true;
// Everything from the budka shares one channel: the first one after the
// on-board sensors. CayenneLPP allows one value per (channel, type).
// The box's own sensors share one channel (CayenneLPP allows one value per
// (channel, type)); meter k gets the k-th channel after it. Channels are
// kept even when a meter is momentarily missing, so a meter's numbers never
// move to another channel between two requests.
uint8_t ch = next_available_channel;
bool any = false;
if (fresh(t)) { telemetry.addTemperature(ch, t.v); any = true; }
if (fresh(h)) { telemetry.addRelativeHumidity(ch, h.v); any = true; }
if (fresh(p)) { telemetry.addBarometricPressure(ch, p.v); any = true; }
if (fresh(volt)) { telemetry.addVoltage(ch, volt.v); any = true; }
if (fresh(amp)) { telemetry.addCurrent(ch, amp.v); any = true; }
// LPP_POWER is whole watts, unsigned — useless for a ~1 W box. Analog input
// carries 0.01 resolution.
if (fresh(watt)) { telemetry.addAnalogInput(ch, watt.v); any = true; }
if (fresh(wh)) { telemetry.addEnergy(ch, wh.v / 1000.0f); any = true; } // LPP energy is kWh
if (mot_valid && (millis() - mot_at) < BUDKA_LINK_STALE_MS) {
telemetry.addGenericSensor(ch, (float)mot);
any = true;
if (fresh(t)) telemetry.addTemperature(ch, t.v);
if (fresh(h)) telemetry.addRelativeHumidity(ch, h.v);
if (fresh(p)) telemetry.addBarometricPressure(ch, p.v);
if (mot_valid && (millis() - mot_at) < BUDKA_LINK_STALE_MS) telemetry.addGenericSensor(ch, (float)mot);
for (int k = 0; k < BUDKA_LINK_METERS; k++) {
uint8_t mch = ch + 1 + k;
if (fresh(volt[k])) telemetry.addVoltage(mch, volt[k].v);
if (fresh(amp[k])) telemetry.addCurrent(mch, amp[k].v);
// LPP_POWER is whole watts, unsigned — useless for a ~1 W load. Analog
// input carries 0.01 resolution.
if (fresh(watt[k])) telemetry.addAnalogInput(mch, watt[k].v);
if (fresh(wh[k])) telemetry.addEnergy(mch, wh[k].v / 1000.0f); // LPP energy is kWh
}
if (any) next_available_channel++;
if (last_line_ms != 0) next_available_channel = ch + 1 + BUDKA_LINK_METERS;
return true;
}