# Connect sensor with azure iot hub

**URL:** https://discourse.nodered.org/t/connect-sensor-with-azure-iot-hub/3909
**Category:** General
**Created:** [12 October 2018 05:43 UTC](https://discourse.nodered.org/t/connect-sensor-with-azure-iot-hub/3909 "2018-10-12T05:43:15Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![manal](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@manal](https://discourse.nodered.org/u/manal)
#### Post date: [12 October 2018 05:43 UTC](https://discourse.nodered.org/t/connect-sensor-with-azure-iot-hub/3909/1 "2018-10-12T05:43:15Z")

</div>

hi all,

I am trying to connect rpi ds18b20 with azure iot hub, but the iot hub is disconnected all the time even I entered the host name. here, I am trying with real sensor , it is not simulated. could you help me to know where is the problem, please?  
I installed node-red in raspberry pi 3 modle b+ , with raspbian  
node-red version V0.19.3  
node.js version v8.11.1

Thanks

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [12 October 2018 06:08 UTC](https://discourse.nodered.org/t/connect-sensor-with-azure-iot-hub/3909/2 "2018-10-12T06:08:04Z")

</div>

Have you looked at the log file to see if any errors are listed?

---

<div class="post-metadata">

### Author: ![manal](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@manal](https://discourse.nodered.org/u/manal)
#### Post date: [12 October 2018 06:25 UTC](https://discourse.nodered.org/t/connect-sensor-with-azure-iot-hub/3909/3 "2018-10-12T06:25:04Z")

</div>

Sorry, do you mean node-red console? or there is another log.

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [12 October 2018 06:31 UTC](https://discourse.nodered.org/t/connect-sensor-with-azure-iot-hub/3909/4 "2018-10-12T06:31:34Z")

</div>

Well you could check the console or look at the historical log data using the command node-red-log

---

<div class="post-metadata">

### Author: ![manal](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@manal](https://discourse.nodered.org/u/manal)
#### Post date: [12 October 2018 06:32 UTC](https://discourse.nodered.org/t/connect-sensor-with-azure-iot-hub/3909/5 "2018-10-12T06:32:09Z")

</div>

ok. sorry I am new with node-red. I found this in console

Connection string :HostName=HostName=[c......](http://cloud-.......);DeviceId=undefined;SharedAccessKey=undefined

12 Oct 06:26:09 - [error] [azureiothub:Azure IoT Hub] Could not connect: connect ENOENT /=[c,,,,,,,,](

I didn't define this in node red as I do not know where can I enter this information? I just put the host name in azure iot hub node?

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [12 October 2018 06:38 UTC](https://discourse.nodered.org/t/connect-sensor-with-azure-iot-hub/3909/6 "2018-10-12T06:38:23Z")

</div>

If you haven’t read it the page dedicated to the raspberry pi in the docs is worth a read.

I’ve never used that node (if you are using a specific node it’s worth stating that in your initial post in future). But there is a initial flow in the nodes readme, so I would suggest trying to get their example to work and if you can’t come back here.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [12 October 2018 07:56 UTC](https://discourse.nodered.org/t/connect-sensor-with-azure-iot-hub/3909/7 "2018-10-12T07:56:39Z")

</div>

> [@manal](#):
>
> Connection string :HostName=HostName=[c......](http://cloud-.......);DeviceId=undefined;SharedAccessKey=undefined

It looks like you haven't completed the setup of the Azure hub. I've not used it myself but I'm guessing that it uses an OAuth authentication that requires setup firstly in the hub itself. That should give you an access key and possibly the other settings you are missing above (DeviceId for example). It may also require you to define the URL that the authentication service will hand control back to. Likely to be the URL for Node-RED.

---

<div class="post-metadata">

### Author: ![manal](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@manal](https://discourse.nodered.org/u/manal)
#### Post date: [15 October 2018 02:22 UTC](https://discourse.nodered.org/t/connect-sensor-with-azure-iot-hub/3909/8 "2018-10-15T02:22:54Z")

</div>

thanks guys

it is working now, the problem was " "  
I should write the connection string between " "

but after that I have encountered new problem ...  
sometimes the device send data to cloud, other times it shows error message...

"Error while trying to send message : not connected error: connect ECONNREFUSED "node-red ip: port"

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [15 October 2018 08:49 UTC](https://discourse.nodered.org/t/connect-sensor-with-azure-iot-hub/3909/9 "2018-10-15T08:49:51Z")

</div>

Are you on an enterprise network? If so, I'd say that their security services and routing is slowing down your connection. It may be that the latency is sometimes a little too high.

---

<div class="post-metadata">

### Author: ![manal](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@manal](https://discourse.nodered.org/u/manal)
#### Post date: [16 October 2018 02:02 UTC](https://discourse.nodered.org/t/connect-sensor-with-azure-iot-hub/3909/10 "2018-10-16T02:02:20Z")

</div>

I am using the university network and connect to azure iot hub from my university account ... I think the problem as you said

thanks
