Diagnostic Dashboard socket

Elixir Phoenix socket library must be used https://hexdocs.pm/phoenix/js/

Connect to socket channel diagnostic_dashboard_widget:<MACHINE_ID>

where <MACHINE_ID> is the id of the machine

Events

Get data

push a data request message in get_data event

request = {
  "from": "2020-01-01 09:00:00Z",
  "to": "2020-01-01 10:00:00Z",
  "machine_id": "52a692bf-85ce-4db9-80f1-f3cf89d9fe0f",
  "machine_variable_ids": ["d395bfb3-b080-40a0-a30d-e34f79fd96c0"],
  "type": "metrics"
}
channel.push("get_data", request, 10000).receive("ok", (payload) => {
	
})

The payload sent from the things5 backend will be something like

{
  "machine_variables": [
    {
      "data": [],
      "id": "99e86a0a-b33c-4169-9316-7b6aad59c2a8",
      "label": "allarme porta",
      "name": "variable-5",
      "source": "events"
    },
    {
      "data": [
        {
          "timestamp": "2020-01-01 09:13:00Z",
          "value": 1
        },
        {
          "timestamp": "2020-01-01 09:14:00Z",
          "value": null
        },
        {
          "timestamp": "2020-01-01 09:15:00Z",
          "value": null
        },
        {
          "timestamp": "2020-01-01 09:16:00Z",
          "value": null
        },
        {
          "timestamp": "2020-01-01 09:17:00Z",
          "value": null
        },
        {
          "timestamp": "2020-01-01 09:18:00Z",
          "value": null
        },
        {
          "timestamp": "2020-01-01 09:19:00Z",
          "value": null
        },
        {
          "timestamp": "2020-01-01 09:20:00Z",
          "value": null
        },
        {
          "timestamp": "2020-01-01 09:21:00Z",
          "value": null
        },
        {
          "timestamp": "2020-01-01 09:22:00Z",
          "value": null
        },
        {
          "timestamp": "2020-01-01 09:23:00Z",
          "value": 2
        }
      ],
      "id": "1b45d33b-7e06-4574-89ea-b7b059505b80",
      "label": "variable-2",
      "name": "variable-2",
      "source": "metrics"
    },
    {
      "data": [
        {
          "timestamp": "2020-01-01 09:15:00Z",
          "value": 15
        },
        {
          "timestamp": "2020-01-01 09:16:00Z",
          "value": null
        },
        {
          "timestamp": "2020-01-01 09:17:00Z",
          "value": 20
        }
      ],
      "id": "13ef74a2-895d-4408-8fb6-9a84e5c4f93b",
      "label": "variable-3",
      "name": "variable-3",
      "source": "metrics"
    }
  ]
}

{
  "machine_variables": [
    {
      "data": [
        {
          "end_time": null,
          "name": "variable-2",
          "start_time": "2020-01-01 09:17:51Z",
          "value": "spenta"
        }
      ],
      "id": "a2fb64e2-ca31-44b6-885a-23e1d837eb10",
      "label": "stato",
      "name": "variable-2"
    }
  ]
}

Realtime

The channel where realtime data updates will be published is realtime:type=TYPE

where TYPE is the type of the widget, one of metrics,states,events

channel.on("realtime:type=states", payload => {
  console.log(payload)
  // {
  //   "timestamp": "2020-02-18 09:35:51.917494Z",
  //   "translations": { "it": "2" },
  //   "value": "on",
  //   "name": "door",
  //   "source": "states"
  // }
})