0

I have tried to deploy the very simple node-red flow to send a message using MQTT to Azure. Unfortunately it crashes node-red every time.

I'm running NodeRed on a Raspberry Pi 3:

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

Been trying both of these node libraries:

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

Node Red Log:

   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..

This is my simple flow:

NodeRed Flow

And the information in the nodes:

Azure IoT Hub

Azure IoT Hub information

DTU Smart Library Azure

{
  "deviceID": "SensorTag-D2",
  "SAK": "<Primary-Key>",
  "Protocol": "mqtt",
  "Data": {
    "Light": "25"
  }
} 
hardillb
  • 54,545
  • 11
  • 67
  • 105

2 Answers2

0

From the log and Azure IoT Hub node information, it seems that you did not set the connection string of the Azure IoT Hub.You can import the flow via copy and paste the below in the popup window:

[{"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":[]}]

And then double click on the Azure IoT Hub node, it will show the connection string setting. enter image description here

And please note that,when you want to send the data, you should set Payload of the inject as string format instead of json.

Michael Xu
  • 4,382
  • 1
  • 8
  • 16
  • Which NodeRed library do you use? In the one I use it only says HostName: . And it would obviously be better if it would take an entire connection string as yours does. – Niklas Buhl May 18 '18 at 08:11
  • @NiklasBuhl, sorry for late reply. My Node-RED version is v0.18.5. Can you export your flow so that i can compare the difference between with mine sample? – Michael Xu May 21 '18 at 01:34
  • I mean which Azure IoT Hub node library do you use? Because it has the right input: "Connection String". Where the ones I found only has "Hostname". – Niklas Buhl May 22 '18 at 08:19
  • @NiklasBuhl, i used the node-red-contrib-azure-iot-hub library.You can refer to this article(https://flows.nodered.org/node/node-red-contrib-azure-iot-hub). – Michael Xu May 22 '18 at 09:03
  • @NiklasBuhl, have you tried to use node-red-contrib-azure-iot-hub library to create the flow with Azure IoT Hub node?If it does not works, feel free let me know. – Michael Xu May 23 '18 at 06:42
  • I think the issue might have been that I tried to inject the data as JSON instead of a string as you mentioned! – Niklas Buhl May 30 '18 at 11:25
0

You need to use data format below on inject node.

{
  "deviceId": "testenode1",
  "key": "cw3nniq77BbjpOCDLqb7xEFTU509HeR6Ki1NwR20jj0=",
  "protocol": "amqp",
  "data": "{tem: 25, wind: 20}"
}

and Azure IoT Hub node has hostname.

I think the previous version has SAK instead of key.

Karl
  • 854
  • 9
  • 21
Kevin Oh
  • 1
  • 2