a544594769
- cabin_node: subscribes to local MQTT (ESPHome sensors), sends temperature, battery voltage/SOC and switch states over LoRa SF12 - cabin_gw: receives LoRa packets, publishes JSON to home MQTT broker - Bidirectional: gateway forwards ON/OFF commands from home HA to node - cabin_node always in RX mode (12V powered) — commands arrive instantly - ESPHome config for ESP32 on teknisk rom: Victron MPPT BLE + JBD BMS BLE + DS18B20 temperatures + GPIO switches for varme/VVB Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
37 lines
1.2 KiB
C
37 lines
1.2 KiB
C
#pragma once
|
||
#include <stdint.h>
|
||
|
||
#define CABIN_PACKET_MAGIC 0xCA
|
||
#define CABIN_CMD_MAGIC 0xCB
|
||
|
||
// Command IDs
|
||
#define CMD_VARME 0x01
|
||
#define CMD_VVB 0x02 // varmtvannsbereder
|
||
|
||
// Wire format: 13 bytes total
|
||
// At SF12 BW125: ~1.3s airtime
|
||
// flags bits: 0=varme, 1=vvb (1=on, 0=off)
|
||
#define CABIN_FLAG_VARME (1 << 0)
|
||
#define CABIN_FLAG_VVB (1 << 1)
|
||
|
||
struct __attribute__((packed)) CabinPacket {
|
||
uint8_t magic; // = CABIN_PACKET_MAGIC
|
||
uint8_t seq; // rolling counter
|
||
int16_t temp_in_x10; // indoor temp * 10 (213 = 21.3 °C), INT16_MIN = no data
|
||
int16_t temp_out_x10; // outdoor temp * 10, INT16_MIN = no data
|
||
uint16_t batt_mv; // battery voltage mV (12V system: ~10000–14400)
|
||
uint8_t batt_pct; // SOC 0–100, 0xFF = no data
|
||
uint8_t flags; // switch states: bit0=varme, bit1=vvb
|
||
uint32_t sig; // truncated HMAC-SHA256
|
||
};
|
||
|
||
// Command packet: home → gateway → node → ESPHome switch
|
||
// 8 bytes total
|
||
struct __attribute__((packed)) CabinCmdPacket {
|
||
uint8_t magic; // = CABIN_CMD_MAGIC
|
||
uint8_t seq;
|
||
uint8_t cmd_id; // CMD_VARME, CMD_VVB, ...
|
||
uint8_t value; // 0 = off, 1 = on
|
||
uint32_t sig;
|
||
};
|