如何使 kuzzle-device-manager 插件 API 动作有效?
How to make kuzzle-device-manager plugin API actions works?
我在后端文件中成功安装并加载了kuzzle-device-manager
:
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);
但是当我尝试使用该插件的控制器时,例如 device-manager/device
和 create
操作,我得到一个错误输出。
这是我在 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();
结果日志:
API action "device-manager/device":"create" not found
注意:nyc-open-data
索引存在且为空。
对于文档中的这个错误,我们深表歉意,device-manager/device:create
方法不可用,因为插件使用 auto-provisioning 直到 v2.
您应该向您的解码器发送有效负载,如果设备不存在,插件将自动配置该设备https://docs.kuzzle.io/official-plugins/device-manager/1/guides/decoders/#receive-payloads
我在后端文件中成功安装并加载了kuzzle-device-manager
:
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);
但是当我尝试使用该插件的控制器时,例如 device-manager/device
和 create
操作,我得到一个错误输出。
这是我在 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();
结果日志:
API action "device-manager/device":"create" not found
注意:nyc-open-data
索引存在且为空。
对于文档中的这个错误,我们深表歉意,device-manager/device:create
方法不可用,因为插件使用 auto-provisioning 直到 v2.
您应该向您的解码器发送有效负载,如果设备不存在,插件将自动配置该设备https://docs.kuzzle.io/official-plugins/device-manager/1/guides/decoders/#receive-payloads