feat: add factory_Reset, reconfigure_settings endpoints for sensors
This commit is contained in:
@@ -77,6 +77,23 @@ defmodule Localiser.Web.Controllers.SensorController do
|
||||
unauthorized: {"Unauthorized", "application/json", Schemas.Error}
|
||||
]
|
||||
|
||||
operation :factory_reset,
|
||||
summary: "Send factory reset command to sensor",
|
||||
parameters: [id: [in: :path, type: :integer, required: true]],
|
||||
responses: [
|
||||
ok: {"Command sent", "application/json", Schemas.CommandSent},
|
||||
unauthorized: {"Unauthorized", "application/json", Schemas.Error}
|
||||
]
|
||||
|
||||
operation :reconfigure,
|
||||
summary: "Push new network settings to sensor",
|
||||
parameters: [id: [in: :path, type: :integer, required: true]],
|
||||
request_body: {"Reconfigure params", "application/json", Schemas.SensorReconfigureParams, required: true},
|
||||
responses: [
|
||||
ok: {"Command sent", "application/json", Schemas.CommandSent},
|
||||
unauthorized: {"Unauthorized", "application/json", Schemas.Error}
|
||||
]
|
||||
|
||||
operation :calibration_start,
|
||||
summary: "Begin RSSI calibration",
|
||||
parameters: [id: [in: :path, type: :integer, required: true]],
|
||||
@@ -181,6 +198,19 @@ defmodule Localiser.Web.Controllers.SensorController do
|
||||
end
|
||||
end
|
||||
|
||||
def factory_reset(conn, %{"id" => id}) do
|
||||
sensor = Sensors.get_sensor!(id)
|
||||
{:ok, _} = Sensors.factory_reset(sensor)
|
||||
json(conn, %{status: "ok"})
|
||||
end
|
||||
|
||||
def reconfigure(conn, %{"id" => id} = params) do
|
||||
sensor = Sensors.get_sensor!(id)
|
||||
config = Map.take(params, ["ssid", "password", "mqtt_broker", "mqtt_port"])
|
||||
{:ok, _} = Sensors.reconfigure_settings(sensor, config)
|
||||
json(conn, %{status: "ok"})
|
||||
end
|
||||
|
||||
def calibration_start(conn, %{"id" => id, "reference_distance" => ref_dist}) do
|
||||
sensor = Sensors.get_sensor!(id)
|
||||
:ok = SensorServer.begin_calibration(sensor.sensor_id, ref_dist)
|
||||
|
||||
Reference in New Issue
Block a user