Files
butterfly-edfa-rack-firmware/include/config.h
T
James Bateman (hp-laptop) 58475386ba Butterfly EDFA Rack bridge: seed + EDFA over WiFi/MQTT to Home Assistant
ESP32 firmware bridging the 1550 nm MOPA (Koheron CTL200 seed + Agiltron
M511 two-stage EDFA) to MQTT/HA as a single device. Telemetry and control
for both instruments verified end-to-end: MQTT command -> seed lasing ->
booster ramp to 27 dBm (~515 mW) at the documented 2500 mA operating point.

- PlatformIO/Arduino project, project-local venv, Makefile upload flow
- Koheron ASCII driver on UART2; Agiltron binary 0x55AA driver on UART1
- HA discovery (sensors, binary_sensors, switches, numbers); LWT availability
- Static IP, firmware current clamps on seed and booster pump
2026-06-19 10:16:50 +01:00

66 lines
3.3 KiB
C

// Compile-time configuration for the Butterfly EDFA Rack bridge.
#pragma once
#include "secrets.h"
// ── MQTT topics ─────────────────────────────────────────────────────
// One HA device, one topic base. Sub-units namespaced under it:
// <base>/availability online | offline (LWT)
// <base>/diag/<key> ESP/network diagnostics
// <base>/seed/<key> Koheron CTL200 (increment 3)
// <base>/amp/<key> Agiltron M511 EYDFA (increment 4)
// <base>/set/<...> command topics (increment 5)
#define TOPIC_BASE "lab/laser/" DEVICE_NAME
#define TOPIC_AVAIL TOPIC_BASE "/availability"
#define DISCOVERY_PREFIX "homeassistant"
#define AVAIL_ONLINE "online"
#define AVAIL_OFFLINE "offline"
#define TOPIC_CMD TOPIC_BASE "/set" // subscribe <base>/set/#
// ── Agiltron M511 identity & safety limits ──────────────────────────
// SN Y4022708 / PN EDFA-1C51113331111 -> device ID 0x0000006F (edfa.py).
// Startup reads SN/PN and logs them so the ID is confirmed before control.
#define AGILTRON_DEV_ID 0x00, 0x00, 0x00, 0x6F
// HA number sliders are capped here. The hardware allows 8000 mA pump, but
// the lab notes report ~2500 mA pump-1 -> ~27 dBm (~515 mW). Keep a margin.
#define SEED_CURRENT_MAX_MA 300 // CTL200 ilmax default is 1000; seed DFB is low-power
#define PUMP_CURRENT_MAX_MA 3000 // firmware clamps amp pump-1 to this
// ── Serial links to the instruments (wired in later increments) ─────
// UART0 stays the USB console. The classic ESP32 has 3 hardware UARTs.
//
// Koheron CTL200 (ASCII, 115200 8N1, "\r\n", ">>" prompt) -> UART2
// ESP32 GPIO17 (TX2) -> CTL200 RX, GPIO16 (RX2) <- CTL200 TX, GND
//
// Agiltron M511 (binary 0x55AA packets, 115200 8N1) -> UART1
// ESP32 GPIO26 (TX1) -> M511 RX(pin3), GPIO25 (RX1) <- M511 TX(pin7), GND
// (UART1 default pins clash with SPI flash on WROOM, so remap to 26/25.)
#define KOHERON_UART_NUM 2
#define KOHERON_TX_PIN 17
#define KOHERON_RX_PIN 16
#define KOHERON_BAUD 115200
#define AGILTRON_UART_NUM 1
#define AGILTRON_TX_PIN 26
#define AGILTRON_RX_PIN 25
#define AGILTRON_BAUD 115200
// ── Static IP ───────────────────────────────────────────────────────
// Pinned to .150 (free as of 2026-06-17) to avoid the DHCP clash with the
// BKtel EDFA Pi on .101. Comment out USE_STATIC_IP to fall back to DHCP.
#define USE_STATIC_IP
#define STATIC_IP_OCTETS 192, 168, 0, 150
#define GATEWAY_OCTETS 192, 168, 0, 1
#define SUBNET_OCTETS 255, 255, 255, 0
#define DNS_OCTETS 192, 168, 0, 1
// ── Timing ──────────────────────────────────────────────────────────
#define PUBLISH_INTERVAL_MS 2000 // telemetry cadence
#define MQTT_RECONNECT_MS 5000
// PubSubClient's default 256-byte buffer is too small for discovery
// payloads that embed the device block; bump it.
#define MQTT_BUFFER_SIZE 1024