我尝试部署非常简单的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"
}
} 发布于 2018-05-17 10:24:57
从日志和Azure IoT集线器节点信息来看,您似乎没有设置Azure IoT Hub.You可以通过在弹出窗口中复制并粘贴以下内容来导入流的连接字符串:
[{"id":"7b108cb1.4807c8","type":"azureiothub","z":"8d630437.6181a8","name":"Azure IoT Hub","protocol":"amqp","x":379.5,"y":89.22000122070312,"wires":[["b79e7772.b39cc8"]]},{"id":"2269b09.2499b5","type":"inject","z":"8d630437.6181a8","name":"Inject data","topic":"","payload":"Hello from device","payloadType":"str","repeat":"","crontab":"","once":false,"x":209.5,"y":196.01998901367187,"wires":[["7b108cb1.4807c8"]]},{"id":"b79e7772.b39cc8","type":"function","z":"8d630437.6181a8","name":"Convert Bytes to String","func":"msg.payload = msg.payload.toString();\nreturn msg;","outputs":1,"noerr":0,"x":614.5,"y":201.57000732421875,"wires":[["a142535d.158f4"]]},{"id":"a142535d.158f4","type":"debug","z":"8d630437.6181a8","name":"","active":true,"console":"false","complete":"false","x":762.5,"y":320.1499938964844,"wires":[]}]然后双击Azure IoT集线器节点,它将显示连接字符串设置。

请注意,当您想要发送数据时,应该将inject的Payload设置为string格式,而不是json格式。
发布于 2019-07-12 16:18:35
您需要在inject节点上使用以下数据格式。
{
"deviceId": "testenode1",
"key": "cw3nniq77BbjpOCDLqb7xEFTU509HeR6Ki1NwR20jj0=",
"protocol": "amqp",
"data": "{tem: 25, wind: 20}"
}并且Azure IoT集线器节点具有主机名。
我认为之前的版本是SAK而不是key。
https://stackoverflow.com/questions/50369857
复制相似问题