我遵循了本教程:
Running the CC26xx Contiki Examples
但是我没有使用cc26xx-demo,而是使用cc26xx-web-demo并成功管理以启动并运行所有内容我可以访问6lbr网页,当我访问sensorTag页面时,我看到mqtt配置页面为图所示:
如果我点击sensorTag页面(上图)中的索引,我会看到数据:
问题是,如何编写一个简单的nodejs js文件,该文件使用mqtt代理信息来获取所有sensorTag 传感器 数据并将其保存在本地对象中。
我试着运行这个例子,但没有运气
var mqtt = require('mqtt')
client = mqtt.createClient(1883, '192.168.1.109');
client.subscribe(what do I write here);
client.on('message', function(topic, message) { console.log(message); });
我不知道我做错了什么
tcpdump似乎在1883端口上检测到mqqt数据包,但是当我用节点运行js文件时,我似乎无法控制传感器数据。
我继续使用contiki wiki并发现了这些信息 “您也可以订阅主题并接收命令,但这只有在您使用”组织ID“!='快速启动'时才有效。因此,如果您提供不同的组织ID(不要忘记身份验证令牌!),设备将订阅:
IOT-2 / CMD / + / FMT / JSON“
这是否意味着订阅的主题是快速入门,但即使如此,我使用了“+ /#”,它们对所有主题进行了subrcibes并且仍然没有在控制台上打印?
答案 0 :(得分:0)
希望这适合你:
var mqtt = require('mqtt');
var fs = require('fs');
var options = { port: PORT, host: HOST };/*user, password and others authentication if there.*/
var client = mqtt.connect('HOST', options);
client.on('connect', function ()
{
client.subscribe("topic, command or data");
client.publish("topic, command or data", data, function () {
});
});
client.on('error', function () { });
client.on('offline', function () { });
client.on('message', function (topic, message) {
console.log(message.toString());
});