repeater/internal/models/models.go
Pierre-Olivier Mercier 950f73371c 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.
2026-05-01 22:26:43 +08:00

76 lines
2.7 KiB
Go

package models
import "time"
// WiFiNetwork represents a discovered WiFi network
type WiFiNetwork struct {
SSID string `json:"ssid"`
Signal int `json:"signal"`
Security string `json:"security"`
Channel int `json:"channel"`
BSSID string `json:"bssid"`
}
// ConnectedDevice represents a device connected to the hotspot
type ConnectedDevice struct {
Name string `json:"name"`
Type string `json:"type"`
MAC string `json:"mac"`
IP string `json:"ip"`
Vendor string `json:"vendor,omitempty"`
SignalDbm int32 `json:"signalDbm,omitempty"`
RxBytes uint64 `json:"rxBytes,omitempty"`
TxBytes uint64 `json:"txBytes,omitempty"`
ConnectedAt time.Time `json:"connectedAt,omitzero"`
}
// HotspotConfig represents hotspot configuration
type HotspotConfig struct {
SSID string `json:"ssid"`
Password string `json:"password"`
Channel int `json:"channel"`
}
// HotspotStatus represents detailed hotspot status
type HotspotStatus struct {
State string `json:"state"` // ENABLED, DISABLED, etc.
SSID string `json:"ssid"` // Current SSID being broadcast
BSSID string `json:"bssid"` // MAC address of the AP
Channel int `json:"channel"` // Current channel
Frequency int `json:"frequency"` // Frequency in MHz
NumStations int `json:"numStations"` // Number of connected stations
HWMode string `json:"hwMode"` // Hardware mode (g, a, n, ac, etc.)
CountryCode string `json:"countryCode"` // Country code
}
// SystemStatus represents overall system status
type SystemStatus struct {
Connected bool `json:"connected"`
ConnectionState string `json:"connectionState"` // Connection state: connected, disconnected, connecting, disconnecting, roaming
ConnectedSSID string `json:"connectedSSID"`
HotspotStatus *HotspotStatus `json:"hotspotStatus,omitempty"` // Detailed hotspot status
ConnectedCount int `json:"connectedCount"`
DataUsage float64 `json:"dataUsage"`
Uptime int64 `json:"uptime"`
ConnectedDevices []ConnectedDevice `json:"connectedDevices"`
}
// WiFiConnectRequest represents a request to connect to WiFi
type WiFiConnectRequest struct {
SSID string `json:"ssid" binding:"required"`
Password string `json:"password"`
}
// LogEntry represents a system log entry
type LogEntry struct {
Timestamp time.Time `json:"timestamp"`
Source string `json:"source"`
Message string `json:"message"`
}
// DHCPLease represents a DHCP lease entry
type DHCPLease struct {
IP string
MAC string
Hostname string
}