node.jsdockerpluginskuzzle

How to make kuzzle-device-manager plugin API actions works?


I successfully installed and loaded kuzzle-device-manager in the backend file:

import { Backend } from 'kuzzle';
import { DeviceManagerPlugin } from 'kuzzle-device-manager';

const app = new Backend('playground');

console.log(app.config);

const deviceManager = new DeviceManagerPlugin();

const mappings = {
  updatedAt: { type: 'date' },
  payloadUuid: { type: 'keyword' },
  value: { type: 'float' }
} 

deviceManager.devices.registerMeasure('humidity', mappings)

app.plugin.use(deviceManager)

app.start()
  .then(async () => {
    // Interact with Kuzzle API to create a new index if it does not already exist
    console.log(' started!');
  })
  .catch(console.error);

But when i try to use controllers from that plugin for example device-manager/device with create action i get an error output. Here is my "client" code in js:

const { Kuzzle, WebSocket } = require("kuzzle-sdk")

const kuzzle = new Kuzzle(
  new WebSocket('KUZZLE_IP')
)

kuzzle.on('networkError', error => {
  console.error('Network Error: ', error);
})

const run = async () => {
  try {
    // Connects to the Kuzzle server
    await kuzzle.connect();
    // Creates an index
    const result = await kuzzle.query({
      index: "nyc-open-data",
      controller: "device-manager/device",
      action: "create",
      body: {
        model: "model-1234",
        reference: "reference-1234"
      }
    }, {
      queuable: false
    })
    console.log(result)

  } catch (error) {
    console.error(error.message);
  } finally {
    kuzzle.disconnect();
  }
};
run();

And the result log:

API action "device-manager/device":"create" not found

Note: The nyc-open-data index exists and is empty.


Solution

  • We apologize for this mistake in the documentation, the device-manager/device:create method is not available because the plugin is using auto-provisioning until the v2.

    You should send a payload to your decoder, the plugin will automatically provision the device if it does not exists https://docs.kuzzle.io/official-plugins/device-manager/1/guides/decoders/#receive-payloads