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:
1 parent
560bf24fc2
commit
a6a5dc7dfc
2 files changed
+39
-23
No files matched your search
@@ -74,14 +74,20 @@ void BudkaLinkSensorManager::handleLine() {
|
|||||||
if (!strcmp(k, "t")) dst = &t;
|
if (!strcmp(k, "t")) dst = &t;
|
||||||
else if (!strcmp(k, "h")) dst = &h;
|
else if (!strcmp(k, "h")) dst = &h;
|
||||||
else if (!strcmp(k, "p")) dst = &p;
|
else if (!strcmp(k, "p")) dst = &p;
|
||||||
else if (!strcmp(k, "v")) dst = &volt;
|
|
||||||
else if (!strcmp(k, "i")) dst = &
|
|
||||||
else if (!strcmp(k, "w")) dst = &watt;
|
|
||||||
else if (!strcmp(k, "wh")) dst = &wh;
|
|
||||||
else if (!strcmp(k, "mot")) {
|
else if (!strcmp(k, "mot")) {
|
||||||
mot = strtoul(v, NULL, 10);
|
mot = strtoul(v, NULL, 10);
|
||||||
mot_valid = true;
|
mot_valid = true;
|
||||||
mot_at = now;
|
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 = &[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) {
|
if (dst) {
|
||||||
dst->v = strtof(v, NULL);
|
dst->v = strtof(v, NULL);
|
||||||
@@ -95,24 +101,25 @@ bool BudkaLinkSensorManager::querySensors(uint8_t requester_permissions, Cayenne
|
|||||||
EnvironmentSensorManager::querySensors(requester_permissions, telemetry);
|
EnvironmentSensorManager::querySensors(requester_permissions, telemetry);
|
||||||
if (!(requester_permissions & TELEM_PERM_ENVIRONMENT)) return true;
|
if (!(requester_permissions & TELEM_PERM_ENVIRONMENT)) return true;
|
||||||
|
|
||||||
// Everything from the budka shares one channel: the first one after the
|
// The box's own sensors share one channel (CayenneLPP allows one value per
|
||||||
// on-board sensors. CayenneLPP allows one value per (channel, type).
|
// (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;
|
uint8_t ch = next_available_channel;
|
||||||
bool any = false;
|
if (fresh(t)) telemetry.addTemperature(ch, t.v);
|
||||||
if (fresh(t)) { telemetry.addTemperature(ch, t.v); any = true; }
|
if (fresh(h)) telemetry.addRelativeHumidity(ch, h.v);
|
||||||
if (fresh(h)) { telemetry.addRelativeHumidity(ch, h.v); any = true; }
|
if (fresh(p)) telemetry.addBarometricPressure(ch, p.v);
|
||||||
if (fresh(p)) { telemetry.addBarometricPressure(ch, p.v); any = true; }
|
if (mot_valid && (millis() - mot_at) < BUDKA_LINK_STALE_MS) telemetry.addGenericSensor(ch, (float)mot);
|
||||||
if (fresh(volt)) { telemetry.addVoltage(ch, volt.v); any = true; }
|
for (int k = 0; k < BUDKA_LINK_METERS; k++) {
|
||||||
if (fresh(amp)) { telemetry.addCurrent(ch, amp.v); any = true; }
|
uint8_t mch = ch + 1 + k;
|
||||||
// LPP_POWER is whole watts, unsigned — useless for a ~1 W box. Analog input
|
if (fresh(volt[k])) telemetry.addVoltage(mch, volt[k].v);
|
||||||
// carries 0.01 resolution.
|
if (fresh(amp[k])) telemetry.addCurrent(mch, amp[k].v);
|
||||||
if (fresh(watt)) { telemetry.addAnalogInput(ch, watt.v); any = true; }
|
// LPP_POWER is whole watts, unsigned — useless for a ~1 W load. Analog
|
||||||
if (fresh(wh)) { telemetry.addEnergy(ch, wh.v / 1000.0f); any = true; } // LPP energy is kWh
|
// input carries 0.01 resolution.
|
||||||
if (mot_valid && (millis() - mot_at) < BUDKA_LINK_STALE_MS) {
|
if (fresh(watt[k])) telemetry.addAnalogInput(mch, watt[k].v);
|
||||||
telemetry.addGenericSensor(ch, (float)mot);
|
if (fresh(wh[k])) telemetry.addEnergy(mch, wh[k].v / 1000.0f); // LPP energy is kWh
|
||||||
any = true;
|
|
||||||
}
|
}
|
||||||
if (any) next_available_channel++;
|
if (last_line_ms != 0) next_available_channel = ch + 1 + BUDKA_LINK_METERS;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,12 @@
|
|||||||
// The budka sends one NMEA-style line every ~30 s (firmware/main/mc_link.h in
|
// The budka sends one NMEA-style line every ~30 s (firmware/main/mc_link.h in
|
||||||
// the chytra-budka repo):
|
// the chytra-budka repo):
|
||||||
//
|
//
|
||||||
// CB1 id=fbfe18 t=21.4 h=63 p=1013.2 v=5.04 i=0.221 w=1.11 wh=310.75 mot=3 up=1234*5A\r\n
|
// CB1 id=fbfe18 t=21.4 h=63 p=1013.2 v1=5.04 i1=0.221 w1=1.11 wh1=310.75
|
||||||
|
// v2=4.96 i2=0.090 w2=0.45 wh2=111.70 mot=3 up=1234*5A\r\n (one line)
|
||||||
|
//
|
||||||
|
// Meters are numbered 1..BUDKA_LINK_METERS in id order on the budka. The box's
|
||||||
|
// own sensors (t/h/p/mot) take one LPP channel; meter k gets the k-th channel
|
||||||
|
// after it.
|
||||||
//
|
//
|
||||||
// `*XX` is the XOR of every byte between the leading 'C' and the '*'. A line
|
// `*XX` is the XOR of every byte between the leading 'C' and the '*'. A line
|
||||||
// with a bad checksum or an unknown version is dropped whole. Keys the budka
|
// with a bad checksum or an unknown version is dropped whole. Keys the budka
|
||||||
@@ -22,6 +27,9 @@
|
|||||||
#ifndef BUDKA_LINK_BAUD
|
#ifndef BUDKA_LINK_BAUD
|
||||||
#define BUDKA_LINK_BAUD 115200
|
#define BUDKA_LINK_BAUD 115200
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef BUDKA_LINK_METERS
|
||||||
|
#define BUDKA_LINK_METERS 3
|
||||||
|
#endif
|
||||||
#ifndef BUDKA_LINK_STALE_MS
|
#ifndef BUDKA_LINK_STALE_MS
|
||||||
#define BUDKA_LINK_STALE_MS (120UL * 1000UL)
|
#define BUDKA_LINK_STALE_MS (120UL * 1000UL)
|
||||||
#endif
|
#endif
|
||||||
@@ -43,13 +51,14 @@ private:
|
|||||||
float v = 0;
|
float v = 0;
|
||||||
unsigned long at = 0; // millis() of the last update, 0 = never
|
unsigned long at = 0; // millis() of the last update, 0 = never
|
||||||
};
|
};
|
||||||
Val t, h, p, volt, amp, watt, wh;
|
Val t, h, p;
|
||||||
|
Val volt[BUDKA_LINK_METERS], amp[BUDKA_LINK_METERS], watt[BUDKA_LINK_METERS], wh[BUDKA_LINK_METERS];
|
||||||
uint32_t mot = 0;
|
uint32_t mot = 0;
|
||||||
bool mot_valid = false;
|
bool mot_valid = false;
|
||||||
unsigned long mot_at = 0;
|
unsigned long mot_at = 0;
|
||||||
unsigned long last_line_ms = 0;
|
unsigned long last_line_ms = 0;
|
||||||
|
|
||||||
char line[200];
|
char line[256];
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
|
||||||
void handleLine();
|
void handleLine();
|
||||||
|
|||||||
Reference in new issue
Block a user