我想为我的应用程序实现Live Objects MQTT界面,但我不是很熟悉这个协议。任何人都有正确设置连接的代码示例?
谢谢您的回复!
答案 0 :(得分:0)
您可以在Github https://github.com/Orange-OpenSource/LiveObjects-samples-nodejs
上找到node.js的一些代码示例它也适用于其他在Github上有链接的平台:https://developer.orange.com/apis/datavenue/code-sample
问候
答案 1 :(得分:0)
这里是一个示例:
const mqtt = require('mqtt');
const mqttTopic = "router/~event/v1/data/new/urn/lora/#";
const url = "mqtt://liveobjects.orange-business.com:1883";
const apiKey ="<your api key>";
let client = mqtt.connect(url, {
username: "payload",
password: apiKey,
keepAlive: 30
});
client.on("connect", function () {
console.log("Connected to Live Objects");
client.subscribe(mqttTopic);
console.log("MQTT::Subscribed to topic:", mqttTopic);
});
client.on("error", function (err) {
console.log("MQTT::Error from client --> ", err);
});
client.on("message", function (topic, message) {
let loraMessage = JSON.parse(message);
<your code here>
});