Core
IoT Backend v2.x
2

Define an Asset model #

To define an Asset model, we need to register it on the framework.

A model is declared with the following information:

  • tenant group allowed to use the model
  • model name
  • accepted measures
  • metadata

We will define an Asset model of name Room which accept a temperature measure and a metadata indicating in which building the room is located.

An example of the complete implementation can be found in the apps/api/lib/modules/assets/ directory

For this, we will use the Device Manager plugin:

Copied to clipboard!
import { DeviceManagerPlugin } from "kuzzle-device-manager";

const deviceManager = app.plugin.get < DeviceManagerPlugin > "device-manager";

deviceManager.models.registerAsset("smartcity", "Room", {
  measures: [
    {
      name: "temperature",
      type: "temperature",
    },
  ],
  metadataMapping: {
    building: { type: "keyword" },
  },
});