<?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>IoTHubTrigger &#8211; Sibeesh Passion</title>
	<atom:link href="https://sibeeshpassion.com/tag/iothubtrigger/feed/" rel="self" type="application/rss+xml" />
	<link>https://sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Fri, 11 Jan 2019 09:40:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>IoTHubTrigger &#8211; Sibeesh Passion</title>
	<link>https://sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>IoTHubTrigger Azure Function and Azure IoT Hub</title>
		<link>https://sibeeshpassion.com/iothubtrigger-azure-function-and-azure-iot-hub/</link>
					<comments>https://sibeeshpassion.com/iothubtrigger-azure-function-and-azure-iot-hub/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Thu, 27 Dec 2018 11:47:52 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[IoT]]></category>
		<category><![CDATA[Azure Function]]></category>
		<category><![CDATA[Azure IoT]]></category>
		<category><![CDATA[codeproject]]></category>
		<category><![CDATA[IoT Hub]]></category>
		<category><![CDATA[IoTHubTrigger]]></category>
		<category><![CDATA[MXChip]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13494</guid>

					<description><![CDATA[[toc] Introduction For the past few days I am playing with my MXChip and had written some articles about the same, you should be able to find those here. Here in this article, we will send some data to our Azure IoT hub and we will connect an Azure Function with our IoT Hub using IoTHubTrigger Event Hub Trigger Attribute. If you are ready, let&#8217;s do this. Background As I said this article is part of my IoT article series, so if you have read my previous articles on this topic, it may be easier for you to understand the [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



<h2 class="wp-block-heading">Introduction</h2>



<p>For the past few days I am playing with my MXChip and had written some articles about the same, you should be able to find those <a href="https://sibeeshpassion.com/category/iot/">here</a>. Here in this article, we will send some data to our Azure IoT hub and we will connect an Azure Function with our IoT Hub using IoTHubTrigger Event Hub  Trigger Attribute. If you are ready, let&#8217;s do this. </p>



<h2 class="wp-block-heading">Background</h2>



<p>As I said this article is part of my IoT article series, so if you have read my previous articles on this topic, it may be easier for you to understand the concept. Before you start this article, please make sure that you had already created an Azure IoT hub and it is running. You can always send the messages to this IoT Hub either by connecting the actual device, let&#8217;s say an MXChip or using a simulating device.</p>



<h2 class="wp-block-heading">IoTHubTrigger Demo</h2>



<h3 class="wp-block-heading">Creating an Azure Function App</h3>



<p>I am going to create an Azure Function App in Visual Studio, if you are not sure about how we can create and publish the Azure Function, please read <a href="https://sibeeshpassion.com/azure-function-as-output-job-topology-of-an-azure-stream-analytics-job/#play-with-azure-function">this section</a> of my previous article. Let&#8217;s create a new solution now. </p>



<figure class="wp-block-image"><img fetchpriority="high" decoding="async" width="650" height="375" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/IoTHubTrigger.jpg" alt="" class="wp-image-13495" srcset="/wp-content/uploads/2018/12/IoTHubTrigger.jpg 650w, /wp-content/uploads/2018/12/IoTHubTrigger-300x173.jpg 300w, /wp-content/uploads/2018/12/IoTHubTrigger-400x231.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>IoTHubTrigger</figcaption></figure>



<p>Once you click OK, a new Azure Function will be generated for you with some initial codes in it. Let&#8217;s edit the Function as below.</p>



<pre class="wp-block-code"><code>using Microsoft.Azure.EventHubs;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using System.Text;
using IoTHubTrigger = Microsoft.Azure.WebJobs.EventHubTriggerAttribute;

namespace IoTHubTrigger_Azure_Function_and_Azure_IoT_Hub
{
    public static class IoTHubFunc
    {
        [FunctionName("IoTHubData")]
        public static void Run(
            [IoTHubTrigger("messages/events", Connection = "IoTHubTriggerConnection", ConsumerGroup ="FuncGroup")]EventData message, 
            ILogger log)
        {
            log.LogInformation($"C# IoT Hub trigger function processed a message: {Encoding.UTF8.GetString(message.Body.Array)}");
        }
    }
}</code></pre>



<p>Here the IoTHubTriggerConnection is the connection string we are providing in the local.settings.json file. The consumer group will come into the play if you have many applications which need to be receiving the data from your IoT Hub. Below is the class definition of EventHubTriggerAttribute.</p>



<pre class="wp-block-code"><code>public sealed class EventHubTriggerAttribute : Attribute
    {
        public EventHubTriggerAttribute(string eventHubName);

        public string EventHubName { get; }
        public string ConsumerGroup { get; set; }
        public string Connection { get; set; }
    }</code></pre>



<h3 class="wp-block-heading">Send data to the Azure IoT Hub</h3>



<p>As I mentioned earlier, there are two ways you can send the data to the Azure IoT Hub.</p>



<ol class="wp-block-list"><li>Using a device, for example, MXChip </li><li><a href="https://sibeeshpassion.com/an-introduction-to-azure-stream-analytics-job/#run-the-stream-analytics-job-and-see-the-data-in-the-database">Simulated device</a></li></ol>



<p>Once the data is been sending, you can see the message received count in Azure IoT Hub in the overview section. </p>



<h3 class="wp-block-heading">Run the Azure Function</h3>



<p>So, the IoT Hub is started receiving the messages from the device, and now we can use our Azure Function to pull the data from the IoT hub with the help of IoT hub Trigger. Run your Function App, Simulated Device application and see the output. </p>



<figure class="wp-block-image"><img decoding="async" width="650" height="484" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/IoTHubTrigger-Demo-WIth-Simulated-App.jpg" alt="" class="wp-image-13496" srcset="/wp-content/uploads/2018/12/IoTHubTrigger-Demo-WIth-Simulated-App.jpg 650w, /wp-content/uploads/2018/12/IoTHubTrigger-Demo-WIth-Simulated-App-300x223.jpg 300w, /wp-content/uploads/2018/12/IoTHubTrigger-Demo-WIth-Simulated-App-400x298.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>IoT Hub Trigger Output </figcaption></figure>



<p>As you can see in the output, our Azure Function app is receiving the data from Azure IoT hub instantly. Now you can perform any actions with this data. I will leave that to you.</p>



<h2 class="wp-block-heading">Conclusion</h2>



<p>Wow!. Now we have learned,</p>



<ul class="wp-block-list"><li>Usage of Azure IoT Hub Trigger in Azure Function</li><li>Creating Azure Function App</li><li>See the Data from Azure IoT Hub in the Azure Function App</li></ul>



<p>You can always ready my IoT articles&nbsp;<a href="https://sibeeshpassion.com/category/iot/">here</a>.</p>



<h2 class="wp-block-heading">Your turn. What do you think?</h2>



<p>Thanks a lot for reading. Did I miss anything that you may think which is needed in this article? Could you find this post as useful? Kindly do not forget to share me your feedback.</p>



<p>Kindest Regards<br>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/iothubtrigger-azure-function-and-azure-iot-hub/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
