feat: add get_version endpoint for individual sensors
This commit is contained in:
@@ -59,6 +59,11 @@ defmodule Localiser.Domain.Sensors do
|
||||
{:ok, sensor}
|
||||
end
|
||||
|
||||
def get_version(%Sensor{} = sensor) do
|
||||
Localiser.MQTT.Connection.publish(cmd_topic(sensor), Jason.encode!(%{action: "version"}))
|
||||
{:ok, sensor}
|
||||
end
|
||||
|
||||
def send_ota_update(%Sensor{} = sensor, url, version) do
|
||||
payload = %{
|
||||
action: "ota",
|
||||
|
||||
@@ -239,6 +239,12 @@ defmodule Localiser.Web.Controllers.SensorController do
|
||||
json(conn, %{status: "ok"})
|
||||
end
|
||||
|
||||
def get_version(conn, %{"id" => id}) do
|
||||
sensor = Sensors.get_sensor!(id)
|
||||
{:ok, _} = Sensors.get_version(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"])
|
||||
|
||||
@@ -103,5 +103,6 @@ defmodule Localiser.Web.Router do
|
||||
post "/sensors/:id/reconfigure", SensorController, :reconfigure
|
||||
post "/sensors/:id/calibration/start", SensorController, :calibration_start
|
||||
post "/sensors/:id/calibration/stop", SensorController, :calibration_stop
|
||||
get "/sensors/:id/version", SensorController, :get_version
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user