Add a Drones fleet section that fills itself in on connect
The fleet lived as a tab inside the Logbook, which buried it, and every
drone had to be typed in by hand — model, serial and firmware copied off
an airframe the app was already talking to.
Promote it to its own nav section above Logbook, and let a connecting
drone register itself. The Fly App already forwarded model, serial and
firmware upstream; the hub was keeping only the model. It now carries the
identity through to DeviceState, and the Web App offers it to a new
POST /api/drones/auto, which upserts keyed by serial. The auto path only
writes what the aircraft is authoritative about (model, both firmware
versions) and never touches what the pilot curates.
Serial and the firmware versions resolve on their own schedules after
connect — the serial in seconds, the aircraft firmware sometimes a minute
later — so nothing along the path treats an absent value as a cleared one,
and a later event filling firmware in still reaches the server. The auto
call rides every telemetry frame, so the client remembers the identity
tuple it last sent and only a change goes out; a 4xx is the server's
settled answer and is not retried, or one drone connected for an hour
would mean one request per frame for an hour.
New fields on drones: firmware, controller_firmware, and registration for
the FAA/CAA aircraft number — distinct from operator_number, which stays
the EU operator ID. Controller firmware is the remote controller's own
version, read from its component; the flight controller's version is a
different quantity and stays off this field (see 002e484). name becomes
optional and is now the pilot's custom name: auto-added drones arrive
unnamed, so the API serves a computed displayName (name, else model +
serial) for the fleet table, the flight picker and the CSV export. A
unique index on serial is what keeps the find-then-create path from
forking a drone's history across two records.
The schema is applied to the remote PocketBase; the migration is here for
fresh deployments, which the remote does not read.
Verified against a simulated device over the real socket with identity
resolving late: one record from four events, both firmware versions
filled, curated fields intact across re-registration, and a drone deleted
while connected coming back on the next frame.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
3e066c0a99
commit
33595c99e8
19 files changed
+931
-426
No files matched your search
@@ -182,11 +182,22 @@ func (h *Hub) Ingest(deviceID string, raw map[string]any) {
|
||||
s.Connected = c
|
||||
if !c {
|
||||
s.Telemetry = Telemetry{} // drone unlinked: live telemetry is no longer valid
|
||||
s.Serial, s.Firmware, s.ControllerFirmware = "", "", ""
|
||||
}
|
||||
}
|
||||
if m, ok := raw["model"].(string); ok {
|
||||
s.Model = m
|
||||
}
|
||||
if s.Connected {
|
||||
applyIdentity(s, raw)
|
||||
}
|
||||
case "identity":
|
||||
// Ignore identity that arrives after a disconnect: the Fly App forwards
|
||||
// every SDK event upstream before its own connected-check, so a callback
|
||||
// resolving late would otherwise repopulate what the disconnect cleared.
|
||||
if s.Connected {
|
||||
applyIdentity(s, raw)
|
||||
}
|
||||
case "battery":
|
||||
if p, ok := toInt(raw["percent"]); ok {
|
||||
s.Telemetry.BatteryPercent = &p
|
||||
|
||||
@@ -23,13 +23,22 @@ type Telemetry struct {
|
||||
|
||||
// DeviceState is the server's aggregated view of one app/drone.
|
||||
type DeviceState struct {
|
||||
DeviceID string `json:"deviceId"`
|
||||
Online bool `json:"online"` // app's websocket is connected to the server
|
||||
Connected bool `json:"connected"` // a drone is connected to the app
|
||||
Model string `json:"model"`
|
||||
Registration string `json:"registration"`
|
||||
Telemetry Telemetry `json:"telemetry"`
|
||||
LastSeenMs int64 `json:"lastSeenMs"`
|
||||
DeviceID string `json:"deviceId"`
|
||||
Online bool `json:"online"` // app's websocket is connected to the server
|
||||
Connected bool `json:"connected"` // a drone is connected to the app
|
||||
Model string `json:"model"`
|
||||
// Registration is the *SDK* registration state reported by the Fly App
|
||||
// ("success", "failed", …) — not the aircraft's FAA/CAA registration number,
|
||||
// which lives on the drone's logbook record.
|
||||
Registration string `json:"registration"`
|
||||
// Identity of the connected aircraft, as it reports itself. Serial and the
|
||||
// two firmware versions resolve asynchronously after connect, each on its own
|
||||
// schedule, so these fill in over several events rather than all at once.
|
||||
Serial string `json:"serial"`
|
||||
Firmware string `json:"firmware"`
|
||||
ControllerFirmware string `json:"controllerFirmware"`
|
||||
Telemetry Telemetry `json:"telemetry"`
|
||||
LastSeenMs int64 `json:"lastSeenMs"`
|
||||
}
|
||||
|
||||
// TrackPoint is one sample of the drone's GPS track (for the map trail).
|
||||
@@ -84,6 +93,22 @@ func toInt(v any) (int, bool) {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
// applyIdentity copies the aircraft's self-reported identity from a raw event.
|
||||
// A field the event omits (or reports null) means "not resolved yet" — the SDK
|
||||
// answers serial in seconds but firmware can take far longer — so an absent
|
||||
// value never clears one an earlier event already delivered.
|
||||
func applyIdentity(s *DeviceState, raw map[string]any) {
|
||||
if v, ok := raw["serial"].(string); ok && v != "" {
|
||||
s.Serial = v
|
||||
}
|
||||
if v, ok := raw["firmware"].(string); ok && v != "" {
|
||||
s.Firmware = v
|
||||
}
|
||||
if v, ok := raw["controllerFirmware"].(string); ok && v != "" {
|
||||
s.ControllerFirmware = v
|
||||
}
|
||||
}
|
||||
|
||||
// applyTelemetry copies any present telemetry fields from a raw event map.
|
||||
func applyTelemetry(t *Telemetry, raw map[string]any) {
|
||||
if v, ok := toInt(raw["satelliteCount"]); ok {
|
||||
|
||||
Reference in new issue
Block a user