# Azure IoT Hub - Node - Connectivity Loss

**URL:** <https://discourse.nodered.org/t/azure-iot-hub-node-connectivity-loss/40672>\
**Category:** General\
**Created:** [9 February 2021 13:01 UTC](https://discourse.nodered.org/t/azure-iot-hub-node-connectivity-loss/40672 "2021-02-09T13:01:36Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![sathishkumarc14](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@sathishkumarc14](https://discourse.nodered.org/u/sathishkumarc14)\
**Post date:** [9 February 2021 13:01 UTC](https://discourse.nodered.org/t/azure-iot-hub-node-connectivity-loss/40672/1 "2021-02-09T13:01:37Z")

</div>

Hi,

Started using "Azure IoT hub" node from [here](https://flows.nodered.org/node/node-red-contrib-azure-iot-hub). It sends the data as a payload in MQTT/HTTP.

If internet connectivity fails or IoT hub is not available while sending a data from node red how to handle? Can we get any response like connectivity error or message?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [9 February 2021 13:43 UTC](https://discourse.nodered.org/t/azure-iot-hub-node-connectivity-loss/40672/2 "2021-02-09T13:43:56Z")

</div>

I haven't used that node, but the first thing I would do is to attach a Catch node to it and see if it generates errors for you.

However, I would not hold out too much hope as I see it has not been updated in three years.

---

<div class="post-metadata">

**Author:** ![aderici](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/aderici/32/37279_2.png) [@aderici](https://discourse.nodered.org/u/aderici)\
**Post date:** [9 February 2021 19:18 UTC](https://discourse.nodered.org/t/azure-iot-hub-node-connectivity-loss/40672/3 "2021-02-09T19:18:27Z")

</div>

Watch for node status changes and handle accordingly. When connection is lost it should be reflected in the node status

---

<div class="post-metadata">

**Author:** ![sathishkumarc14](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@sathishkumarc14](https://discourse.nodered.org/u/sathishkumarc14)\
**Post date:** [10 February 2021 04:26 UTC](https://discourse.nodered.org/t/azure-iot-hub-node-connectivity-loss/40672/4 "2021-02-10T04:26:59Z")

</div>

can we send a data to Azure IoT Hub using MQTT out node? Like publish MQTT.

---

<div class="post-metadata">

**Author:** ![sathishkumarc14](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@sathishkumarc14](https://discourse.nodered.org/u/sathishkumarc14)\
**Post date:** [10 February 2021 04:28 UTC](https://discourse.nodered.org/t/azure-iot-hub-node-connectivity-loss/40672/5 "2021-02-10T04:28:23Z")

</div>

Catch node doesn't give any connectivity loss error or information. Is there any other way to send data from Node RED to Azure IoT Hub?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [10 February 2021 07:17 UTC](https://discourse.nodered.org/t/azure-iot-hub-node-connectivity-loss/40672/6 "2021-02-10T07:17:11Z")

</div>

Does the status show anything helpful as suggested by @aderici? If so you can use a status node.

---

<div class="post-metadata">

**Author:** ![sathishkumarc14](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@sathishkumarc14](https://discourse.nodered.org/u/sathishkumarc14)\
**Post date:** [10 February 2021 08:44 UTC](https://discourse.nodered.org/t/azure-iot-hub-node-connectivity-loss/40672/7 "2021-02-10T08:44:55Z")

</div>

That is okay. But if internet connectivity is lost then node status is not changing. This one is not reliable.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [10 February 2021 09:24 UTC](https://discourse.nodered.org/t/azure-iot-hub-node-connectivity-loss/40672/8 "2021-02-10T09:24:37Z")

</div>

Does the node send a message at all in the error condition?  
If so then feed it into a debug node configured to show Complete Message and see what is in there.

---

<div class="post-metadata">

**Author:** ![aderici](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/aderici/32/37279_2.png) [@aderici](https://discourse.nodered.org/u/aderici)\
**Post date:** [10 February 2021 10:01 UTC](https://discourse.nodered.org/t/azure-iot-hub-node-connectivity-loss/40672/9 "2021-02-10T10:01:06Z")

</div>

@sathishkumarc14 You can also use http to communicate with iot hub, see an example here. Copy and import this flow :

```auto
[{"id":"54de72b2.ff5d2c","type":"function","z":"ef196bfe.de8c48","name":"prepare IoT Hub message","func":"msg.payload = JSON.stringify({\"hello\": \"world\"})\nmsg.headers = {}\nmsg.headers[\"Authorization\"] = {iotHubSasToken}`;\nmsg.url = `https://{iotHubName}.azure-devices.net/devices/${deviceId}/messages/events?api-version=2018-06-30\nreturn msg;","outputs":1,"noerr":0,"x":250,"y":240,"wires":[["a33ab64.dfac048"]]},{"id":"a33ab64.dfac048","type":"http request","z":"ef196bfe.de8c48","name":"IoT Hub HttpS","method":"POST","ret":"txt","paytoqs":false,"url":"","tls":"","persist":false,"proxy":"","authType":"","x":500,"y":240,"wires":[["8cfb0902.4cfea8"]]},{"id":"62458b2.8d37c74","type":"inject","z":"ef196bfe.de8c48","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":180,"wires":[["54de72b2.ff5d2c"]]},{"id":"8cfb0902.4cfea8","type":"debug","z":"ef196bfe.de8c48","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":620,"y":180,"wires":[]}]

```

You will need to generate a "SAS Token" for your device id in order to use this method.

Best regards,

---

<div class="post-metadata">

**Author:** ![sathishkumarc14](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@sathishkumarc14](https://discourse.nodered.org/u/sathishkumarc14)\
**Post date:** [10 February 2021 10:45 UTC](https://discourse.nodered.org/t/azure-iot-hub-node-connectivity-loss/40672/10 "2021-02-10T10:45:43Z")

</div>

Thanks @aderici It is working fine.

---

<div class="post-metadata">

**Author:** ![nikhilkinkar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nikhilkinkar/32/37072_2.png) [@nikhilkinkar](https://discourse.nodered.org/u/nikhilkinkar)\
**Post date:** [12 February 2021 19:17 UTC](https://discourse.nodered.org/t/azure-iot-hub-node-connectivity-loss/40672/11 "2021-02-12T19:17:05Z")

</div>

> [@sathishkumarc14](#):
>
> can we send a data to Azure IoT Hub using MQTT out node?

Have a look at this blog post ([here](https://medium.com/@nikhil.kinkar/connecting-node-red-to-azure-iot-hub-using-mqtt-nodes-6e9160549348)), recently I was in similar situation like yours, found the solution for it using MQTT nodes for connection to Azure IoT Hub.

---

<div class="post-metadata">

**Author:** ![sathishkumarc14](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@sathishkumarc14](https://discourse.nodered.org/u/sathishkumarc14)\
**Post date:** [15 February 2021 09:51 UTC](https://discourse.nodered.org/t/azure-iot-hub-node-connectivity-loss/40672/12 "2021-02-15T09:51:03Z")

</div>

@nikhilkinkar Great information. Thanks.

Can we log the data if MQTT fails? How can we identify the MQTT connectivity failure?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [15 February 2021 10:25 UTC](https://discourse.nodered.org/t/azure-iot-hub-node-connectivity-loss/40672/13 "2021-02-15T10:25:26Z")

</div>

> [@sathishkumarc14](#):
>
> How can we identify the MQTT connectivity failure?

That is what the MQTT LWT (Last Will and Testament) feature is for. You will find that described (and a lot more besides) in [MQTT Essentials - All Core Concepts Explained](https://www.hivemq.com/mqtt-essentials/)

**[Edit]** Actually that might not be the right answer. Where is it that you are are trying to detect the error and where is the MQTT broker, and which comms link is it that is failing?

---

<div class="post-metadata">

**Author:** ![aderici](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/aderici/32/37279_2.png) [@aderici](https://discourse.nodered.org/u/aderici)\
**Post date:** [15 February 2021 11:55 UTC](https://discourse.nodered.org/t/azure-iot-hub-node-connectivity-loss/40672/14 "2021-02-15T11:55:00Z")

</div>

I’ve been through all this, use http, you’ll thank me later 🙂

---

<div class="post-metadata">

**Author:** ![nikhilkinkar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nikhilkinkar/32/37072_2.png) [@nikhilkinkar](https://discourse.nodered.org/u/nikhilkinkar)\
**Post date:** [15 February 2021 13:38 UTC](https://discourse.nodered.org/t/azure-iot-hub-node-connectivity-loss/40672/15 "2021-02-15T13:38:50Z")

</div>

@sathishkumarc14 if you are saving node-red logs, whenever there is any change in mqtt node connectivity you can get it from node-red logs. About identifying the mqtt connectivity failure, you can use node-red catch flow for catching any future errors.  
I would add one more point here, I have used mqtt nodes with AWS IoT core, it is working from a longer time without any issues. While working with Azure I have seen that the documentation for Azure is quite difficult to get to the point as compared to AWS (I am new to Azure).
