kuzzleio / kuzzle-device-manager

IoT Devices & Assets Management providing digital twins, payload decoding, normalized measures, provisioning. Multi-Tenant ready for white labelled and B2B2C applications.
https://docs.kuzzle.io/official-plugins/device-manager/1
Apache License 2.0
14 stars 6 forks source link

How to create an engine? #327

Closed xdien closed 7 months ago

xdien commented 7 months ago

Hello kuzzle

Thank you

rolljee commented 7 months ago

Hello, we are currently working on a new documentation that will be much more precise on how to initialise the device manager plugin.

But you should be able to create an engine using this piece of code.

this.app.sdk
      .query({
        action: 'create',
        controller: `device-manager/engine`,
        group,
        index,
      })
      .catch((error) => {
        this.app.log.error(`[${index}] Cannot ${action} ${plugin} engine: ${error}`);

        throw error;
      });

The device manager is an open source plugin, there is no need to have a paid plugin to setup engine

xdien commented 7 months ago

Thank you @rolljee . I hope the documentation is completed soon and has more examples.

xdien commented 7 months ago

I tried successfully creating the engine, then I created the asset, maybe I created the correct json content body

POST http://localhost:7512/_/device-manager/models/assets
Authorization: Bearer xxxx

{
    "engineGroup":"esp",
    "model":"Distiller",
    "measures": [
        {
            "name": "temperature",
            "type": "float"
        },
        {
            "name": "humidity",
            "type": "float"
        }
    ]
}

But the server responded back error, I know index, but I don't know collection and targets on the url?

{
  "action": "writeAsset",
  "controller": "device-manager/models",
  "error": {
    "code": 33619971,
    "id": "api.assert.missing_argument",
    "message": "Missing argument \"index, collection or targets\".",
    "props": [
      "index, collection or targets"
    ],
    "stack": "BadRequestError: Missing argument \"index, collection or targets\".\n      [...Kuzzle internal calls deleted...]\n      at DocumentController.search (/home/xdien/workspace/next-iot/backend/node_modules/kuzzle/lib/api/controllers/documentController.js:92:20)\n      at doAction (/home/xdien/workspace/next-iot/backend/node_modules/kuzzle/lib/api/funnel.js:1079:47)\n      at Funnel.executePluginRequest (/home/xdien/workspace/next-iot/backend/node_modules/kuzzle/lib/api/funnel.js:756:20)\n      at FunnelProtocol.query (/home/xdien/workspace/next-iot/backend/node_modules/kuzzle/lib/core/shared/sdk/funnelProtocol.js:95:51)\n      at Proxy._timeoutRequest (/home/xdien/workspace/next-iot/backend/node_modules/kuzzle-sdk/src/Kuzzle.js:763:34)\n      at Proxy.query (/home/xdien/workspace/next-iot/backend/node_modules/kuzzle-sdk/src/Kuzzle.js:591:21)\n      at Proxy.query (/home/xdien/workspace/next-iot/backend/node_modules/kuzzle/lib/core/shared/sdk/embeddedSdk.js:132:22)\n      at AssetService.refreshModel (/home/xdien/workspace/next-iot/backend/node_modules/kuzzle-device-manager/lib/modules/asset/AssetService.ts:333:35)\n      at async Kuzzle.ask (/home/xdien/workspace/next-iot/backend/node_modules/kuzzle/lib/kuzzle/event/kuzzleEventEmitter.js:229:22)\n      at async ModelService.writeAsset (/home/xdien/workspace/next-iot/backend/node_modules/kuzzle-device-manager/lib/modules/model/ModelService.ts:106:5)\n      at async ModelsController.writeAsset (/home/xdien/workspace/next-iot/backend/node_modules/kuzzle-device-manager/lib/modules/model/ModelsController.ts:115:24)\n      at async Funnel.processRequest (/home/xdien/workspace/next-iot/backend/node_modules/kuzzle/lib/api/funnel.js:668:28)",
    "status": 400
  },
  "headers": {},
  "node": "knode-bored-maugrim-14974",
  "requestId": "7afe4c19-d9d2-417e-907c-90908ff3e827",
  "result": null,
  "status": 400,
  "volatile": null
}
xdien commented 7 months ago

I was able to create the asset but the error was because I filled in the wrong engineGroup

"engineGroup":"esp",