0

我正在运行一个永久脚本,使用以下命令将数据从树莓派 3 发送到 azure-iot-hub,root@raspberrypi3:~# forever start /home/pi/azure/iam/ble_azure.js

工作了大约 1.5 天后,我停止在 auzre-iot-hub 收到消息,当我检查永久列表时,我得到以下信息:

root@raspberrypi3:~# forever list
info:    Forever processes running
data:        uid  command         script                          forever pid  id logfile                 uptime         
data:    [0] NWgI /usr/bin/nodejs /home/pi/azure/iam/ble_azure.js 8990    3784    /root/.forever/NWgI.log 0:21:17:38.742 

当我检查日志文件时,我收到以下错误消息:

/home/pi/azure/iam/node_modules/applicationinsights/AutoCollection/Exceptions.js:27
                        throw error;
                        ^
NotConnectedError: mqtt.js returned client disconnecting error
    at translateError (/home/pi/azure/iam/node_modules/azure-iot-device-mqtt/lib/mqtt-translate-error.js:25:11)
    at MqttTwinReceiver._handleError (/home/pi/azure/iam/node_modules/azure-iot-device-mqtt/lib/mqtt-twin-receiver.js:201:42)
    at /home/pi/azure/iam/node_modules/azure-iot-device-mqtt/lib/mqtt-twin-receiver.js:64:18
    at MqttClient._checkDisconnecting (/home/pi/azure/iam/node_modules/mqtt/lib/client.js:314:7)
    at MqttClient.subscribe (/home/pi/azure/iam/node_modules/mqtt/lib/client.js:423:12)
    at /home/pi/azure/iam/node_modules/azure-iot-device-mqtt/lib/mqtt-twin-receiver.js:62:22
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickCallback (internal/process/next_tick.js:104:9)
error: Forever detected script exited with code: 7
error: Script restart attempt #34
state has changed poweredOn
started scanning
[IoT hub Client] Connect error: mqtt.js returned premature close error

通过日志文件,mqtt错误不断发生多次并永远成功处理,我不明白为什么1.5天后,我得到这个错误:

**error: Forever detected script exited with code: 7
error: Script restart attempt #34**

还有为什么我一直收到这样的 mqtt 错误,为什么它一直断开连接?

**NotConnectedError: mqtt.js returned client disconnecting error**


Forever --version 
v0.15.3

root@raspberrypi3:~# uname -a
Linux raspberrypi3 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux

谢谢

4

1 回答 1

0

如果您使用Client.fromConnectionString实例化客户端对象,SDK 会每 45 分钟断开连接并重新连接以更新共享访问签名令牌。(使用不同身份验证机制的 AMQP 不会发生这种情况)。可能是在重新建立连接时,客户端遇到了我们在此问题中一直在跟踪的“过早关闭”错误。

有两件事可以帮助限制与断开/重新连接相关的潜在错误:

最后但并非最不重要的一点是,SDK 的下一个版本 (1.2.0) 将包含一个重试/重新连接逻辑,它比以前更强大。我会更新问题以在它发布时指向它。

于 2017-10-24T19:14:34.517 回答