#pragma once // Telemetry from a Chytra Budka (ESP32-S3 bird box) over a one-way UART line. // // 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 v=5.04 i=0.221 w=1.11 wh=310.75 mot=3 up=1234*5A\r\n // // `*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 // could not read are simply absent; a value not refreshed for // BUDKA_LINK_STALE_MS is left out of the telemetry instead of being reported // stale. // // Wiring: budka "mc_tx" pad -> BUDKA_LINK_RX_PIN, plus GND. The UART needs a TX // pin too, but nothing is ever sent; BUDKA_LINK_TX_PIN defaults to the XIAO's // LED_GREEN, which idles HIGH (= LED off) like an unused TX line does. #include "EnvironmentSensorManager.h" #ifndef BUDKA_LINK_BAUD #define BUDKA_LINK_BAUD 115200 #endif #ifndef BUDKA_LINK_STALE_MS #define BUDKA_LINK_STALE_MS (120UL * 1000UL) #endif class BudkaLinkSensorManager : public EnvironmentSensorManager { public: bool begin() override; 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. bool hasMotion() const { return mot_valid; } uint32_t motionCount() const { return mot; } unsigned long lastLineMillis() const { return last_line_ms; } private: struct Val { float v = 0; unsigned long at = 0; // millis() of the last update, 0 = never }; Val t, h, p, volt, amp, watt, wh; uint32_t mot = 0; bool mot_valid = false; unsigned long mot_at = 0; unsigned long last_line_ms = 0; char line[200]; size_t len = 0; void handleLine(); bool fresh(const Val& x) const; };