station: Surface signal, traffic and connection time in API and UI

Hostapd already parsed signal strength and rx/tx counters but the
station -> ConnectedDevice conversion threw them away. Add signalDbm,
rxBytes, txBytes and connectedAt to the OpenAPI schema and the
ConnectedDevice model, and centralise the conversion in
station.ToConnectedDevice so handlers, the periodic refresh and the
event callbacks all serialise the same shape.

Two follow-on bugs surfaced while wiring this up:

- The hostapd backend only stored station entries on first contact.
  Subsequent polls were dropped, so signal and byte counters never
  refreshed. Reconcile updates in checkStationChanges.
- ConnectedAt was reset to time.Now() on every conversion. Track
  FirstSeen on HostapdStation when the station joins, and preserve
  the timestamp across periodic refreshes in app.go so the UI's
  "connected since" badge is stable.

Frontend gains a metrics row on each device card with signal bars,
total traffic and a live duration. Falls back gracefully when a
backend (DHCP, ARP) doesn't expose these fields.
This commit is contained in:
nemunaire 2026-05-01 22:26:43 +08:00
commit 950f73371c
8 changed files with 231 additions and 37 deletions

View file

@ -418,7 +418,7 @@ components:
properties:
name:
type: string
description: Device hostname
description: Device hostname (may be empty when DHCP did not provide one)
example: "iPhone-12"
type:
type: string
@ -440,6 +440,30 @@ components:
description: Assigned IP address
pattern: '^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$'
example: "192.168.1.100"
vendor:
type: string
description: Hardware vendor inferred from the MAC OUI prefix (empty when unknown)
example: "Apple"
signalDbm:
type: integer
format: int32
description: Wi-Fi signal strength in dBm (0 when unavailable, e.g. for non-hostapd backends)
example: -54
rxBytes:
type: integer
format: int64
description: Total bytes received from the device since connection (0 when unavailable)
example: 1048576
txBytes:
type: integer
format: int64
description: Total bytes sent to the device since connection (0 when unavailable)
example: 524288
connectedAt:
type: string
format: date-time
description: Timestamp when the station first appeared (best effort)
example: "2026-05-01T08:30:00Z"
required:
- name
- type