我正在尝试在Windows 10上设置本地Thingsboard安装,可以从ESP8266设备向其发送温度数据。我知道我不了解执行此操作所需的条件,并且我的实验失败了。
我认为安装和配置步骤太多,无法在此处提供所有步骤以进行诊断。但是我很乐意提供一些有关如何自己诊断问题的建议,例如打开更多调试跟踪。
(下面列出的所有IP地址都是私有的,不敏感。)
要了解事物板,我首先在在线演示系统上设置了一个带有设备和仪表板以显示温度的帐户。一旦使用curl命令, 我创建了一个ESP8266项目,该项目成功将数据发布到Thingsboard在线演示安装中。即数据显示在我的在线仪表板上。这是WORKING ESP8266项目相关行的摘录。
#include <PubSubClient.h>
#include <ESP8266WiFi.h>
#define TOKEN "BJ9nLTOAc3hEL3NOlGei"
char thingsboardServer[] = "demo.thingsboard.io"; // Online demo system
int thingsboard_port = 1883; // Online demo system
client.setServer( thingsboardServer, thingsboard_port );
client.connect("ESP8266 Device", TOKEN, NULL);
String payload = "{";
payload += "\"temperature\":"; payload += temperature;
payload += ",";
payload += "\"humidity\":"; payload += humidity;
payload += "}";
// Send payload
char attributes[100];
payload.toCharArray( attributes, 100 );
client.publish( "v1/devices/me/telemetry", attributes );
我根据Thingboard入门指南设置了Thingsboard本地安装,修改了设备访问令牌以使其与在线安装相匹配。安装并配置了设备和仪表板的Thingsboard之后,我可以使用以下命令在仪表板上显示数据:
curl -v -X POST -d“ {\” temperature \“:25}” http://192.168.2.5:8080/api/v1/BJ9nLTOAc3hEL3NOlGei/telemetry --header“ Content-Type:application / json”
我将ESP8266项目中的值更改为以下值。但是,运行时,在Thingsboard仪表板的本地Windows安装上看不到任何东西。
IPAddress thingsboardServer(192, 168, 2, 5);// Local laptop
int thingsboard_port = 1883; // Local laptop
在Thingsboard网站上进一步阅读时,我怀疑我需要一个网关和代理(例如Mosquitto)。因此,我按照网关和Mosquitto的安装说明进行操作。遵循这些说明中“步骤8.2”末尾的所有步骤https://thingsboard.io/docs/iot-gateway/getting-started/#step-8-connect-to-external-mqtt-broker
我注意到警告,默认情况下Mosquitto和Thingsboard都在1883年侦听,并将Mosquitto更改为在1884年侦听。我还将mqtt-gui-extension-configuration.json的端口更改为1884。 为了使mosquitto-pub命令“工作”,我在Mosquitto配置文件中更改了访问权限:
allow_anonymous true.
使用两个控制台窗口,我可以看到我在一个窗口中的mosquitto_pub中发布的内容出现在另一个窗口中运行的mosquitto_sub中。
所以
mosquitto_pub -h localhost -p 1884 -t "v1/device/me/telemetry" -m '{"temperature":36.6}' -u BJ9nLTOAc3hEL3NOlGei
产生
C:\Program Files\mosquitto>mosquitto_sub -d -t "v1/device/me/telemetry" -h localhost -p 1884
Client mosq/nmafqF16uw5edvXJGA sending CONNECT
Client mosq/nmafqF16uw5edvXJGA received CONNACK (0)
Client mosq/nmafqF16uw5edvXJGA sending SUBSCRIBE (Mid: 1, Topic: v1/device/me/telemetry, QoS: 0, Options: 0x00)
Client mosq/nmafqF16uw5edvXJGA received SUBACK
Subscribed (mid: 1): 0
Client mosq/nmafqF16uw5edvXJGA received PUBLISH (d0, q0, r0, m0, 'v1/device/me/telemetry', ... (20 bytes))
'{temperature:36.6}'
接下来,我将ESP8266项目更改为使用1884年的Mosquitto端口(1883年的Instad)。
int thingsboard_port = 1884; // Local laptop
我从命令行启动了Mosquitto,以允许显示日志记录。产生此输出是为了响应ESP8266对client.publish的调用
1568132857: New client connected from 192.168.2.2 as ESP8266 Device (p2, c1, k15, u'BJ9nLTOAc3hEL3NOlGei').
1568132857: No will message specified.
1568132857: Sending CONNACK to ESP8266 Device (0, 0)
1568132857: Received PUBLISH from ESP8266 Device (d0, q0, r0, m0, 'v1/devices/me/telemetry', ... (38 bytes))
1568132880: Client ESP8266 Device has exceeded timeout, disconnecting.
1568132899: Received PINGREQ from mosq/nmafqF16uw5edvXJGA
1568132899: Sending PINGRESP to mosq/nmafqF16uw5edvXJGA
tb-gateway.log重复包含这两行:
2019-09-10 17:56:41,980 [pool-3-thread-1] INFO o.t.g.service.MqttMessageSender - Outgoing queue is not empty. [1] messages are still in progress
2019-09-10 17:56:41,981 [pool-3-thread-1] INFO o.t.g.service.MqttMessageSender - Waiting until all messages are sent before going to the next bucket