hub: actually send start/stop commands over MQTT
Build (Dev) / build (push) Successful in 11s
CI / quality (push) Successful in 11s
CI / quality (pull_request) Successful in 11s

The /cameras/{id}/start and /stop handlers only wrote a recording_events
row — they never published the command, so the camera never recorded.
Add Subscriber.PublishCommand (publishes {"command":...} to
remoterig/cameras/<id>/command, which the XIAO forwards to the ESP-01S),
thread a CommandPublisher into the recording handlers, and wire mqttSub in
via apiRouter. Tests pass nil (publish skipped).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Joshua King
2026-06-05 20:28:26 -04:00
parent b1ed8cdb20
commit d538dd3b70
4 changed files with 44 additions and 8 deletions
+12
View File
@@ -143,6 +143,18 @@ type statusPayload struct {
UptimeSec *int `json:"uptime_sec"`
}
// PublishCommand sends a command (e.g. "start_recording") to a camera's
// command topic, which its ESP32 bridge subscribes to and forwards over UART.
func (s *Subscriber) PublishCommand(cameraID, command string) error {
topic := "remoterig/cameras/" + cameraID + "/command"
payload, _ := json.Marshal(map[string]string{"command": command})
tok := s.client.Publish(topic, 2, false, payload)
if !tok.WaitTimeout(3 * time.Second) {
return fmt.Errorf("publish to %s timed out", topic)
}
return tok.Error()
}
func (s *Subscriber) handleStatus(cameraID string, payload []byte) {
var sp statusPayload
if err := json.Unmarshal(payload, &sp); err != nil {