0

我想为我的应用程序实现 Live Objects MQTT 接口,但我对这个协议不是很熟悉。有人有正确设置连接的代码示例吗?

谢谢你的回复!

4

2 回答 2

1

您可以在 Github https://github.com/Orange-OpenSource/LiveObjects-samples-nodejs上找到一些 node.js 的代码示例

它也适用于其他平台,这里有 Github 上的链接:https ://developer.orange.com/apis/datavenue/code-sample

问候

于 2017-03-09T14:43:50.880 回答
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>
});
于 2018-07-11T07:14:19.313 回答