<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>iot Archives - Blog IT</title>
	<atom:link href="https://blogit.create.pt/tag/iot-2/feed/" rel="self" type="application/rss+xml" />
	<link>https://blogit.create.pt/tag/iot-2/</link>
	<description>Create IT blogger community</description>
	<lastBuildDate>Wed, 18 Nov 2020 23:00:54 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>
	<item>
		<title>WLED &#8211; Check how I built my first TV led strip super easy</title>
		<link>https://blogit.create.pt/ricardocosta/2020/11/18/wled-check-how-i-built-my-first-tv-led-strip-super-easy/</link>
					<comments>https://blogit.create.pt/ricardocosta/2020/11/18/wled-check-how-i-built-my-first-tv-led-strip-super-easy/#comments</comments>
		
		<dc:creator><![CDATA[Ricardo Costa]]></dc:creator>
		<pubDate>Wed, 18 Nov 2020 23:00:44 +0000</pubDate>
				<category><![CDATA[IoT]]></category>
		<category><![CDATA[iot]]></category>
		<category><![CDATA[led]]></category>
		<guid isPermaLink="false">https://blogit.create.pt/?p=12141</guid>

					<description><![CDATA[<p>WLED is a really cool project found here. It&#8217;s a web server to run on ESP8266/ESP32 that can control a lot of different kind of leds. In the next paragraphs I will show you how did I build my first TV led strip. I will show you the parts that I&#8217;ve used, how to install [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/ricardocosta/2020/11/18/wled-check-how-i-built-my-first-tv-led-strip-super-easy/">WLED &#8211; Check how I built my first TV led strip super easy</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>WLED is a really cool project found <a rel="noreferrer noopener" href="https://github.com/Aircoookie/WLED" data-type="URL" data-id="https://github.com/Aircoookie/WLED" target="_blank">here</a>. It&#8217;s a web server to run on ESP8266/ESP32 that can control a lot of different kind of leds.</p>



<p>In the next paragraphs I will show you how did I build my first TV led strip. I will show you the parts that I&#8217;ve used, how to install the software, and also the way I&#8217;ve assembled everything in a small box on the back of my TV.</p>



<p>The first thing that I did was to buy an ESP8266. I bought this <a rel="noreferrer noopener" href="https://mauser.pt/catalog/product_info.php?cPath=1667_2889_2619&amp;products_id=096-6784" target="_blank">one</a> from Mauser.</p>



<figure class="wp-block-image size-large is-resized is-style-default"><img fetchpriority="high" decoding="async" src="https://blogit.create.pt/wp-content/uploads/2020/11/ESP8266.jpg" alt="ESP8266" class="wp-image-12144" width="512" height="290" srcset="https://blogit.create.pt/wp-content/uploads/2020/11/ESP8266.jpg 1024w, https://blogit.create.pt/wp-content/uploads/2020/11/ESP8266-300x170.jpg 300w, https://blogit.create.pt/wp-content/uploads/2020/11/ESP8266-768x435.jpg 768w, https://blogit.create.pt/wp-content/uploads/2020/11/ESP8266-696x394.jpg 696w, https://blogit.create.pt/wp-content/uploads/2020/11/ESP8266-742x420.jpg 742w" sizes="(max-width: 512px) 100vw, 512px" /><figcaption>ESP8266</figcaption></figure>



<p>I&#8217;ve connected the ESP8266 to my PC with the USB cable. And uploaded to the device. How did I do that?</p>



<p>The WLED binary that I&#8217;ve used was <em><strong>WLED_0.10.2_ESP8266.bin</strong></em> that I&#8217;ve downloaded from the <a rel="noreferrer noopener" href="https://github.com/Aircoookie/WLED/releases" target="_blank">releases page</a>.</p>



<p>I use this great tool esphome-flasher. Downloaded the latest release <a rel="noreferrer noopener" href="https://github.com/esphome/esphome-flasher/releases" target="_blank">here</a>. Just run the tool and choose the previous downloaded binary. Don&#8217;t forget to have the device connected to the USB port of your computer.</p>



<figure class="wp-block-image size-large is-resized is-style-default"><img decoding="async" src="https://blogit.create.pt/wp-content/uploads/2020/11/esphome-flasher-wled.png" alt="esphome flasher wled" class="wp-image-12148" width="704" height="637" srcset="https://blogit.create.pt/wp-content/uploads/2020/11/esphome-flasher-wled.png 703w, https://blogit.create.pt/wp-content/uploads/2020/11/esphome-flasher-wled-300x271.png 300w, https://blogit.create.pt/wp-content/uploads/2020/11/esphome-flasher-wled-696x630.png 696w, https://blogit.create.pt/wp-content/uploads/2020/11/esphome-flasher-wled-464x420.png 464w" sizes="(max-width: 704px) 100vw, 704px" /><figcaption>esphome flasher wled</figcaption></figure>



<p>In my computer the device shows up in COM4 port.</p>



<p>After that your newly flashed WLED device should give you an access point named WLED-AP. Connect to it with wled1234 password. I connected with my phone and I was immediately redirected to the first time configuration web page. If this doesn&#8217;t happen to you, open the browser and go to 4.3.2.1 you should see this page.</p>



<figure class="wp-block-image size-large is-resized is-style-default"><img decoding="async" src="https://blogit.create.pt/wp-content/uploads/2020/11/wled-first-configuration-732x1024.jpg" alt="wled first configuration" class="wp-image-12150" width="549" height="768" srcset="https://blogit.create.pt/wp-content/uploads/2020/11/wled-first-configuration-732x1024.jpg 732w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-first-configuration-214x300.jpg 214w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-first-configuration-768x1075.jpg 768w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-first-configuration-696x974.jpg 696w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-first-configuration-1068x1495.jpg 1068w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-first-configuration-300x420.jpg 300w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-first-configuration.jpg 1076w" sizes="(max-width: 549px) 100vw, 549px" /><figcaption>wled first configuration</figcaption></figure>



<p>Insert your home wifi SSID and password, click Save &amp; Connect. </p>



<figure class="wp-block-image size-large is-resized is-style-default"><img decoding="async" src="https://blogit.create.pt/wp-content/uploads/2020/11/wled-wifi-settings-489x1024.jpg" alt="wled wifi settings" class="wp-image-12151" width="367" height="768" srcset="https://blogit.create.pt/wp-content/uploads/2020/11/wled-wifi-settings-489x1024.jpg 489w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-wifi-settings-143x300.jpg 143w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-wifi-settings-768x1607.jpg 768w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-wifi-settings-734x1536.jpg 734w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-wifi-settings-979x2048.jpg 979w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-wifi-settings-696x1456.jpg 696w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-wifi-settings-1068x2235.jpg 1068w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-wifi-settings-201x420.jpg 201w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-wifi-settings.jpg 1080w" sizes="(max-width: 367px) 100vw, 367px" /><figcaption>wled wifi settings</figcaption></figure>



<p>Your device will reboot and connect to your wifi network. </p>



<figure class="wp-block-image size-large is-resized is-style-default"><img decoding="async" src="https://blogit.create.pt/wp-content/uploads/2020/11/wled-wifi-connect-1024x412.jpg" alt="wled wifi connect" class="wp-image-12152" width="512" height="206" srcset="https://blogit.create.pt/wp-content/uploads/2020/11/wled-wifi-connect-1024x412.jpg 1024w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-wifi-connect-300x121.jpg 300w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-wifi-connect-768x309.jpg 768w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-wifi-connect-696x280.jpg 696w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-wifi-connect-1068x430.jpg 1068w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-wifi-connect-1043x420.jpg 1043w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-wifi-connect.jpg 1080w" sizes="(max-width: 512px) 100vw, 512px" /><figcaption>wled wifi connect</figcaption></figure>



<p>Find the IP address of your device using one of the thousands of network tools available on the internet and open your browser with that IP address.  </p>



<figure class="wp-block-image size-large is-resized is-style-default"><img decoding="async" src="https://blogit.create.pt/wp-content/uploads/2020/11/wled-488x1024.jpg" alt="wled" class="wp-image-12153" width="366" height="768" srcset="https://blogit.create.pt/wp-content/uploads/2020/11/wled-488x1024.jpg 488w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-143x300.jpg 143w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-768x1611.jpg 768w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-732x1536.jpg 732w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-977x2048.jpg 977w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-696x1460.jpg 696w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-1068x2240.jpg 1068w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-200x420.jpg 200w, https://blogit.create.pt/wp-content/uploads/2020/11/wled.jpg 1080w" sizes="(max-width: 366px) 100vw, 366px" /><figcaption>wled</figcaption></figure>



<p>And that&#8217;s it. You have your WLED device installed and ready to use. </p>



<p>For the LED strip I bought from <a rel="noreferrer noopener" href="https://pt.aliexpress.com/item/2036819167.html?spm=a2g0s.9042311.0.0.fd36b90avJwEnK" target="_blank">AliExpress</a>. It&#8217;s a 5 meter WS2810 LED strip (individually addressable leds). The next configuration is the LED count. For that, I needed to measure my TV, cut the strip and count the number of LEDs that I was going to control. For my TV I have 18 leds on each side and 32 leds, top and bottom. That gives me a total led count of 100.</p>



<figure class="wp-block-image size-large is-resized is-style-default"><img decoding="async" src="https://blogit.create.pt/wp-content/uploads/2020/11/wled-led-count-473x1024.jpg" alt="wled led count" class="wp-image-12155" width="473" height="1024" /><figcaption>wled led count</figcaption></figure>



<p>Now for the wire connection, this is how you should do it. Im using a 5V led strip so I followed the first option in the schematics picture below.</p>



<figure class="wp-block-image size-large is-resized is-style-default"><img decoding="async" src="https://blogit.create.pt/wp-content/uploads/2020/11/wled-wire-connection.png" alt="wled wire connection" class="wp-image-12157" width="640" height="426" srcset="https://blogit.create.pt/wp-content/uploads/2020/11/wled-wire-connection.png 640w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-wire-connection-300x200.png 300w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-wire-connection-631x420.png 631w" sizes="(max-width: 640px) 100vw, 640px" /><figcaption>wled wire connection</figcaption></figure>



<p>I took this picture from projectwiki &#8211; <a rel="noreferrer noopener" href="https://github.com/Aircoookie/WLED/wiki" target="_blank">https://github.com/Aircoookie/WLED/wiki</a></p>



<p>If the distance between the device and the led strip is long you should use a level shifter. That was not my case so I didnt have the need to include one in my solution. I used the 470 ohm resistor and and the 1000 uF capacitor.</p>



<p>Because I used the nodemcu, it is an ESP8266 device, I connected the D4 pin to the data input on the led strip. The led strip has3 conductors, 5V, GND and DATA.</p>



<p>I connected the 5V and GND not only in the beginning of the led strip but also in the end. The data input, that is connected to D4 pin, it is only connected in the beginning of the strip, and there is an arrow on the strip pointing to the data signal flow direction. </p>



<figure class="wp-block-image size-large is-resized is-style-default"><img decoding="async" src="https://blogit.create.pt/wp-content/uploads/2020/11/wled-power-data-1.jpg" alt="wled power data" class="wp-image-12164" width="512" height="384" srcset="https://blogit.create.pt/wp-content/uploads/2020/11/wled-power-data-1.jpg 1024w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-power-data-1-300x225.jpg 300w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-power-data-1-768x576.jpg 768w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-power-data-1-696x522.jpg 696w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-power-data-1-560x420.jpg 560w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-power-data-1-80x60.jpg 80w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-power-data-1-265x198.jpg 265w" sizes="(max-width: 512px) 100vw, 512px" /><figcaption>wled power data</figcaption></figure>



<p>And that&#8217;s it! I can know control my TV led strip thru the web interface and I can also use the WLED mobile that I&#8217;ve installed on my smartphone.</p>



<p>Enjoy!</p>



<figure class="wp-block-image size-large is-style-default"><img decoding="async" width="1024" height="815" src="https://blogit.create.pt/wp-content/uploads/2020/11/wled-show.jpg" alt="wled show" class="wp-image-12165" srcset="https://blogit.create.pt/wp-content/uploads/2020/11/wled-show.jpg 1024w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-show-300x239.jpg 300w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-show-768x611.jpg 768w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-show-696x554.jpg 696w, https://blogit.create.pt/wp-content/uploads/2020/11/wled-show-528x420.jpg 528w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>wled show</figcaption></figure>
<p>The post <a href="https://blogit.create.pt/ricardocosta/2020/11/18/wled-check-how-i-built-my-first-tv-led-strip-super-easy/">WLED &#8211; Check how I built my first TV led strip super easy</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/ricardocosta/2020/11/18/wled-check-how-i-built-my-first-tv-led-strip-super-easy/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Home Assistant with Shelly 2.5 switch the easy way</title>
		<link>https://blogit.create.pt/ricardocosta/2020/10/20/home-assistant-with-shelly-2-5-switch-the-easy-way/</link>
					<comments>https://blogit.create.pt/ricardocosta/2020/10/20/home-assistant-with-shelly-2-5-switch-the-easy-way/#respond</comments>
		
		<dc:creator><![CDATA[Ricardo Costa]]></dc:creator>
		<pubDate>Tue, 20 Oct 2020 10:40:36 +0000</pubDate>
				<category><![CDATA[IoT]]></category>
		<category><![CDATA[Home Automation]]></category>
		<category><![CDATA[home assistant]]></category>
		<category><![CDATA[iot]]></category>
		<category><![CDATA[mqtt]]></category>
		<category><![CDATA[shelly]]></category>
		<guid isPermaLink="false">https://blogit.create.pt/?p=12052</guid>

					<description><![CDATA[<p>How-to configure Home Assistant configuration.yaml file for your Shelly 2.5 switch. The 2.5 switch is a double relay switch and roller shutter.</p>
<p>The post <a href="https://blogit.create.pt/ricardocosta/2020/10/20/home-assistant-with-shelly-2-5-switch-the-easy-way/">Home Assistant with Shelly 2.5 switch the easy way</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>I&#8217;ve recently bought a Shelly 2.5 switch and this is how I&#8217;ve setup my Home Assistant. Here is my configuration.yaml for the switches. I&#8217;m controlling lights as a result I&#8217;m using the lights objects</p>



<p>I use the Home Assistant add-on named mosquitto as MQTT for everything so I can keep the communication system the same for all my devices and keep the management system simple.</p>



<p>First of all I configured my Shelly 2.5 thru the web interface to use MQTT. This is done in the &#8220;Internet &amp; Security&#8221; configuration settings, &#8220;Advance Developer &#8211; Settings&#8221;.</p>



<p>I configured the username and password that was set in Mosquitto MQTT server in Home Assistant. Don&#8217;t forget the IP address of the Home Assistant server (port 1883).</p>



<p>I&#8217;ve used a custom MQTT prefix as you can see in the yaml files configuration below. I use this prefix as a way to give a name to my switch</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" width="792" height="930" src="https://blogit.create.pt/wp-content/uploads/2020/10/shelly-2.5-mqtt.png" alt="Shelly 2.5 web interface for configuring MQTT" class="wp-image-12064" srcset="https://blogit.create.pt/wp-content/uploads/2020/10/shelly-2.5-mqtt.png 792w, https://blogit.create.pt/wp-content/uploads/2020/10/shelly-2.5-mqtt-255x300.png 255w, https://blogit.create.pt/wp-content/uploads/2020/10/shelly-2.5-mqtt-768x902.png 768w, https://blogit.create.pt/wp-content/uploads/2020/10/shelly-2.5-mqtt-696x817.png 696w, https://blogit.create.pt/wp-content/uploads/2020/10/shelly-2.5-mqtt-358x420.png 358w" sizes="(max-width: 792px) 100vw, 792px" /></figure></div>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: yaml; title: ; notranslate">
# lights
light:
  - platform: mqtt
    unique_id: luz_sala_jantar_tecto
    name: &quot;Luz do tecto da sala de jantar&quot;
    state_topic: &quot;shellies/sala_tecto/relay/0&quot;
    command_topic: &quot;shellies/sala_tecto/relay/0/command&quot;
    payload_on: &#039;on&#039;
    payload_off: &#039;off&#039;
    retain: false
    qos: 1
  - platform: mqtt
    unique_id: luz_sala_estar_tecto
    name: &quot;Luz do tecto da sala de estar&quot;
    state_topic: &quot;shellies/sala_tecto/relay/1&quot;
    command_topic: &quot;shellies/sala_tecto/relay/1/command&quot;
    payload_on: &#039;on&#039;
    payload_off: &#039;off&#039;
    retain: false
    qos: 1

</pre></div>


<p>The Shelly 2.5 has temperature sensor so I&#8217;ve configured it like this</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: yaml; title: ; notranslate">
sensor:
  - platform: mqtt
    unique_id: sensor_temperatura_sala_tecto
    name: &quot;Temperatura da luz do tecto da sala&quot;
    state_topic: &quot;shellies/sala_tecto/temperature&quot;
    unit_of_measurement: &#039;ºC&#039;

</pre></div>


<p>There is a power sensor so check the configuration here </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
sensor:
  - platform: mqtt
    unique_id: sensor_potencia_sala_jantar_tecto
    name: &quot;Potência da luz do tecto da sala de jantar&quot;
    state_topic: &quot;shellies/sala_tecto/relay/0/power&quot;
    unit_of_measurement: &#039;W&#039;

</pre></div>


<p>And for the energy sensor, this is the way I&#8217;ve set it up. </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: yaml; title: ; notranslate">
sensor
  - platform: mqtt
    unique_id: sensor_energia_sala_jantar_tecto
    name: &quot;Energia da luz do tecto da sala de jantar&quot;
    state_topic: &quot;shellies/sala_tecto/relay/0/energy&quot;
    unit_of_measurement: &#039;Wh&#039;

</pre></div>


<p>And I&#8217;ve used a binary sensor for the the temperature alert. </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: yaml; title: ; notranslate">
binary_sensor:
  - platform: mqtt
    unique_id: alerta_temperatura_luz_sala_tecto
    name: &quot;Alerta de temperatura da luz do tecto da sala&quot;
    state_topic: &quot;shellies/sala_tecto/overtemperature&quot;
    device_class: &quot;heat&quot;
    payload_off: &quot;0&quot;
    payload_on: &quot;1&quot;
</pre></div>


<p>If you want you can check the Shelly 2.5 specification here at the official Selly <a href="https://shelly.cloud/products/shelly-25-smart-home-automation-relay/" target="_blank" rel="noreferrer noopener">website</a>.</p>



<p>And I&#8217;m a <a href="https://www.mauser.pt">Mauser.pt</a> store fan so go check the site. </p>
<p>The post <a href="https://blogit.create.pt/ricardocosta/2020/10/20/home-assistant-with-shelly-2-5-switch-the-easy-way/">Home Assistant with Shelly 2.5 switch the easy way</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/ricardocosta/2020/10/20/home-assistant-with-shelly-2-5-switch-the-easy-way/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>IoT: Raspberry Pi2 and Azure Event Hubs and Mono and SQL Database–experiences</title>
		<link>https://blogit.create.pt/jota/2015/06/26/iot-raspberry-pi2-and-azure-event-hubs-and-mono-and-sql-databaseexperiences/</link>
					<comments>https://blogit.create.pt/jota/2015/06/26/iot-raspberry-pi2-and-azure-event-hubs-and-mono-and-sql-databaseexperiences/#comments</comments>
		
		<dc:creator><![CDATA[Jota]]></dc:creator>
		<pubDate>Fri, 26 Jun 2015 12:46:40 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[IoT]]></category>
		<category><![CDATA[Microsoft Azure]]></category>
		<category><![CDATA[azure]]></category>
		<category><![CDATA[iot]]></category>
		<category><![CDATA[mono]]></category>
		<category><![CDATA[raspberry pi]]></category>
		<guid isPermaLink="false">http://blogit.create.pt/joaomartins/?p=5161</guid>

					<description><![CDATA[<p>A couple of months ago I bought a Pi2 , to complement the Pi1 I use mostly as a media center. I also bought modmypi’s Raspberry Pi YouTube Workshop Kit, a pack that includes a breadboard, cables, a set of sensors, and that pairs with a set of Tutorial videos on how to set it [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/jota/2015/06/26/iot-raspberry-pi2-and-azure-event-hubs-and-mono-and-sql-databaseexperiences/">IoT: Raspberry Pi2 and Azure Event Hubs and Mono and SQL Database–experiences</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>A couple of months ago I bought a Pi2 , to complement the Pi1 I use mostly as a media center. I also bought modmypi’s <a href="http://www.modmypi.com/raspberry-pi/set-up-kits/project-kits/raspberry-pi-youtube-workshop-kit/?search=youtube" target="_blank">Raspberry Pi YouTube Workshop Kit</a>, a pack that includes a breadboard, cables, a set of sensors, and that pairs with a set of Tutorial videos on how to set it up. The tutorials are all done using Python, but my goal was (obviously) to do the same using .Net/Mono on raspian.</p>
<p>Using an approach and code that initially was similar for example to Jan Tielens’ in his <a href="http://Raspberry Pi + GPIOs with DS18B20 + Azure + C# = Internet Thermometer" target="_blank">“Raspberry Pi + GPIOs with DS18B20 + Azure + C# = Internet Thermometer”</a> article, and which I’ll describe in a later post, I now have my Pi2 sending temperature readings to an Azure Event Hub using REST, from where it is read by Azure Stream Analytics and then dropped into an Azure SQL Database. I still hope to wire this up to PowerBI, but there doesn’t seem to be a way at the moment to connect my MSDN Azure account with my corporate account where we have 100 PowerBI licenses, so that will have to wait.</p>
<p>What I wanted to share for now are some tips regarding the process, which are not described elsewhere in other articles I read on the net, and which I guess are very specific to the IoT/sensor world (to which I am new). Keep in mind that my simple goal was to have the Pi2 send temperature readings to Azure every minute.</p>
<p><strong>Service Bus Queue vs Event Hub</strong></p>
<p>My initial code was posting readings to an SB Queue. I didn’t antecipate using Event Hubs, since an event every minute doesn’t justify the platforms’ capabilities. Turns out that Azure Stream Analytics doesn’t support SB Queues as the source, so I had to change the connection code that posts temperature readings using REST. The changes were very few, but included:</p>
<ul>
<li>Dropping the support for custom headers, which I was injecting in the message sent to the Service Bus (example: sensor id). I had to move this information into the message payload itself;
<li>Changing the URL to which the message is posted, including the API version. To write to SB I was using <em>https://myservice.servicebus.windows.net/queuename/messages?timeout=60&amp;api-version=<strong>2015-01</strong></em> and had to change this to: <em>https://myservice.servicebus.windows.net/eventhubname/messages?timeout=60&amp;api-version=<strong>2014-05</strong></em> .</li>
</ul>
<p><strong>Reading the Temperature – closing the Stream</strong></p>
<p>The code that reads from the sensor, in Jan Tielens’ code (and other similar code found on the net), doesn’t allow for repeat readings in a loop. This line of code:</p>
<p><font face="Consolas">var w1slavetext = deviceDir.GetFiles(&#8220;w1_slave&#8221;).FirstOrDefault().OpenText().ReadToEnd();</font></p>
<p>… actually leaves a text stream open (StreamReader class), that has to be closed for repeat readings to work. So that was another fix.</p>
<p><strong>The main loop – time between readings</strong></p>
<p>My application is simple console application implementing a <font face="Consolas">while(true)</font> loop, that does this:</p>
<ul>
<li>Read a temperature value from the sensor
<li>Send a message to an Event Hub, by doing an HTTP post of a JSON-serialized message
<li>Wait for 60 seconds with Thread.Sleep</li>
</ul>
<p>One thing I noticed was that the readings were spaced, not 60 seconds, but 60+something. This “something”, usually 2-3 seconds, were obviously caused by the time the first two steps took. So to fix this I created a <font face="Consolas">System.Diagnostics.Stopwatch</font> at the start of the main loop, and at its end waited for 60 seconds minus the time it took for the first 2 operations to execute.</p>
<p>Now the readings were close enough (to a few milliseconds) to one every minute. Simple fix, simple mistake to make.</p>
<p><strong>The main loop – long operations</strong></p>
<p>The previous solution has a problem, which I quickly found out about. After running for a few hours, I had some posts to the Event Hubs that took a long time. More than 60 seconds. Maybe the cause was some Wifi problem, or network issue, don’t know. But what this meant was that I was calling <font face="Consolas">Thread.Sleep</font> with a negative value, which crashed the app. So another fix: if the operations took more than 60 seconds, don’t sleep and do another temperature reading immediately.</p>
<p><strong>The main loop – SHA tokens’ lifetime</strong></p>
<p>At the top of the app, before the main loop, the first thing I do is to create a SHA token used to connect to the event hub. This token has a lifetime, which I think is one hour by default. So, as you can expect: after one hour of reading temperature (60 readings), the SHA token expired, and sending the message failed with a 401 (permission denied), and I had an exception that stopped the app. Back to the code, another simple fix: wrap the sending of the message to the eventhub (which uses the <font face="Consolas">WebClient</font> class) with a try/catch, and when I find a <font face="Consolas">WebException</font> with 401 as the error code, recreate the SHA token and send the message again.</p>
<p><strong>The main loop – the all encompassing try-catch</strong></p>
<p>The last fix I did after I started having unhandled exceptions which I am not sure are due to the Pi2, Mono, network, whatever: I just wrapped the code inside the main loop inside a general try-catch, logged any error to the console output, and continue the loop execution. A “just in case” solution.</p>
<p><strong>Finally, getting information about the device</strong></p>
<p>This is not specific to the handing of the readings themselves, but I think is relevant. In the payload of my messages I wanted to include some information specific to the device, and found out I could find this information by reading from some devices/streams provided by the Raspian OS. I dug into some samples in the net, and ended up doing code that gets both the serial and the model name. The OS calls I do, using the <font face="Consolas">Process/ProcessStartInfo</font> classes as a way to get into <font face="Consolas">bash</font> are:</p>
<p><font face="Consolas">cat /proc/cpuinfo | grep Serial | awk &#8216;{print $3}&#8217;&nbsp;&nbsp; &#8212; this gets you the device’s serial, for example “00000000f5b55a06”</font></p>
<p><font face="Consolas">cat /proc/cpuinfo | grep &#8216;model name&#8217; | head -n 1 – this gets you a string from where you can extract the model name, for example “ARMv7 Processor rev 5 (v7l)”</font></p>
<p>&nbsp;</p>
<p>I’m still cleaning up the code and making sure it’s stable, but I’ll post it to github pretty soon. Contact me if want to see it sooner. Anyway, what I did already realize is that the colder time of the day, in my place at least, is between 22:00 and 02:00, which surprised me, and the temperature variation is about 4 Celcius on average.&nbsp; Interesting info!</p>
<p>The post <a href="https://blogit.create.pt/jota/2015/06/26/iot-raspberry-pi2-and-azure-event-hubs-and-mono-and-sql-databaseexperiences/">IoT: Raspberry Pi2 and Azure Event Hubs and Mono and SQL Database–experiences</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/jota/2015/06/26/iot-raspberry-pi2-and-azure-event-hubs-and-mono-and-sql-databaseexperiences/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
