Budka posílá každých ~30 s po jednosměrném UARTu řádek `CB1 id=… t= h= p= v= i= w= wh= mot= up=…*XX` (NMEA XOR součet). BudkaLinkSensorManager je EnvironmentSensorManager + Serial1 RX: řádek se špatným součtem zahodí celý, hodnoty starší než 2 min do telemetrie nedává. Všechno z budky jde na jeden LPP kanál za čidly na desce; výkon jako analog input (LPP_POWER má rozlišení 1 W). TX UARTu je LED_GREEN — nic se nevysílá a klidová jednička ji drží zhasnutou. Zapíná se jen -D BUDKA_LINK_RX_PIN=<pin>; bez něj se nic nemění. Nový env Xiao_nrf52_sensor (upstream pro XIAO nRF sensor neměl). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
58 lines
1.8 KiB
C++
58 lines
1.8 KiB
C++
#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;
|
|
};
|