Skip to content
This repository was archived by the owner on Oct 11, 2023. It is now read-only.

[API Specifications] Device Models

Devis Lucato edited this page Aug 22, 2017 · 2 revisions

Get list of device types that can be simulated

The list of device types is injected into the service using a list of configuration files, which are automatically discovered when the service starts.

To create a new device type, a new configuration file is added to the folder where the configuration files are stored, and the microservice is restarted or re-deployed.

The service configuration allows to specify the path where the device type files are stored.

  • Visibility: public
  • Auth: requires Viewer|Admin

Request:

GET /v1/devicetypes

Response:

200 OK
Content-Type: application/JSON
{
  "Items": [
    {
      "Id": "11110000-1111-0000-0000-000011110000",
      "Version": "0.0.1",
      "Name": "Elevator",
      "Description": "Simulated Elevator with floor number sensor",
      "Protocol": "HTTP",
      "DeviceBehavior": {
        "get_current_floor": {
          "Type": "javascript",
          "Path": "elevator-position-sensor.js"
        },
        "do_elevator_go_down": {
          "Type": "javascript",
          "Path": "elevator-go-down-method.js"
        },
        "do_elevator_go_up": {
          "Type": "javascript",
          "Path": "elevator-go-up-method.js"
        }
      },
      "Telemetry": {
        "Messages": [
          {
            "Interval": 1000,
            "Message": "{\"current_floor\": ${get_current_floor.value}}",
            "MessageSchema": {
              "Format": "JSON",
              "Fields": {
                "current_floor": "Integer"
              }
            }
          }
        ]
      },
      "Methods": {
        "Start": {
          "Actions": [
            "${do_start}"
          ]
        }
      },
      "$metadata": {
        "$type": "DeviceType;1",
        "$uri": "/v1/devicetypes/11110000-1111-0000-0000-000011110000"
      }
    },
    {
      "Id": "22220000-2222-0000-0000-000022220000",
      "Version": "0.0.1",
      "Name": "Chiller",
      "Description": "Simulated Chiller with temperature and humidity sensors",
      "Protocol": "AMQP",
      "DeviceBehavior": {
        "get_random_temperature": {
          "Type": "javascript",
          "Path": "random-temperature-celsius-sensor.js"
        },
        "get_random_percentage": {
          "Type": "javascript",
          "Path": "random-percentage-sensor.js"
        },
        "get_power_source": {
          "Type": "javascript",
          "Path": "chiller-power-sensors.js"
        },
        "do_reboot": {
          "Type": "javascript",
          "Path": "chiller-reboot-method.js"
        },
        "do_upgrade": {
          "Type": "javascript",
          "Path": "chiller-upgrade-method.js"
        }
      },
      "Telemetry": {
        "Messages": [
          {
            "Interval": 15000,
            "Message": "{\"temperature\": ${get_random_temperature.value},\"t_unit\":\"C\",\"humidity\": ${get_random_percentage.value},\"h_unit\":\"%\",\"voltage\": ${get_power_source.voltage},\"v_unit\":\"${get_power_source.voltage_unit}\",\"power\": ${get_power_source.power},\"p_unit\":\"${get_power_source.power_unit}\"}",
            "MessageSchema": {
              "Format": "JSON",
              "Fields": {
                "temperature": "Double",
                "humidity": "Integer",
                "voltage": "Double",
                "power": "Double",
                "t_unit": "Text",
                "h_unit": "Text",
                "v_unit": "Text",
                "p_unit": "Text"
              }
            }
          }
        ]
      },
      "Methods": {
        "Reboot": {
          "Actions": [
            "${do_reboot}"
          ]
        },
        "Upgrade": {
          "Actions": [
            "${do_reboot}",
            "${do_upgrade}",
            "${do_reboot}"
          ]
        }
      },
      "$metadata": {
        "$type": "DeviceType;1",
        "$uri": "/v1/devicetypes/22220000-2222-0000-0000-000022220000"
      }
    }
  ],
  "$metadata": {
    "$type": "DeviceTypeList;1",
    "$uri": "/v1/devicetypes"
  }
}

Clone this wiki locally