diff --git a/src/helpers/sensors/BudkaLinkSensorManager.cpp b/src/helpers/sensors/BudkaLinkSensorManager.cpp index 46eba573..59e6612f 100644 --- a/src/helpers/sensors/BudkaLinkSensorManager.cpp +++ b/src/helpers/sensors/BudkaLinkSensorManager.cpp @@ -75,9 +75,13 @@ void BudkaLinkSensorManager::handleLine() { else if (!strcmp(k, "h")) dst = &h; else if (!strcmp(k, "p")) dst = &p; else if (!strcmp(k, "mot")) { - mot = strtoul(v, NULL, 10); - mot_valid = true; - mot_at = now; + char* end; + unsigned long m = strtoul(v, &end, 10); + if (end != v) { + mot = m; + mot_valid = true; + mot_at = now; + } } else { // Meter fields: v i w wh, k = 1..BUDKA_LINK_METERS. size_t kl = strlen(k); @@ -90,8 +94,12 @@ void BudkaLinkSensorManager::handleLine() { } } if (dst) { - dst->v = strtof(v, NULL); - dst->at = now; + char* end; + float f = strtof(v, &end); + if (end != v) { // "v1=" with no number is not a reading + dst->v = f; + dst->at = now; + } } } last_line_ms = now; diff --git a/src/helpers/sensors/BudkaLinkSensorManager.h b/src/helpers/sensors/BudkaLinkSensorManager.h index 57e17e7e..4fa7bc49 100644 --- a/src/helpers/sensors/BudkaLinkSensorManager.h +++ b/src/helpers/sensors/BudkaLinkSensorManager.h @@ -5,7 +5,7 @@ // The budka sends one NMEA-style line every ~30 s (firmware/main/mc_link.h in // the chytra-budka repo): // -// CB1 id=fbfe18 t=21.4 h=63 p=1013.2 v1=5.04 i1=0.221 w1=1.11 wh1=310.75 +// CB1 id=0a1b2c 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 @@ -24,6 +24,10 @@ #include "EnvironmentSensorManager.h" +#if ENV_INCLUDE_GPS + #error "BudkaLinkSensorManager uses Serial1, which the GPS code also claims" +#endif + #ifndef BUDKA_LINK_BAUD #define BUDKA_LINK_BAUD 115200 #endif @@ -40,8 +44,10 @@ public: bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) override; void loop() override; - // Last motion count and the time it last increased (0 = never), so the - // app can raise an alert on new motion. + // Cumulative PIR count as last reported by the budka (hasMotion() = the + // budka has a PIR and sent a count), and millis() of the last valid line + // (0 = none yet) — enough for an app to alert on new motion or a silent + // budka. bool hasMotion() const { return mot_valid; } uint32_t motionCount() const { return mot; } unsigned long lastLineMillis() const { return last_line_ms; }