Skip to content

Implement GET /api/v1/robots/{esn}/state handler #19

@infraax

Description

@infraax

Task: Robot State Endpoint

Parent epic: #4 (M1 — Robot Connection)
Depends on: #15 (Registry), #18 (EventStream populating state)

What to do

Add GET /api/v1/robots/{esn}/state route to buildRouter in main.go, returning a live api.RobotState snapshot from the ConnectionManager.

mux.HandleFunc("GET /api/v1/robots/{esn}/state", func(w http.ResponseWriter, r *http.Request) {
    esn := r.PathValue("esn")
    cm, ok := registry.Get(esn)
    if !ok {
        writeJSON(w, http.StatusNotFound, api.ErrorResponse{Error: "robot not found"})
        return
    }
    writeJSON(w, http.StatusOK, cm.State())
})

The api.RobotState type is already defined in pkg/api/types.go — populate all fields from live SDK data.

Fields to populate (from EventStream state)

  • battery.voltage, battery.level, battery.is_charging, battery.is_on_charger
  • pose.x, pose.y, pose.z, pose.angle_rad
  • stimulation (from StimulationInfo events)
  • faces_visible (from RobotObservedFace events)
  • is_on_charger, is_picked_up
  • has_control (from behavior control stream)

Definition of done

curl http://localhost:8070/api/v1/robots/008093b9/state returns JSON with a real battery.voltage value matching the robot. This is the Milestone 1 completion criterion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions