我试图部署非常简单的node-red流来使用MQTT向Azure发送消息 . 不幸的是,每次都会崩溃节点红色 .
我在Raspberry Pi 3上运行NodeRed:
16 May 11:29:19 - [info] Node-RED version: v0.18.4
16 May 11:29:19 - [info] Node.js version: v8.11.1
16 May 11:29:19 - [info] Linux 4.14.34-v7+ arm LE
一直在尝试这两个节点库:
https://github.com/Azure/azure-iot-sdk-node/tree/master/device/node-red https://github.com/rasavant-ms/node-red-contrib-azure/tree/master/iot-hub
节点红色日志:
Connection string :HostName=learning-hub.azure-devices.net;DeviceId=undefined;SharedAccessKey=undefined
16 May 11:16:52 - [error] [azureiothub:Azure IoT Hub] Could not connect: Connection refused: Not authorized
16 May 11:16:52 - [info] [azureiothub:Azure IoT Hub] Connected to Azure IoT Hub.
16 May 11:16:52 - [red] Uncaught Exception:
16 May 11:16:52 - TypeError: Cannot read property 'on' of undefined
nodered.service: Main process exited, code=exited, status=1/FAILURE
nodered.service: Unit entered failed state.
nodered.service: Failed with result 'exit-code'.
nodered.service: Service hold-off time over, scheduling restart.
Stopped Node-RED graphical event wiring tool..
这是我的简单流程:
以及节点中的信息:
Azure IoT中心
DTU智能库Azure
{
"deviceID": "SensorTag-D2",
"SAK": "<Primary-Key>",
"Protocol": "mqtt",
"Data": {
"Light": "25"
}
}
1 回答
从日志和Azure IoT Hub节点信息中,您似乎没有设置Azure IoT Hub的连接字符串 . 您可以通过复制导入流,并在弹出窗口中粘贴以下内容:
然后双击Azure IoT Hub节点,它将显示连接字符串设置 .
请注意,当您想要发送数据时,您应该将注入的Payload设置为字符串格式而不是json .