0
votes

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"
  }
} 
2

2 Answers

0
votes

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.

0
votes

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.