feat(relays): generic HTTP relay board, and point band switching at it

An operator was about to build band→relay mapping into the custom URL rows.
It already exists, and better: relay auto-control has a per-relay "band" rule
driving webswitch, KMTronic, Dingtian, Denkovi and USB boards. It holds state
so a relay is only commanded when its wanted position changed, reads the
boards live before the first apply so it does not re-command one already in
place, and carries per-relay labels. A URL fired on a band change has none of
that, and would have been a second definition of "which antenna on which band"
— the drift that cost us a week on counties.

So the gap was only the hardware: a hand-made switch is none of the five named
types. It is now the sixth, "HTTP relay": an ON URL and an OFF URL, either as
one pattern with {relay} substituted, or one pair per relay. The per-relay
form is the reason it exists — these boxes often have URLs with nothing in
common between channels (…/FF0101 and …/FF0201), which no pattern can express.

Status is remembered rather than read: most have no endpoint worth trusting.
The cost is stated in the code and the panel — after a restart every relay is
re-commanded once, which is harmless on a board with no memory and far better
than assuming an antenna is already selected.

And the Connections panel now says so, exactly where the wrong choice is made:
picking a band change with a URL transport shows a note pointing at Station
Control. The URL transport stays — a lookup pushed to a webhook or a QSO to a
dashboard is an event, not a state, and Station Control has no place for it.
This commit is contained in:
2026-08-15 02:23:03 +02:00
parent ffd6bcf54b
commit 26b8dade20
8 changed files with 321 additions and 9 deletions
@@ -23,7 +23,12 @@ import {
type RotatorProps = { centerLat?: number | null; centerLon?: number | null; bearing?: number | null };
type Device = { id: string; type: string; name: string; host: string; user?: string; pass?: string; channels?: number; labels: string[] };
type Device = {
id: string; type: string; name: string; host: string;
user?: string; pass?: string; channels?: number; labels: string[];
// Generic HTTP board only. The per-relay URLs win over the patterns.
on_urls?: string[]; off_urls?: string[]; on_pattern?: string; off_pattern?: string;
};
type Relay = { number: number; label: string; on: boolean };
type DevStatus = { id: string; name: string; type: string; connected: boolean; error?: string; relays: Relay[] };
@@ -34,8 +39,8 @@ type DevStatus = { id: string; name: string; type: string; connected: boolean; e
const CARD_MIN = 430; // narrowest a card may get before "Auto" drops a column
const GRID_GAP = 16; // px between cards, both axes
const RELAY_COUNT: Record<string, number> = { webswitch: 5, kmtronic: 8, denkovi: 8, usbrelay: 8, dingtian: 2 };
const TYPE_LABEL: Record<string, string> = { webswitch: 'WebSwitch 1216H', kmtronic: 'KMTronic 8-relay', denkovi: 'Denkovi USB (FT245)', usbrelay: 'Denkovi USB (serial)', dingtian: 'Dingtian IOT relay' };
const RELAY_COUNT: Record<string, number> = { webswitch: 5, kmtronic: 8, denkovi: 8, usbrelay: 8, dingtian: 2, httpgen: 4 };
const TYPE_LABEL: Record<string, string> = { webswitch: 'WebSwitch 1216H', kmtronic: 'KMTronic 8-relay', denkovi: 'Denkovi USB (FT245)', usbrelay: 'Denkovi USB (serial)', dingtian: 'Dingtian IOT relay', httpgen: 'HTTP relay' };
// Relay count for a configured device: fixed by type, except Denkovi (4/8) and
// the generic USB-serial board, whose channel count the user picks.
@@ -675,6 +680,7 @@ function DeviceEditor({ device, onChange, onSave, onCancel, t }: {
const isDingtian = device.type === 'dingtian';
const isDenkovi = device.type === 'denkovi';
const isUsbRelay = device.type === 'usbrelay';
const isHTTPGen = device.type === 'httpgen';
// COM ports for the generic USB-serial relay picker.
const [serialPorts, setSerialPorts] = useState<string[]>([]);
useEffect(() => {
@@ -726,6 +732,7 @@ function DeviceEditor({ device, onChange, onSave, onCancel, t }: {
<SelectItem value="dingtian">Dingtian IOT relay (LAN / WiFi)</SelectItem>
<SelectItem value="denkovi">Denkovi USB (FT245 / D2XX)</SelectItem>
<SelectItem value="usbrelay">Denkovi USB (serial / COM)</SelectItem>
<SelectItem value="httpgen">{t('station.typeHttpGen')}</SelectItem>
</SelectContent>
</Select>
</div>
@@ -734,7 +741,7 @@ function DeviceEditor({ device, onChange, onSave, onCancel, t }: {
<Input value={device.name} placeholder={TYPE_LABEL[device.type]} onChange={(e) => onChange({ ...device, name: e.target.value })} />
</div>
</div>
{(isDenkovi || isUsbRelay || isDingtian) && (
{(isDenkovi || isUsbRelay || isDingtian || isHTTPGen) && (
<div className="space-y-1 max-w-[10rem]">
<Label>{t('station.channels')}</Label>
<Select value={String(chanCount(device))} onValueChange={(v) => setChannels(parseInt(v, 10))}>
@@ -820,6 +827,57 @@ function DeviceEditor({ device, onChange, onSave, onCancel, t }: {
)}
</div>
)}
{/* Generic HTTP board: a URL to switch each relay on and one to switch it
off. Two ways to fill it, and the per-relay one is why this type
exists — a hand-made switch often has URLs with nothing in common
between channels, which no pattern can express. */}
{isHTTPGen && (
<div className="space-y-3 rounded-md border border-border/60 p-3">
<div className="grid grid-cols-2 gap-3">
<div className="space-y-1">
<Label>{t('station.onPattern')}</Label>
<Input className="font-mono text-xs" placeholder="http://192.168.1.9/relay?n={relay}&state=on"
value={device.on_pattern ?? ''}
onChange={(e) => onChange({ ...device, on_pattern: e.target.value })} />
</div>
<div className="space-y-1">
<Label>{t('station.offPattern')}</Label>
<Input className="font-mono text-xs" placeholder="http://192.168.1.9/relay?n={relay}&state=off"
value={device.off_pattern ?? ''}
onChange={(e) => onChange({ ...device, off_pattern: e.target.value })} />
</div>
</div>
<div className="text-[10px] text-muted-foreground">{t('station.patternHint')}</div>
<div className="space-y-1">
<Label>{t('station.perRelayUrls')}</Label>
<div className="space-y-1">
{device.labels.map((_, i) => (
<div key={i} className="grid grid-cols-[2.5rem_1fr_1fr] items-center gap-2">
<span className="text-[11px] text-muted-foreground">{i + 1}</span>
<Input className="h-8 font-mono text-[11px]" placeholder={t('station.onUrlPh')}
value={device.on_urls?.[i] ?? ''}
onChange={(e) => {
const on_urls = [...(device.on_urls ?? [])];
while (on_urls.length < device.labels.length) on_urls.push('');
on_urls[i] = e.target.value;
onChange({ ...device, on_urls });
}} />
<Input className="h-8 font-mono text-[11px]" placeholder={t('station.offUrlPh')}
value={device.off_urls?.[i] ?? ''}
onChange={(e) => {
const off_urls = [...(device.off_urls ?? [])];
while (off_urls.length < device.labels.length) off_urls.push('');
off_urls[i] = e.target.value;
onChange({ ...device, off_urls });
}} />
</div>
))}
</div>
<div className="text-[10px] text-muted-foreground">{t('station.perRelayHint')}</div>
</div>
</div>
)}
<div className="space-y-1">
<Label>{t('station.labels')}</Label>
<div className="grid grid-cols-4 gap-2">
@@ -501,6 +501,17 @@ function CustomFields({ draft, setDraft }: {
</div>
</div>
{/* The one place these two features overlap. A relay board is a STATE per
band, not an event: Station Control tracks it, reads the boards at
startup and does not re-switch while the VFO moves inside a band. A
URL fired on a band change has none of that, and building the mapping
by hand here is work that is already done there. */}
{draft.trigger === 'band_change' && isURL && (
<div className="rounded border border-warning-border bg-warning-muted px-2 py-1.5 text-[11px] text-warning-muted-foreground leading-relaxed">
{t('udpp.relayInstead')}
</div>
)}
{isURL ? (
<div className="space-y-1">
<Label>{t('udpp.url')}</Label>