<?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 &#8211; Sibeesh Passion</title>
	<atom:link href="https://www.sibeeshpassion.com/category/iot/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Sun, 11 Aug 2019 19:30:09 +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>IoT &#8211; Sibeesh Passion</title>
	<link>https://www.sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Raspberry Pi 4, What is There for You, Worth Buying?</title>
		<link>https://www.sibeeshpassion.com/raspberry-pi-4-what-is-there-for-you-worth-buying-it/</link>
					<comments>https://www.sibeeshpassion.com/raspberry-pi-4-what-is-there-for-you-worth-buying-it/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Sun, 11 Aug 2019 19:10:52 +0000</pubDate>
				<category><![CDATA[IoT]]></category>
		<category><![CDATA[Connected Devices]]></category>
		<category><![CDATA[Internet of Things]]></category>
		<category><![CDATA[Raspberry PI]]></category>
		<category><![CDATA[Raspberry Pi 4]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13873</guid>

					<description><![CDATA[I bought a Raspberry Pi 4 recently and in this video I will explain the key features about the device and I will also show how you can set up your Raspberry Pi 4 for the first time. We will look at the the box together and unbox the same. I hope you will like this video. Your turn. What do you think? Thanks a lot for watching the video. Did I miss anything that you may think which is needed in this video? Could you find this post as useful? Kindly do not forget to share me your feedback [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>I bought a Raspberry Pi 4 recently and in this video I will explain the key features about the device and I will also show how you can set up your Raspberry Pi 4 for the first time. We will look at the the box together and unbox the same. I hope you will like this video. </p>



<figure><iframe width="560" height="315" src="https://www.youtube.com/embed/gCEUITJL_G8" allowfullscreen=""></iframe></figure>



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



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



<p>Kindest Regards<br>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/raspberry-pi-4-what-is-there-for-you-worth-buying-it/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Detect Noise Level Audio Decibels in MXChip Azure IoT DevKit</title>
		<link>https://www.sibeeshpassion.com/detect-noise-level-audio-decibels-in-mxchip-azure-iot-devkit/</link>
					<comments>https://www.sibeeshpassion.com/detect-noise-level-audio-decibels-in-mxchip-azure-iot-devkit/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 14 Jan 2019 10:02:13 +0000</pubDate>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[IoT]]></category>
		<category><![CDATA[AudioClassV2]]></category>
		<category><![CDATA[AZ3166]]></category>
		<category><![CDATA[Azure IoT]]></category>
		<category><![CDATA[Calculate Decibels]]></category>
		<category><![CDATA[IoT Hub]]></category>
		<category><![CDATA[MXChip]]></category>
		<category><![CDATA[Noise Level Detector]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13546</guid>

					<description><![CDATA[[toc] Introduction Playing with Azure IoT DevKit MXChip is always fun, the device has many capabilities. For the past few days, I have been working with some of the capabilities of this device like Atmospheric pressure, Temperature, Humidity through its Sensors. In this Article, I will show you how you can calculate the noise level using the microphone of AZ3166&#160;IoT Device. Now let&#8217;s start implementing the same. I hope you will like it. Background In our last article, we have already seen how to read the temperature, humidity, atmospheric pressure from the MXChip AZ3166 sensors and send those to our [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



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



<p>Playing with Azure IoT DevKit MXChip is always fun, the device has many capabilities. For the past few days, I have been working with some of the capabilities of this device like Atmospheric pressure, Temperature, Humidity through its Sensors. In this Article, I will show you how you can calculate the noise level using the microphone of  AZ3166&nbsp;IoT Device. Now let&#8217;s start implementing the same. I hope you will like it.</p>



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



<p>In our last article, we have already seen <a href="https://sibeeshpassion.com/mxchip-device-with-pressure-humidity-temperature-info-using-azure-iot-workbench/">how to read the temperature, humidity, atmospheric pressure from the MXChip AZ3166 sensors and send those to our Azure IoT Hub.</a> Here in this article let&#8217;s do the following tasks.</p>



<ol class="wp-block-list"><li>Find the Noise level using the AudioClassV2 class </li><li>Send the Values to our IoT Hub</li></ol>



<h2 class="wp-block-heading">Source Code</h2>



<p>Please feel free to play around with <a href="https://github.com/SibeeshVenu/MXChip-Azure-IoT-Arduino">this repository</a>.</p>



<h2 class="wp-block-heading">Using the Code</h2>



<p>Once you have your own work space, we can open the solution in VSCode and start coding.  </p>



<h3 class="wp-block-heading">main.ino</h3>



<p>This is our solution starting point, every project must have its own sketch file, usually this file will be containing at least the functions  loop() and setup(). </p>



<p>Before we get started, let&#8217;s include the header files we are going to use.</p>



<script src="https://gist.github.com/SibeeshVenu/24082ec5b1c605ce0adf6bb851da0e68.js"></script>



<p>Now we can declare our constants and variables.</p>



<script src="https://gist.github.com/SibeeshVenu/988b564861b20768e0b124337663fa25.js"></script>



<p>Now we can add the codes for the configuration, usually, you wouldn&#8217;t have to edit any codes in this section. </p>



<script src="https://gist.github.com/SibeeshVenu/6529a57c8c43dc27e3b8df77b0e849fc.js"></script>



<p>As I mentioned earlier, every INO file will have its own setup() and loop() function. We can modify our setup() function as below. </p>



<script src="https://gist.github.com/SibeeshVenu/bbad6e7fba9f55aa9b8e8212b493f03c.js"></script>



<p>The function loop() will be called each 5 seconds, as I had set the INTERVAL as 5000 milliseconds. </p>



<script src="https://gist.github.com/SibeeshVenu/3351fe05a571eefba9d6b4821abb3aa4.js"></script>



<p>Now we can edit our code of loop() function as below. </p>



<script src="https://gist.github.com/SibeeshVenu/aca2ff9d475dd9a7ec9817eb3f073cb2.js"></script>



<h3 class="wp-block-heading">utility.cpp</h3>



<p>As you can see, once we get the values from the function get_prediction (), we are passing the decibels values to our setMessage() function, which we have defined in the file utility.cpp. Inside the setMessage () function, we will add the decibels value to JSON object using the function  json_object_set_number (). </p>



<script src="https://gist.github.com/SibeeshVenu/1b8f34a42d8a9dd2ca61e1af45b949f5.js"></script>



<p>You should also add the files featurizer.h and featurizer.s to get it working. You can get those files from the source code repository mentioned above. </p>



<h2 class="wp-block-heading">Compile and Upload to the Device</h2>



<p>As we have already made the needed changes, it is time to compile the Device solution and upload the same to our Device. Press F1 and select Azure IoT Device Workbench: Compile Device Code. If you ever get an error as &#8220;error: utility.h: No such file or directory&#8221;, please compile the device code again. If you are facing any unexpected errors, please delete the &#8220;.build&#8221; folder and compile again.</p>



<p>Once you get a message as &#8221; [Done] Finished verify sketch &#8211; Main.ino &#8221; in your Output window, you can upload the solution to your device. To do so, press F1 again, and select &#8221; Azure IoT Device Workbench: Upload Device Code&#8221;. Please make sure that the device is been connected to your machine. If everything goes well, you will be getting a message as &#8221; [Done] Uploaded the sketch: Main.ino&#8221;. </p>



<p>Please remember to see the GitHub repository for the full code.</p>



<h2 class="wp-block-heading">Device to Cloud Messages</h2>



<p>Now your device will be sending the Decibels data to the <a href="https://sibeeshpassion.com/category/azure">Azure</a> IoT Hub. Let&#8217;s see that in the D2C Monitoring window. </p>



<figure class="wp-block-image"><img fetchpriority="high" decoding="async" width="650" height="350" src="https://sibeeshpassion.com/wp-content/uploads/2019/01/Send-MXChip-Data-to-Cloud.gif" alt="" class="wp-image-13555"/><figcaption>Send MXChip Data to Cloud</figcaption></figure>



<script src="https://gist.github.com/SibeeshVenu/54159143c4d141808602f38b82314422.js"></script>



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



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



<ul class="wp-block-list"><li>How to detect the noise level in MXChip</li><li>How to use AudioClassV2 </li><li>How to send device data to the Azure IoT Hub</li></ul>



<p>Please consider reading my IoT articles&nbsp;<a href="https://sibeeshpassion.com/category/iot/">here</a>&nbsp;for the continuation.</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://www.sibeeshpassion.com/detect-noise-level-audio-decibels-in-mxchip-azure-iot-devkit/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>MXChip Device with Pressure, Humidity, Temperature Info using Azure IoT Workbench</title>
		<link>https://www.sibeeshpassion.com/mxchip-device-with-pressure-humidity-temperature-info-using-azure-iot-workbench/</link>
					<comments>https://www.sibeeshpassion.com/mxchip-device-with-pressure-humidity-temperature-info-using-azure-iot-workbench/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Fri, 04 Jan 2019 10:40:52 +0000</pubDate>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[IoT]]></category>
		<category><![CDATA[Azure IoT]]></category>
		<category><![CDATA[Device to Cloud]]></category>
		<category><![CDATA[IoT Hub]]></category>
		<category><![CDATA[Microcontroller]]></category>
		<category><![CDATA[MXChip]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13520</guid>

					<description><![CDATA[[toc] Introduction I have got my MXChip a few days ago, and I have been playing with the same. Here in this article, we will see how we can set up our MXChip and get it working to send Temperature, Humidity, Pressure etc information to our Azure IoT Hub. Once we have received the data in our Azure IoT Hub we can do anything with that, I have already written some articles on the same topic, you can read them here. Let&#8217;s configure our IoT device now. Background The MXChip is a microcontroller with a bunch of sensors in it, [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



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



<p>I have got my <a href="https://sibeeshpassion.com/tag/mxchip/">MXChip</a> a few days ago, and I have been playing with the same. Here in this article, we will see how we can set up our MXChip and get it working to send Temperature, Humidity, Pressure etc information to our Azure IoT Hub. Once we have received the data in our Azure IoT Hub we can do anything with that, I have already written some articles on the same topic, you can read them <a href="https://sibeeshpassion.com/category/iot/">here</a>. Let&#8217;s configure our IoT device now. </p>



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



<p>The MXChip is a microcontroller with a bunch of sensors in it, the main advantage of this device is it is connected to Azure, which made the device to cloud and cloud to device transmission easier than ever. Here in this article, we will configure this device with the help of a tool/extension called Azure IoT Workbench in Visual Studio code. Once we are done configuring, we can change the CPP code to send the pressure information from the pressure sensor to the Azure IoT Hub. </p>



<h2 class="wp-block-heading">Source Code</h2>



<p>Please feel free to play with this repository <a href="https://github.com/SibeeshVenu/MXChip-Azure-IoT-Arduino">here</a>.</p>



<h2 class="wp-block-heading">Set Up the System</h2>



<p>Before we get started developing our device application/code, we need to set our environment first. So, please make sure that you are following this article and <a href="https://microsoft.github.io/azure-iot-developer-kit/docs/get-started/">configure your Getting started <g class="gr_ gr_4 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins doubleReplace replaceWithoutSep" id="4" data-gr-id="4">project</g></a>.</p>



<h2 class="wp-block-heading">Using the Code</h2>



<p>Once you are able to see the D2C (Device to Cloud) and C2D (Cloud to Device) data, we are good to go and write some code to get the Pressure information from the Pressure Sensor (LPS22HB).</p>



<p>If you open the Device code, from the Getting started tutorial, which got generated using the Azure IoT Workbench tool. You can see the files as below. </p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="752" height="812" src="https://sibeeshpassion.com/wp-content/uploads/2019/01/Azure-IoT-Workbench-Workspace-Files.jpg" alt="" class="wp-image-13526" srcset="/wp-content/uploads/2019/01/Azure-IoT-Workbench-Workspace-Files.jpg 752w, /wp-content/uploads/2019/01/Azure-IoT-Workbench-Workspace-Files-278x300.jpg 278w, /wp-content/uploads/2019/01/Azure-IoT-Workbench-Workspace-Files-400x432.jpg 400w, /wp-content/uploads/2019/01/Azure-IoT-Workbench-Workspace-Files-556x600.jpg 556w" sizes="(max-width: 752px) 100vw, 752px" /><figcaption>Azure IoT Workbench Workspace Files</figcaption></figure></div>



<p>Here, the file azureconfig.json has the connection string information to your IoT Hub, Event Hub.</p>



<pre class="wp-block-code"><code>{
    "componentConfigs": [
        {
            "id": "e8d86334-156d-e40b-9618-a6a54bb94b25",
            "folder": "",
            "name": "",
            "dependencies": [],
            "type": "IoTHub",
            "componentInfo": {
                "values": {
                    "iotHubConnectionString": "",
                    "eventHubConnectionString": "",
                    "eventHubConnectionPath": ""
                }
            }
        }
    ]
}</code></pre>



<p>The file project.code-workspace will have your Device code settings, including the Device path. Usually you wouldn&#8217;t need to check these files, as these values are automatically created when you are doing the provisioning  as mentioned in the Get started tutorial. </p>



<p>The folder Device will have your Arduino code, here we are writing the codes in CPP (C++). If you open the solution in Visual Studio code, it will ask you open the work space, which is nothing but our Device code. Just click on Open Workspace, then we can start coding.</p>



<p>The Config.h file is our configuration file.</p>



<pre class="wp-block-code"><code>#define INTERVAL 2000

#define MESSAGE_MAX_LEN 256

#define TEMPERATURE_ALERT 30</code></pre>



<p>The GetStarted.ino file contains the code for initial set up, that is, to make the device run. It contains the code for WiFi configuration, and Device to Cloud, Cloud to Device communication etc. Below is the sample code. </p>



<pre class="wp-block-code"><code>// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. 
// To get started please visit https://microsoft.github.io/azure-iot-developer-kit/docs/projects/connect-iot-hub?utm_source=ArduinoExtension&amp;utm_medium=ReleaseNote&amp;utm_campaign=VSCode
#include "AZ3166WiFi.h"
#include "AzureIotHub.h"
#include "DevKitMQTTClient.h"

#include "config.h"
#include "utility.h"
#include "SystemTickCounter.h"

static bool hasWifi = false;
int messageCount = 1;
static bool messageSending = true;
static uint64_t send_interval_ms;

//////////////////////////////////////////////////////////////////////////////////////////////////////////
// Utilities
static void InitWifi()
{
  Screen.print(2, "Connecting...");
  
  if (WiFi.begin() == WL_CONNECTED)
  {
    IPAddress ip = WiFi.localIP();
    Screen.print(1, ip.get_address());
    hasWifi = true;
    Screen.print(2, "Running... \r\n");
  }
  else
  {
    hasWifi = false;
    Screen.print(1, "No Wi-Fi\r\n ");
  }
}

static void SendConfirmationCallback(IOTHUB_CLIENT_CONFIRMATION_RESULT result)
{
  if (result == IOTHUB_CLIENT_CONFIRMATION_OK)
  {
    blinkSendConfirmation();
  }
}

static void MessageCallback(const char* payLoad, int size)
{
  blinkLED();
  Screen.print(1, payLoad, true);
}

static void DeviceTwinCallback(DEVICE_TWIN_UPDATE_STATE updateState, const unsigned char *payLoad, int size)
{
  char *temp = (char *)malloc(size + 1);
  if (temp == NULL)
  {
    return;
  }
  memcpy(temp, payLoad, size);
  temp[size] = '\0';
  parseTwinMessage(updateState, temp);
  free(temp);
}

static int  DeviceMethodCallback(const char *methodName, const unsigned char *payload, int size, unsigned char **response, int *response_size)
{
  LogInfo("Try to invoke method %s", methodName);
  const char *responseMessage = "\"Successfully invoke device method\"";
  int result = 200;

  if (strcmp(methodName, "start") == 0)
  {
    LogInfo("Start sending temperature and humidity data");
    messageSending = true;
  }
  else if (strcmp(methodName, "stop") == 0)
  {
    LogInfo("Stop sending temperature and humidity data");
    messageSending = false;
  }
  else
  {
    LogInfo("No method %s found", methodName);
    responseMessage = "\"No method found\"";
    result = 404;
  }

  *response_size = strlen(responseMessage) + 1;
  *response = (unsigned char *)strdup(responseMessage);

  return result;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////
// Arduino sketch
void setup()
{
  Screen.init();
  Screen.print(0, "IoT DevKit");
  Screen.print(2, "Initializing...");
  
  Screen.print(3, " > Serial");
  Serial.begin(115200);

  // Initialize the WiFi module
  Screen.print(3, " > WiFi");
  hasWifi = false;
  InitWifi();
  if (!hasWifi)
  {
    return;
  }

  LogTrace("HappyPathSetup", NULL);

  Screen.print(3, " > Sensors");
  SensorInit();

  Screen.print(3, " > IoT Hub");
  DevKitMQTTClient_SetOption(OPTION_MINI_SOLUTION_NAME, "DevKit-GetStarted");
  DevKitMQTTClient_Init(true);

  DevKitMQTTClient_SetSendConfirmationCallback(SendConfirmationCallback);
  DevKitMQTTClient_SetMessageCallback(MessageCallback);
  DevKitMQTTClient_SetDeviceTwinCallback(DeviceTwinCallback);
  DevKitMQTTClient_SetDeviceMethodCallback(DeviceMethodCallback);

  send_interval_ms = SystemTickCounterRead();
}

void loop()
{
  if (hasWifi)
  {
    if (messageSending &amp;&amp; 
        (int)(SystemTickCounterRead() - send_interval_ms) >= getInterval())
    {
      // Send teperature data
      char messagePayload[MESSAGE_MAX_LEN];

      bool temperatureAlert = readMessage(messageCount++, messagePayload);
      EVENT_INSTANCE* message = DevKitMQTTClient_Event_Generate(messagePayload, MESSAGE);
      DevKitMQTTClient_Event_AddProp(message, "temperatureAlert", temperatureAlert ? "true" : "false");
      DevKitMQTTClient_SendEventInstance(message);
      
      send_interval_ms = SystemTickCounterRead();
    }
    else
    {
      DevKitMQTTClient_Check();
    }
  }
  delay(1000);
}</code></pre>



<p>Below is the content of the file utility.h.</p>



<pre class="wp-block-code"><code>#ifndef UTILITY_H
#define UTILITY_H

void parseTwinMessage(DEVICE_TWIN_UPDATE_STATE, const char *);
bool readMessage(int, char *);

void SensorInit(void);

void blinkLED(void);
void blinkSendConfirmation(void);
int getInterval(void);</code></pre>



<p>We will be defining all these functions inside the file called utility.<g class="gr_ gr_4 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="4" data-gr-id="4">cpp</g> file, and that&#8217;s where most of our codes are going to be. When you are finished the Get started the tutorial, the initial code will contain the functions which can read the temperature, humidity information from the sensor and send to the cloud. And as you have guessed, it is missing the code for reading and sending the pressure information. Here we are going to do that. Below is the initial code. </p>



<pre class="wp-block-code"><code>// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. 

#include "HTS221Sensor.h"
#include "AzureIotHub.h"
#include "Arduino.h"
#include "parson.h"
#include "config.h"
#include "RGB_LED.h"

#define RGB_LED_BRIGHTNESS 32

DevI2C *i2c;
HTS221Sensor *sensor;
static RGB_LED rgbLed;
static int interval = INTERVAL;
static float humidity;
static float temperature;

int getInterval()
{
    return interval;
}

void blinkLED()
{
    rgbLed.turnOff();
    rgbLed.setColor(RGB_LED_BRIGHTNESS, 0, 0);
    delay(500);
    rgbLed.turnOff();
}

void blinkSendConfirmation()
{
    rgbLed.turnOff();
    rgbLed.setColor(0, 0, RGB_LED_BRIGHTNESS);
    delay(500);
    rgbLed.turnOff();
}

void parseTwinMessage(DEVICE_TWIN_UPDATE_STATE updateState, const char *message)
{
    JSON_Value *root_value;
    root_value = json_parse_string(message);
    if (json_value_get_type(root_value) != JSONObject)
    {
        if (root_value != NULL)
        {
            json_value_free(root_value);
        }
        LogError("parse %s failed", message);
        return;
    }
    JSON_Object *root_object = json_value_get_object(root_value);

    double val = 0;
    if (updateState == DEVICE_TWIN_UPDATE_COMPLETE)
    {
        JSON_Object *desired_object = json_object_get_object(root_object, "desired");
        if (desired_object != NULL)
        {
            val = json_object_get_number(desired_object, "interval");
        }
    }
    else
    {
        val = json_object_get_number(root_object, "interval");
    }
    if (val > 500)
    {
        interval = (int)val;
        LogInfo(">>>Device twin updated: set interval to %d", interval);
    }
    json_value_free(root_value);
}

void SensorInit()
{
    i2c = new DevI2C(D14, D15);
    sensor = new HTS221Sensor(*i2c);
    sensor->init(NULL);

    humidity = -1;
    temperature = -1000;
}

float readTemperature()
{
    sensor->reset();

    float temperature = 0;
    sensor->getTemperature(&amp;temperature);

    return temperature;
}

float readHumidity()
{
    sensor->reset();

    float humidity = 0;
    sensor->getHumidity(&amp;humidity);

    return humidity;
}

bool readMessage(int messageId, char *payload)
{
    JSON_Value *root_value = json_value_init_object();
    JSON_Object *root_object = json_value_get_object(root_value);
    char *serialized_string = NULL;

    json_object_set_number(root_object, "messageId", messageId);

    float t = readTemperature();
    float h = readHumidity();
    bool temperatureAlert = false;
    if(t != temperature)
    {
        temperature = t;
        json_object_set_number(root_object, "temperature", temperature);
    }
    if(temperature > TEMPERATURE_ALERT)
    {
        temperatureAlert = true;
    }
    
    if(h != humidity)
    {
        humidity = h;
        json_object_set_number(root_object, "humidity", humidity);
    }
    serialized_string = json_serialize_to_string_pretty(root_value);

    snprintf(payload, MESSAGE_MAX_LEN, "%s", serialized_string);
    json_free_serialized_string(serialized_string);
    json_value_free(root_value);
    return temperatureAlert;
}</code></pre>



<p>We use different sensors for different items, thus different abstract classes for different things. For example, the abstract class HTS221Sensor is used for Humidity and Temperature, and  LPS22HBSensor sensor for pressure.</p>



<p>So let&#8217;s include the  LPS22HBSensor.</p>



<pre class="wp-block-code"><code>#include "LPS22HBSensor.h"
#include "utility.h"</code></pre>



<p>Now, create a reference of the same. </p>



<pre class="wp-block-code"><code>LPS22HBSensor *pSensor;
static float pressure;</code></pre>



<p>Modify the SensorInit() function by initializing the class LPS22HBSensor.</p>



<pre class="wp-block-code"><code>void SensorInit()
{
    i2c = new DevI2C(D14, D15);
    sensor = new HTS221Sensor(*i2c);
    sensor->init(NULL);

    pSensor = new LPS22HBSensor(*i2c);
    pSensor->init(NULL);

    humidity = -1;
    temperature = -1000;
    pressure = 0;
}</code></pre>



<p>Now, create a new function which can read the Pressure from the sensor. </p>



<pre class="wp-block-code"><code>float readPressure()
{
    float pressure = 0;
    pSensor->getPressure(&amp;pressure);

    return pressure;
}</code></pre>



<p>Now it is time to add the pressure information to the output JSON file, by using the function  json_object_set_number. Modify the function  readMessage with the following code. </p>



<pre class="wp-block-code"><code>float p = readPressure();
if (p != pressure) {
    pressure = p;
    json_object_set_number(root_object, "pressure", pressure);
}</code></pre>



<p>Now,  we have done coding for our device, and it is time to upload the code to the device. </p>



<h3 class="wp-block-heading">Upload the Code to IoT Device</h3>



<p>As we already have the IoT Workbench tool installed, it is super easy to upload the new code to the device. Press F1 in Visual Studio code and select &#8216;Azure IoT Device Workbench: Upload Device Code&#8217;. This command will compile your code, and it throws the error in the Output terminal if there are any.  It does the following actions.</p>



<ol class="wp-block-list"><li>Load the configurations</li><li>Initialize the packages</li><li>Prepare your board for the upload, the Programming LED will blink at this time</li><li>Verify everything</li><li></li></ol>



<p>If everything goes well, you should be able to see an output as below.</p>



<pre class="wp-block-code"><code>Global variables use 60920 bytes (23%) of dynamic memory, leaving 201224 bytes for local variables. Maximum is 262144 bytes.
Uploading...
Info : clock speed 1800 kHz
Info : STLINK v2 JTAG v31 API v2 SWIM v21 VID 0x0483 PID 0x374B
Info : using stlink api v2
Info : Target voltage: 3.307278
** Programming Started **
auto erase enabled
Info : device id = 0x30006441
Info : flash size = 1024kbytes
** Programming Finished **
** Verify Started **
target halted due to breakpoint, current mode: Thread 
xPSR: 0x61000000 pc: 0x2000002e msp: 0x200073fc
verified 578060 bytes in 1.120772s (503.681 KiB/s)
** Verified OK **
** Resetting Target **
shutdown command invoked
[Done] Uploaded the sketch: GetStarted.ino</code></pre>



<h3 class="wp-block-heading">Check the Device to Cloud Messages</h3>



<p>Now, it is time to check the information we are passing to our Azure IoT Hub. Go to Azure IoT Hub Devices section in Visual Studio Code, and right-click on the device and select &#8216;Start Monitoring Device to Cloud (D2C) Message&#8217;</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="455" height="456" src="https://sibeeshpassion.com/wp-content/uploads/2019/01/Start-Monitoring-Device-to-Cloud-D2C-Message.jpg" alt="" class="wp-image-13527" srcset="/wp-content/uploads/2019/01/Start-Monitoring-Device-to-Cloud-D2C-Message.jpg 455w, /wp-content/uploads/2019/01/Start-Monitoring-Device-to-Cloud-D2C-Message-150x150.jpg 150w, /wp-content/uploads/2019/01/Start-Monitoring-Device-to-Cloud-D2C-Message-300x300.jpg 300w, /wp-content/uploads/2019/01/Start-Monitoring-Device-to-Cloud-D2C-Message-130x130.jpg 130w, /wp-content/uploads/2019/01/Start-Monitoring-Device-to-Cloud-D2C-Message-400x401.jpg 400w" sizes="(max-width: 455px) 100vw, 455px" /><figcaption>Start Monitoring Device to Cloud (D2C) Message</figcaption></figure></div>



<p>A new Output Terminal will get opened, where you can see the data we send to cloud. </p>



<figure class="wp-block-image"><img decoding="async" width="580" height="312" src="https://sibeeshpassion.com/wp-content/uploads/2019/01/Send-Temperature-Humidity-Pressure-from-MXChip-Output.gif" alt="Send Temperature, Humidity, Pressure from MXChip Output" class="wp-image-13528"/><figcaption>Send Temperature, Humidity, Pressure from MXChip Output</figcaption></figure>



<pre class="wp-block-code"><code>[IoTHubMonitor] Start monitoring D2C message for [ml-pf] ...
[IoTHubMonitor] Created partition receiver [0] for consumerGroup [$Default]
[IoTHubMonitor] Created partition receiver [1] for consumerGroup [$Default]
[IoTHubMonitor] Created partition receiver [2] for consumerGroup [$Default]
[IoTHubMonitor] Created partition receiver [3] for consumerGroup [$Default]
[IoTHubMonitor] [11:16:45 AM] Message received from [ml-pf]:
{
  "body": {
    "messageId": 198,
    "temperature": 28,
    "pressure": 1007.074707
  },
  "applicationProperties": {
    "temperatureAlert": "false"
  }
}</code></pre>



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



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



<ul class="wp-block-list"><li>How to use IoT Workbench tool in Visual Studio Code</li><li>How to set up your MXChip device</li><li>How to write C++ code for Arduino</li><li>How to get the Pressure information from the sensor</li><li>How to upload the new code to MXChip device</li><li>How to perform the Device to Cloud message output.</li></ul>



<p>Please consider reading my IoT articles <a href="https://sibeeshpassion.com/category/iot/">here</a> for the continuation. </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://www.sibeeshpassion.com/mxchip-device-with-pressure-humidity-temperature-info-using-azure-iot-workbench/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Realtime IoT Data using Azure SignalR and Functions in Angular</title>
		<link>https://www.sibeeshpassion.com/realtime-iot-data-using-azure-signalr-and-functions-in-angular/</link>
					<comments>https://www.sibeeshpassion.com/realtime-iot-data-using-azure-signalr-and-functions-in-angular/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 31 Dec 2018 21:04:26 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[IoT]]></category>
		<category><![CDATA[Azure Function]]></category>
		<category><![CDATA[Azure IoT]]></category>
		<category><![CDATA[Http Trigger]]></category>
		<category><![CDATA[IoT Dev Kit]]></category>
		<category><![CDATA[IoT Hub]]></category>
		<category><![CDATA[IoT Hub Trigger]]></category>
		<category><![CDATA[MXChip]]></category>
		<category><![CDATA[Serverless]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13498</guid>

					<description><![CDATA[[toc] Introduction The data coming from the IoT devices are to be shown in real time, if we failed to do that, then there is no point in showing it. Here in this article, we will see how we can show the real-time data from our IoT device in an Angular application using Azure SignalR service and Azure Functions. Sounds interesting? So the flow of data can be defined as IoT device -&#62; Azure IoT Hub -&#62; Azure Function -&#62; Azure SignalR Service -&#62; Angular application. Sounds interesting? Let&#8217;s start then. Background In our previous article, we have already created [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



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



<p>The data coming from the <a href="https://sibeeshpassion.com/category/iot/">IoT</a> devices are to be shown in real time, if we failed to do that, then there is no point in showing it. Here in this article, we will see how we can show the real-time data from our IoT device in an Angular application using Azure SignalR service and Azure Functions. Sounds interesting? So the flow of data can be defined as IoT device -&gt; Azure IoT Hub -&gt; Azure Function -&gt; Azure SignalR Service -&gt; Angular application. Sounds interesting? Let&#8217;s start then.</p>



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



<p> In our previous article, we have already created an <a href="https://sibeeshpassion.com/iothubtrigger-azure-function-and-azure-iot-hub/">Azure Function which pulls the Data from our IoT Hub</a> whenever there is any new messages/events happening. If you have not read the same, please read it. </p>



<h2 class="wp-block-heading">Source Code</h2>



<p>Please feel free to fork, clone this project from GitHub here: <strong><a href="https://github.com/SibeeshVenu/Realtime-IoT-Device-Data-using-Azure-SignalR-and-Azure-Function-in-Angular">Realtime-IoT-Device-Data-using-Azure-SignalR-and-Azure-Function-in-Angular</a></strong></p>



<h2 class="wp-block-heading">Real-time IoT Data Processing</h2>



<p>We will be creating two solutions, one for Angular application and one for Azure Functions. We will also create a new Azure Signal R service in the Azure portal. </p>



<h3 class="wp-block-heading">Azure SignalR Service</h3>



<p>According to Microsoft,  Azure SignalR Service is an Azure managed PaaS service to simplify the development, deployment, and management of real-time web application using SignalR, with Azure supported SLA, scaling, performance, and security. The service provides API/SDK/CLI/UI, and the <g class="gr_ gr_5 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins doubleReplace replaceWithoutSep" id="5" data-gr-id="5">rich</g> set of code samples, templates, and demo applications.</p>



<p>Core features for Azure SignalR Service:</p>



<ul class="wp-block-list"><li>Native ASP.NET Core SignalR development support</li><li>ASP.NET Core SignalR backend for improved performance and stability</li><li>Redis based backplane scaling</li><li>Web Socket, comet, and .NET Server-Sent-Event support</li><li>REST API support for server broadcast scenarios</li><li>Resource Provider support for ARM Template based CLI</li><li>Dashboard for performance and connection monitoring</li><li>Token-based AUTH model</li></ul>



<p> Let&#8217;s log in to our Azure portal and create a new Azure Signal R service. Click on the +Create a resource and search SignalR Service.  Once you have created the service, go to the keys section and copy the connection string, we will be using the same in our Azure Function.</p>



<h3 class="wp-block-heading">Azure Functions</h3>



<p>As we discussed in my previous article, we will be creating an Azure Function with an IoTHubTrigger in it. You can refer to <a href="https://sibeeshpassion.com/azure-function-as-output-job-topology-of-an-azure-stream-analytics-job/#creating-an-azure-function-solution-and-function">this article</a> for the hints on how to create an Azure Function solution in Visual Studio. Please make sure that you had installed the required packages as mentioned in the image below.</p>



<figure class="wp-block-image"><img decoding="async" width="650" height="390" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Required-Packages.jpg" alt="" class="wp-image-13507" srcset="/wp-content/uploads/2018/12/Required-Packages.jpg 650w, /wp-content/uploads/2018/12/Required-Packages-300x180.jpg 300w, /wp-content/uploads/2018/12/Required-Packages-400x240.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Required Packages</figcaption></figure>



<p>Once you have created a new Function in the solution it is time to add some code.</p>



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

namespace AzureFunction
{
    public static class SignalR
    {
        [FunctionName("SignalR")]
        public static async Task Run(
            [IoTHubTrigger("messages/events", Connection = "IoTHubTriggerConnection", ConsumerGroup = "ml-iot-platform-func")]EventData message,
            [SignalR(HubName = "broadcast")]IAsyncCollector&lt;SignalRMessage> signalRMessages,
            ILogger log)
        {
            var deviceData = JsonConvert.DeserializeObject&lt;DeviceData>(Encoding.UTF8.GetString(message.Body.Array));
            deviceData.DeviceId = Convert.ToString(message.SystemProperties["iothub-connection-device-id"]);


            log.LogInformation($"C# IoT Hub trigger function processed a message: {JsonConvert.SerializeObject(deviceData)}");
            await signalRMessages.AddAsync(new SignalRMessage()
            {
                Target = "notify",
                Arguments = new[] { JsonConvert.SerializeObject(deviceData) }
            });
        }
    }
}</code></pre>



<p>As you can see we are using Microsoft.Azure.WebJobs.EventHubTriggerAttribute for pulling data from our IoT Hub. Here &#8220;messages/events&#8221; is our Event Hub Name and Connection is the IoT Hub connections string which is defined in the local.settings.json file and the ConsumerGroup is the group I have created for the Azure Function solution. </p>



<p>If you have noticed, we are using the HubName as &#8220;broadcast&#8221; in the SignalR attribute and &#8220;notify&#8221; as the SignalR message Target property. If you change the Target property, you may get a warning in your browser console as &#8220;Warning: No client method with the name &#8216;notify&#8217; found.&#8221;. The   @aspnet/<g class="gr_ gr_113 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="113" data-gr-id="113">signalr</g> package is checking for the Target property &#8216;notify&#8217; by default. </p>



<figure class="wp-block-image"><img decoding="async" width="650" height="202" src="https://sibeeshpassion.com/wp-content/uploads/2019/01/Nofity-not-found-error.jpg" alt="" class="wp-image-13517" srcset="/wp-content/uploads/2019/01/Nofity-not-found-error.jpg 650w, /wp-content/uploads/2019/01/Nofity-not-found-error-300x93.jpg 300w, /wp-content/uploads/2019/01/Nofity-not-found-error-400x124.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Nofity not found error</figcaption></figure>



<figure class="wp-block-image"><img decoding="async" width="650" height="255" src="https://sibeeshpassion.com/wp-content/uploads/2019/01/HubConnection-Js-File-Looks-for-Notify.jpg" alt="" class="wp-image-13516" srcset="/wp-content/uploads/2019/01/HubConnection-Js-File-Looks-for-Notify.jpg 650w, /wp-content/uploads/2019/01/HubConnection-Js-File-Looks-for-Notify-300x118.jpg 300w, /wp-content/uploads/2019/01/HubConnection-Js-File-Looks-for-Notify-400x157.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>HubConnection Js File Looks for Notify</figcaption></figure>



<p>So, I will keep the Target property as &#8216;notify&#8217;. By default, the message data doesn&#8217;t contain the device id value, so we will have to get the same from SystemProperties.</p>



<pre class="wp-block-code"><code> var deviceData = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(message.Body.Array));
             deviceData.DeviceId = Convert.ToString(message.SystemProperties["iothub-connection-device-id"]);</code></pre>



<p>Below is my DeviceData class.</p>



<pre class="wp-block-code"><code>using Newtonsoft.Json;
using System;

namespace AzureFunction
{
    public class DeviceData
    {
        [JsonProperty("messageId")]
        public string MessageId { get; set; }

        [JsonProperty("deviceId")]
        public string DeviceId { get; set; }

        [JsonProperty("temperature")]
        public string Temperature { get; set; }

        [JsonProperty("humidity")]
        public string Humidity { get; set; }

        [JsonProperty("pressure")]
        public string pressure { get; set; }

        [JsonProperty("pointInfo")]
        public string PointInfo { get; set; }

        [JsonProperty("ioTHub")]
        public string IoTHub { get; set; }

        [JsonProperty("eventEnqueuedUtcTime")]
        public DateTime EventEnqueuedUtcTime { get; set; }

        [JsonProperty("eventProcessedUtcTime")]
        public DateTime EventProcessedUtcTime { get; set; }

        [JsonProperty("partitionId")]
        public string PartitionId { get; set; }
    }
}</code></pre>



<p>When you work with any client like Angular application, it is important that we need to get the token/connection from the server, so that the client can persist the connection with the <g class="gr_ gr_6 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins doubleReplace replaceWithoutSep" id="6" data-gr-id="6">server</g>, hence the data can be pushed to the client from SignalR service. So, we will create a new Azure Function which will return the connection information with the Url and AccessToken.</p>



<pre class="wp-block-code"><code>using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Extensions.SignalRService;
using Microsoft.Extensions.Logging;

namespace AzureFunction
{
    public static class SignalRConnection
    {
        [FunctionName("SignalRConnection")]
        public static SignalRConnectionInfo Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
            [SignalRConnectionInfo(HubName = "broadcast")] SignalRConnectionInfo info,
            ILogger log) => info;
    }
}</code></pre>



<p>Please make sure that you have set AuthorizationLevel.Anonymous in HttpTrigger attribute and also to use the same HubName we have used for our other Azure Function, which is SignalR. </p>



<p>Now we can customize our local.settings.json file.</p>



<pre class="wp-block-code"><code>{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "AzureSignalRConnectionString": "",
    "MSDEPLOY_RENAME_LOCKED_FILES": 1,
    "IoTHubTriggerConnection": ""
  },
  "Host": {
    "LocalHttpPort": 7071,
    "CORS": "*"
  }
}</code></pre>



<p>Please be noted that this file if for local configuration and remember to change the connections strings here before you run the application. If you want to enable the CORS in the Azure Function in the Azure Portal, you can do that by following the steps mentioned in the image below.</p>



<figure class="wp-block-image"><img decoding="async" width="649" height="227" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Enabling-CORS-in-Azure-Function.jpg" alt="" class="wp-image-13499" srcset="/wp-content/uploads/2018/12/Enabling-CORS-in-Azure-Function.jpg 649w, /wp-content/uploads/2018/12/Enabling-CORS-in-Azure-Function-300x105.jpg 300w, /wp-content/uploads/2018/12/Enabling-CORS-in-Azure-Function-400x140.jpg 400w" sizes="(max-width: 649px) 100vw, 649px" /><figcaption>Enabling CORS in Azure Function</figcaption></figure>



<h3 class="wp-block-heading">Angular Client</h3>



<p>As we have already created our Azure Functions, now it is time to create our Angular client. Let&#8217;s use Angular CLI and create a new project. Now we can add a new package <em>@aspnet/</em><g class="gr_ gr_308 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling ins-del multiReplace" id="308" data-gr-id="308"><em class="">signalr</em></g> to our application which will help us to talk to our Azure SignalR service. </p>



<h4 class="wp-block-heading"> home.component.ts </h4>



<p>Below is my code for home.component.ts file.</p>



<pre class="wp-block-code"><code>import { Component, OnInit, NgZone } from '@angular/core';
import { SignalRService } from 'src/app/services/signal-r.service';
import { StreamData } from 'src/app/models/stream.data';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
  streamData: StreamData = new StreamData();

  constructor(private signalRService: SignalRService) {
  }

  ngOnInit() {
    this.signalRService.init();
    this.signalRService.mxChipData.subscribe(data => {
      this.streamData = JSON.parse(data);
      console.log(data);
    });
  }
}</code></pre>



<h4 class="wp-block-heading"> home.component.html </h4>



<p>We use Material card to show the Device data, so we can define our home.component.html file as preceding.</p>



<pre class="wp-block-code"><code>&lt;div class="container">
  &lt;div class="row">
    &lt;mat-card class="example-card">
      &lt;mat-card-header>
        &lt;div mat-card-avatar class="example-header-image">&lt;/div>
        &lt;mat-card-title>Real Time Values&lt;/mat-card-title>
        &lt;mat-card-subtitle>The real time values of humidity, temprature etc...&lt;/mat-card-subtitle>
      &lt;/mat-card-header>
      &lt;mat-card-content>
        &lt;p>
          &lt;label>DeviceId: &lt;/label>
          {{streamData?.deviceId}}
        &lt;/p>
        &lt;p>
          &lt;label>Temperature: &lt;/label>
          {{streamData?.temperature}}
        &lt;/p>
        &lt;p>
          &lt;label>Humidity: &lt;/label>
          {{streamData?.humidity}}
        &lt;/p>
      &lt;/mat-card-content>
    &lt;/mat-card>
  &lt;/div>
&lt;/div></code></pre>



<h4 class="wp-block-heading">signal-r.service.ts</h4>



<p>Now, we can create a new service which calls our Azure SignalR service. </p>



<pre class="wp-block-code"><code>import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, Subject } from 'rxjs';
import { SignalRConnection } from '../models/signal-r-connection.model';
import { environment } from '../../environments/environment';
import * as SignalR from '@aspnet/signalr';

@Injectable({
  providedIn: 'root'
})

export class SignalRService {
  mxChipData: Subject&lt;string> = new Subject();
  private hubConnection: SignalR.HubConnection;

  constructor(private http: HttpClient) {
  }

  private getSignalRConnection(): Observable&lt;SignalRConnection> {
    return this.http.get&lt;SignalRConnection>(`${environment.baseUrl}SignalRConnection`);
  }

  init() {
    this.getSignalRConnection().subscribe(con => {
      const options = {
        accessTokenFactory: () => con.accessToken
      };

      this.hubConnection = new SignalR.HubConnectionBuilder()
        .withUrl(con.url, options)
        .configureLogging(SignalR.LogLevel.Information)
        .build();

      this.hubConnection.start().catch(error => console.error(error));

      this.hubConnection.on('notify', data => {
        this.mxChipData.next(data);
      });
    });
  }
}</code></pre>



<p>As you can see, we are doing the following things in our service.</p>



<ol class="wp-block-list"><li>Get the SignalR connection information which contains Url and Access token, by calling the SignalRConnection Azure Function.</li><li>Create the Hub connection using SignalR.HubConnectionBuilder.</li><li>Start the Hub connection</li><li>Wire the &#8216;notify&#8217; function, remember we have set this in our Azure Function SignalR.</li></ol>



<h4 class="wp-block-heading">signal-r-connection.model.ts</h4>



<pre class="wp-block-code"><code>export class SignalRConnection {
   url: string;
   accessToken: string;
}</code></pre>



<h4 class="wp-block-heading">stream.data.ts</h4>



<pre class="wp-block-code"><code>export class StreamData {
    messageId: string;
    deviceId: string;
    temperature: string;
    humidity: string;
    pressure: string;
    pointInfo: string;
    ioTHub: string;
    eventEnqueuedUtcTime: string;
    eventProcessedUtcTime: string;
    partitionId: string;
}</code></pre>



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



<p>Now, let&#8217;s just run our Angular application, Azure Function, and a simulated device. Please refer to <a href="https://sibeeshpassion.com/an-introduction-to-azure-stream-analytics-job/#run-the-stream-analytics-job-and-see-the-data-in-the-database">this link</a> for the information related to the Simulated device. Please feel free to connect to your IoT device, if you haven&#8217;t configured the simulated device. </p>



<figure class="wp-block-image"><img decoding="async" width="1280" height="720" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Realtime-IoT-Device-Data.gif" alt="" class="wp-image-13501"/><figcaption>Realtime IoT Device Data</figcaption></figure>



<figure class="wp-block-image"><img decoding="async" width="650" height="250" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Serverless-Realtime-MXChip-Data-Angular.gif" alt="Serverless Realtime MXChip Data Angular" class="wp-image-13512"/><figcaption>Serverless Realtime MXChip Data Angular</figcaption></figure>



<p>References</p>



<ol class="wp-block-list"><li><a href="https://medium.com/medialesson/serverless-real-time-messaging-with-azure-functions-and-azure-signalr-service-c70e781ff3c3">Server less real-time messaging</a></li></ol>



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



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



<ul class="wp-block-list"><li>How to connect IoT Hub and Azure Function </li><li>What is Triggers in Azure Function</li><li>How to connect Azure Function and Azure SignalR service</li><li>How to post data to Azure SignalR service</li><li>How to connect Azure SignalR service from Angular client</li><li>How to show <g class="gr_ gr_377 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="377" data-gr-id="377">real time</g> data in Angular application from IoT device</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://www.sibeeshpassion.com/realtime-iot-data-using-azure-signalr-and-functions-in-angular/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>IoTHubTrigger Azure Function and Azure IoT Hub</title>
		<link>https://www.sibeeshpassion.com/iothubtrigger-azure-function-and-azure-iot-hub/</link>
					<comments>https://www.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 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://www.sibeeshpassion.com/iothubtrigger-azure-function-and-azure-iot-hub/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Azure Function as Output Job Topology of an Azure Stream Analytics Job</title>
		<link>https://www.sibeeshpassion.com/azure-function-as-output-job-topology-of-an-azure-stream-analytics-job/</link>
					<comments>https://www.sibeeshpassion.com/azure-function-as-output-job-topology-of-an-azure-stream-analytics-job/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Wed, 19 Dec 2018 14:37:18 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[IoT]]></category>
		<category><![CDATA[ASA]]></category>
		<category><![CDATA[Azure Function]]></category>
		<category><![CDATA[Azure Function and Azure Stream Analytics]]></category>
		<category><![CDATA[Azure IoT]]></category>
		<category><![CDATA[IoT Hub]]></category>
		<category><![CDATA[MXChip]]></category>
		<category><![CDATA[Stream Analytics Job]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13479</guid>

					<description><![CDATA[[toc] Introduction For the last few days, I am playing with my Azure IoT Dev Kit MXChip. In this article, we are going to see how we can set up an Azure Function as an Output job topology of an Azure Stream Analytics job. Isn&#8217;t that sound interesting? In our previous articles, we have already seen what is an Azure Stream Analytics Job and How can we create in by using the portal and Visual Studio. If you haven&#8217;t read those articles, I strongly recommend you to read. Let&#8217;s jump on to this article now. Background As I have mentioned [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



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



<p>For the last few days, I am playing with my Azure IoT Dev Kit MXChip. In this article, we are going to see how we can set up an Azure Function as an Output job topology of an Azure Stream Analytics job. Isn&#8217;t that sound interesting? In our previous <a href="https://sibeeshpassion.com/tag/stream-analytics-job/">articles</a>, we have already seen what is an Azure Stream Analytics Job and How can we create in by using the portal and Visual Studio. If you haven&#8217;t read those articles, I strongly recommend you to read. Let&#8217;s jump on to this article now.</p>



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



<p>As I have mentioned earlier, in this article we will be,&nbsp;</p>



<ol class="wp-block-list"><li>using our existing Azure Stream Analytics job.</li><li>creating a new Azure Function App.</li><li>setting up the newly created Azure function as an output job topology of the stream analytics job.</li><li>monitoring the data coming to the Azure Function from the stream analytics job.</li></ol>



<h2 class="wp-block-heading">Play with Azure Function</h2>



<p>Yeah, we are going to play with it. Let&#8217;s go and create one then.</p>



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



<p>To create an Azure Function application, you need to login to your Azure portal and click on the Create a resource icon, and then you can search for the &#8221; Function App&#8221;.&nbsp;</p>



<p>In the next screen, provide the following information.&nbsp;</p>



<ol class="wp-block-list"><li>App Name</li><li>Subscription</li><li>Resource Group</li><li>OS</li><li>Hosting plan</li><li>Location&nbsp;</li><li>Runtime stack</li><li>Storage</li><li>Application Insights</li></ol>



<p>Here the consumption plan hosting plan allows you to pay per execution, and the App service plan allows you to have a predefined capacity. For the runtime stack, we will use .NET, however, you are free to use anything you wish.&nbsp;</p>



<p>Once you have created the same, you should be able to see it under the Function Apps section.&nbsp;</p>



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



<p>Now let&#8217;s go to our Visual Studio and create a new solution for our Azure Function.&nbsp;</p>



<div class="wp-block-image"><figure class="aligncenter is-resized"><img decoding="async" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Azure-Function-Project-Type-1024x419.jpg" alt="" class="wp-image-13480" width="512" height="210" srcset="/wp-content/uploads/2018/12/Azure-Function-Project-Type-1024x419.jpg 1024w, /wp-content/uploads/2018/12/Azure-Function-Project-Type-300x123.jpg 300w, /wp-content/uploads/2018/12/Azure-Function-Project-Type-768x314.jpg 768w, /wp-content/uploads/2018/12/Azure-Function-Project-Type-400x163.jpg 400w, /wp-content/uploads/2018/12/Azure-Function-Project-Type.jpg 1375w" sizes="(max-width: 512px) 100vw, 512px" /><figcaption>Azure Function Project Type</figcaption></figure></div>



<p>Now you can right click on your newly created project and add a new HttpTrigger Function. We will keep the Access Rights to Anonymous for now. I have named my function as &#8220;GetData&#8221;. For now, let&#8217;s just get the data from our Stream Analytics job and just check the length.&nbsp;</p>



<pre class="wp-block-code"><code>using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

namespace ml.IoTPlatform.AzureFunctions
{
    public static class GetData
    {
        [FunctionName("GetData")]
        public static async Task&lt;HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post")]HttpRequestMessage req,
            ILogger log)
        {
            log.LogInformation($"GetData function triggered with Uri {req.RequestUri}");

            string content = await req.Content.ReadAsStringAsync();
            log.LogInformation($"String content is {content}");
            dynamic data = JsonConvert.DeserializeObject(content);

            log.LogInformation($"Data count is {data?.Count}");

            if (data?.ToString()?.Length > 262144)
            {
                return new HttpResponseMessage(HttpStatusCode.RequestEntityTooLarge);
            }

            return req.CreateResponse(HttpStatusCode.OK, "Success");
        }
    }
}</code></pre>



<p>As you can see we are not doing nothing much for now, we are just receiving the data as&nbsp;HttpRequestMessage and we are reading the content as&nbsp;req.Content.ReadAsStringAsync() and then deserialize the object. If you are not doing this step, you may get an error as&nbsp;&#8220;<strong>No MediaTypeFormatter is available to read an object of type &#8216;Object&#8217; from content with media type &#8216;application/octet-stream&#8217;.</strong>&#8220;</p>



<p>We are also checking the entity length, and if it is too large we are sending a&nbsp;HttpResponseMessage with status code 413.&nbsp;</p>



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



<p>To publish your Azure Function app, just right click on your project and click Publish and then set up your publish target by choosing the existing Azure Function App, remember we have created on earlier? Once you publish the same, you can go into your Function App and see your Function. You can also test the same with some dummy data.&nbsp;</p>



<p>There are probabilities to get an error as &#8220;<strong>Web Deploy cannot modify the file on the destination because it is locked by an external process</strong>&#8221; when you try to publish your Function App from Visual Studio, while your Function App is running, to fix this you can see my answer <a href="https://stackoverflow.com/questions/37918650/azure-web-app-deploy-web-deploy-cannot-modify-the-file-on-the-destination-becau/53833766#53833766">here</a>.&nbsp;</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="651" height="284" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Function-App-in-Portal.jpg" alt="" class="wp-image-13481" srcset="/wp-content/uploads/2018/12/Function-App-in-Portal.jpg 651w, /wp-content/uploads/2018/12/Function-App-in-Portal-300x131.jpg 300w, /wp-content/uploads/2018/12/Function-App-in-Portal-400x175.jpg 400w" sizes="(max-width: 651px) 100vw, 651px" /><figcaption>Function App in Portal</figcaption></figure></div>



<h2 class="wp-block-heading">Azure Stream Analytics Job</h2>



<p>Let&#8217;s go back to our Azure Stream Analytics now as we have already configured our Azure Function App successfully.&nbsp;</p>



<h3 class="wp-block-heading">Configure Azure Function Output</h3>



<p>In my previous <a href="https://sibeeshpassion.com/azure-stream-analytics-job-and-tools-for-visual-studio/">article</a>, we had created an Azure Stream Analytics job solution using Visual Studio, let&#8217;s open that solution now and configure the new output for Azure Function.&nbsp;</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="640" height="535" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Solution-Explorer.jpg" alt="" class="wp-image-13482" srcset="/wp-content/uploads/2018/12/Solution-Explorer.jpg 640w, /wp-content/uploads/2018/12/Solution-Explorer-300x251.jpg 300w, /wp-content/uploads/2018/12/Solution-Explorer-400x334.jpg 400w" sizes="(max-width: 640px) 100vw, 640px" /><figcaption>Solution Explorer</figcaption></figure></div>



<p>While configuring the Azure Function Output, please make sure that you are selecting the existing azure function app.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="651" height="281" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Azure-Function-Output-Configuration.jpg" alt="" class="wp-image-13483" srcset="/wp-content/uploads/2018/12/Azure-Function-Output-Configuration.jpg 651w, /wp-content/uploads/2018/12/Azure-Function-Output-Configuration-300x129.jpg 300w, /wp-content/uploads/2018/12/Azure-Function-Output-Configuration-400x173.jpg 400w" sizes="(max-width: 651px) 100vw, 651px" /><figcaption>Azure Function Output Configuration</figcaption></figure></div>



<h3 class="wp-block-heading">Update the Script</h3>



<p>We should also do some changes in our Script.asaql file to support our newly created output.&nbsp;</p>



<pre class="wp-block-code"><code>WITH BasicOutput AS 
(
SELECT    
    messageId,
    deviceId,
    temperature,
    humidity,
    pressure,
    pointInfo,
    IoTHub,
    MAX(EventEnqueuedUtcTime) AS EventEnqueuedUtcTime,
    EventProcessedUtcTime,
    PartitionId    
FROM
    Input TIMESTAMP By EventEnqueuedUtcTime
    GROUP BY TUMBLINGWINDOW(second, 10), 
    messageId, 
    deviceId,
    temperature,
    humidity,
    pressure,
    pointInfo,
    IoTHub,
    EventEnqueuedUtcTime,
    EventProcessedUtcTime,
    PartitionId
)

SELECT * INTO SQLServerOutput FROM BasicOutput
SELECT * INTO AzureFunctionOutput FROM BasicOutput</code></pre>



<h3 class="wp-block-heading">Updating the TLS Version</h3>



<p>Once that is done, just click the button Submit to Azure, if you have any doubts in this section, read my previous posts on this topic. Now let&#8217;s log in to the portal again and see all the outputs, inputs, and the query is been published or not.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="651" height="220" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Outputs-in-Portal.jpg" alt="" class="wp-image-13484" srcset="/wp-content/uploads/2018/12/Outputs-in-Portal.jpg 651w, /wp-content/uploads/2018/12/Outputs-in-Portal-300x101.jpg 300w, /wp-content/uploads/2018/12/Outputs-in-Portal-400x135.jpg 400w" sizes="(max-width: 651px) 100vw, 651px" /><figcaption>Outputs in Portal</figcaption></figure></div>



<p>Cool!. Well done, it seems like it is published. Now if you click on the AzureFunctionOutput, you may get a warning as &#8220;<strong>Please make sure that the Minimum TLS version is set to 1.0 on your Azure Functions before you start your ASA job</strong>&#8220;. I would rather treat this as an error instead of a warning because without making this changes our Azure Stream Analytics job will not write to our Azure Function. So this is very important, I spent many hours in this and finally found this was the root cause of my issue, you can see my answer about this <a href="https://stackoverflow.com/questions/53851553/an-error-occurred-send-events-azure-function-output-adapter-failed-to-write-eve/53851554#53851554">here</a>.</p>



<p>So just go to your Azure Function App and click on Platform Features -&gt; SSL -&gt; Minimum TLS Version</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="511" height="397" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Setting-TLS-Version.jpg" alt="" class="wp-image-13485" srcset="/wp-content/uploads/2018/12/Setting-TLS-Version.jpg 511w, /wp-content/uploads/2018/12/Setting-TLS-Version-300x233.jpg 300w, /wp-content/uploads/2018/12/Setting-TLS-Version-400x311.jpg 400w" sizes="(max-width: 511px) 100vw, 511px" /><figcaption>Setting TLS Version</figcaption></figure></div>



<p>There is a saying that developers don&#8217;t care about warning but only the errors, in some cases it is true. Hm, I was just kidding.&nbsp;</p>



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



<p>Once you are done everything mentioned, you are good to go and start your Stream Analytics job, please make sure that your MXChip is connected to a power source so that the device can start sending the data.&nbsp;</p>



<h3 class="wp-block-heading">Checking the SQL Server Output</h3>



<p>Now let&#8217;s login to our SQL Server Database and run the below query to make sure that we are getting the data from the device.</p>



<pre class="wp-block-code"><code>SELECT TOP (1000) [Id]
      ,[messageId]
      ,[deviceId]
      ,[temperature]
      ,[humidity]
      ,[pressure]
      ,[pointInfo]
      ,[IoTHub]
      ,[EventEnqueuedUtcTime]
      ,[EventProcessedUtcTime]
      ,[PartitionId]
  FROM [dbo].[StreamData] order by [EventEnqueuedUtcTime] desc</code></pre>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="651" height="286" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/SQL-Server-Output-Data.jpg" alt="" class="wp-image-13486" srcset="/wp-content/uploads/2018/12/SQL-Server-Output-Data.jpg 651w, /wp-content/uploads/2018/12/SQL-Server-Output-Data-300x132.jpg 300w, /wp-content/uploads/2018/12/SQL-Server-Output-Data-400x176.jpg 400w" sizes="(max-width: 651px) 100vw, 651px" /><figcaption>SQL Server Output Data<br></figcaption></figure></div>



<h3 class="wp-block-heading">Checking Azure Function Output&nbsp;</h3>



<p>To check the Azure Function Output, we can go back to our Azure Function and click on the Function and use the <strong>Monitor </strong>option.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="1024" height="254" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Azure-Function-Output-Data-1024x254.jpg" alt="" class="wp-image-13487" srcset="/wp-content/uploads/2018/12/Azure-Function-Output-Data-1024x254.jpg 1024w, /wp-content/uploads/2018/12/Azure-Function-Output-Data-300x74.jpg 300w, /wp-content/uploads/2018/12/Azure-Function-Output-Data-768x190.jpg 768w, /wp-content/uploads/2018/12/Azure-Function-Output-Data-400x99.jpg 400w, /wp-content/uploads/2018/12/Azure-Function-Output-Data.jpg 1574w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Azure Function Output Data</figcaption></figure></div>



<p>Please be noted that you can always check your Azure Stream Analytics job Activity Log if you found something is not working.&nbsp;</p>



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



<p>In this article, we have learned how to,</p>



<ol class="wp-block-list"><li>work with an Azure Stream Analytics job</li><li>create an Azure Function App</li><li>create Azure Function App solution in Visual Studio</li><li>write an HttpTrigger&nbsp;function and publish the same to the Azure Function App</li><li>set up the Azure Function App as an output job topology of Azure Stream Analytics job</li><li>Use the created package in another solution</li></ol>



<p>In our next article, we will see how you can send this Azure Function Output data to an Azure SignalR service and then get the same data in an Angular Application. I can&#8217;t wait to write my next article.&nbsp;</p>



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



<p>Thanks a lot for reading. I will come back with another post on the same topic very soon.&nbsp;Did I miss anything that you may think which is needed? Could you find this post as useful? Kindly do not forget to share me your feedback.</p>



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



<p>Kindest Regards<br>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/azure-function-as-output-job-topology-of-an-azure-stream-analytics-job/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Azure Stream Analytics Job and Tools for Visual Studio</title>
		<link>https://www.sibeeshpassion.com/azure-stream-analytics-job-and-tools-for-visual-studio/</link>
					<comments>https://www.sibeeshpassion.com/azure-stream-analytics-job-and-tools-for-visual-studio/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Thu, 13 Dec 2018 13:13:50 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[IoT]]></category>
		<category><![CDATA[Azure IoT]]></category>
		<category><![CDATA[Data Lake]]></category>
		<category><![CDATA[MXChip]]></category>
		<category><![CDATA[Stream Analytics Job]]></category>
		<category><![CDATA[Stream Analytics tool]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13461</guid>

					<description><![CDATA[[toc] Introduction Creating an Azure Stream Analytics job and working with them is always a fun. And what if there is a tool which helps you create a stream solution in Visual Studio so that you don&#8217;t want to go over the browser and do some manual button clicks? That&#8217;s where the Azure Data Lake and Stream Analytics Tool extension come into the play. In my previous post, we have already discussed what is an Azure Stream Analytics job and how can we work with the same, if you haven&#8217;t read the same, please read it. Now let&#8217;s go and [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



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



<p>Creating an <a href="https://sibeeshpassion.com/category/azure">Azure</a> Stream Analytics job and working with them is always a fun. And what if there is a tool which helps you create a stream solution in Visual Studio so that you don&#8217;t want to go over the browser and do some manual button clicks? That&#8217;s where the Azure Data Lake and Stream Analytics Tool extension come into the play. In my previous post, we have already discussed <a href="https://sibeeshpassion.com/an-introduction-to-azure-stream-analytics-job/">what is an Azure Stream Analytics job and how can we work with the same</a>, if you haven&#8217;t read the same, please read it. Now let&#8217;s go and use the extension.</p>



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



<p>Recently, I started working with Azure IoT Device Kit, which is a wonderful micro controller board, it can send a lot of information like temperature, humidity to the Azure cloud, as it has a lot of inbuilt sensors. Now in this article, we will create a Visual Studio solution for our Stream Analytics Job so that the same can be moved to a source control and can be easily managed.&nbsp;</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Please be noted that the Extension we are going to use is not yet supported with Visual Studio 2019, and if you try to create the same in VS2019, you will get an error as&nbsp;<a href="https://stackoverflow.com/questions/53727170/azure-stream-analytics-tool-for-visual-studio-in-2019-preview/53727171#53727171">the version of Visual Studio is not supported</a></p><cite>The extension is not supported in VS2019</cite></blockquote>



<h2 class="wp-block-heading">Setting up the Environment</h2>



<p>I am assuming that you have a valid Azure Subscription and you have access to create the resouces in it.&nbsp;</p>



<h3 class="wp-block-heading">Modify Visual Studio with Required Workloads</h3>



<p>Let&#8217;s go to our Visual Studio installer and modify the workloads now.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="651" height="209" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Install-the-Required-Workloads.jpg" alt="" class="wp-image-13464" srcset="/wp-content/uploads/2018/12/Install-the-Required-Workloads.jpg 651w, /wp-content/uploads/2018/12/Install-the-Required-Workloads-300x96.jpg 300w, /wp-content/uploads/2018/12/Install-the-Required-Workloads-400x128.jpg 400w" sizes="(max-width: 651px) 100vw, 651px" /><figcaption>Install the Required Workloads</figcaption></figure></div>



<p>Once the workloads are modified, make sure that the extension is available in your Extensions, you can do that by going to Tools -&gt; Extension menu.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="650" height="451" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Azure-Data-Lake-Extension.jpg" alt="" class="wp-image-13463" srcset="/wp-content/uploads/2018/12/Azure-Data-Lake-Extension.jpg 650w, /wp-content/uploads/2018/12/Azure-Data-Lake-Extension-300x208.jpg 300w, /wp-content/uploads/2018/12/Azure-Data-Lake-Extension-160x110.jpg 160w, /wp-content/uploads/2018/12/Azure-Data-Lake-Extension-400x278.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Azure Data Lake Extension</figcaption></figure></div>



<h3 class="wp-block-heading">Creating a New Stream Analytics Project</h3>



<p>Once the Extension is enabled, you should be able to create a new Azure Stream Analytics Application.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="651" height="359" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Azure-Stream-Analytics-Application.jpg" alt="" class="wp-image-13465" srcset="/wp-content/uploads/2018/12/Azure-Stream-Analytics-Application.jpg 651w, /wp-content/uploads/2018/12/Azure-Stream-Analytics-Application-300x165.jpg 300w, /wp-content/uploads/2018/12/Azure-Stream-Analytics-Application-400x221.jpg 400w" sizes="(max-width: 651px) 100vw, 651px" /><figcaption>Azure Stream Analytics Application&nbsp;</figcaption></figure></div>



<p>The new project will be containing the below files.</p>



<ol class="wp-block-list"><li>Input.json</li><li>Output.json</li><li>JobConfig.json</li><li>Script.asaql</li></ol>



<p>To&nbsp;configure your subscription, please make sure that you have added your&nbsp;Subscription in the Server Explorer.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="435" height="544" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Azure-Server-Explorer.jpg" alt="" class="wp-image-13470" srcset="/wp-content/uploads/2018/12/Azure-Server-Explorer.jpg 435w, /wp-content/uploads/2018/12/Azure-Server-Explorer-240x300.jpg 240w, /wp-content/uploads/2018/12/Azure-Server-Explorer-400x500.jpg 400w" sizes="(max-width: 435px) 100vw, 435px" /><figcaption>Azure Server Explorer</figcaption></figure></div>



<p>The Input.json file is the replica of your Input job topology, <g class="gr_ gr_120 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="120" data-gr-id="120">double click</g> on the file will give you the configuration page to configure the details.&nbsp;</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="1024" height="982" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Input-Configuration-1024x982.jpg" alt="" class="wp-image-13466" srcset="/wp-content/uploads/2018/12/Input-Configuration-1024x982.jpg 1024w, /wp-content/uploads/2018/12/Input-Configuration-300x288.jpg 300w, /wp-content/uploads/2018/12/Input-Configuration-768x736.jpg 768w, /wp-content/uploads/2018/12/Input-Configuration-400x384.jpg 400w, /wp-content/uploads/2018/12/Input-Configuration-626x600.jpg 626w, /wp-content/uploads/2018/12/Input-Configuration.jpg 1504w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Input Configuration</figcaption></figure></div>



<p>The Output.json file is your output job topology, you can have as many outputs you need. In my case it is just one, SQL Server Database.&nbsp;</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="650" height="485" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Output-Configuration.jpg" alt="" class="wp-image-13467" srcset="/wp-content/uploads/2018/12/Output-Configuration.jpg 650w, /wp-content/uploads/2018/12/Output-Configuration-300x224.jpg 300w, /wp-content/uploads/2018/12/Output-Configuration-400x298.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Output Configuration</figcaption></figure></div>



<p>You can always configure your job using the JobConfig.json file. When you configure the Job, you need to be sure about the values you are providing and what are the needs of them.&nbsp;</p>



<p><strong>Data Locale</strong> is your locale input. The option <strong>Output Error Handling</strong> is for handling the situation when the events fail to be written to the output, you can select either Drop or Retry. The <strong>Late Arrival Tolerance Window</strong> is the timeframe which you can wait for the event to reach the IoT hub, the time difference is between the event timestamp and the system time. </p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="650" height="416" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/JobConfiguration.jpg" alt="" class="wp-image-13468" srcset="/wp-content/uploads/2018/12/JobConfiguration.jpg 650w, /wp-content/uploads/2018/12/JobConfiguration-300x192.jpg 300w, /wp-content/uploads/2018/12/JobConfiguration-400x256.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Job Configuration</figcaption></figure></div>



<p>And the Script.asaql is the file where you need to add your custom query which gets data from the input and send it to the output.&nbsp;</p>



<pre class="wp-block-code"><code>SELECT
    messageId,
    deviceId,
    temperature,
    humidity,
    pressure,
    pointInfo,
    IoTHub,
    EventEnqueuedUtcTime,
    EventProcessedUtcTime,
    PartitionId
INTO
    streamoutputs
FROM
    streaminputs</code></pre>



<p>Once everything is done, you are ready to submit the same to the Azure. You can either create a new job or use the existing one.&nbsp;</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="651" height="280" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Submit-Job.jpg" alt="" class="wp-image-13469" srcset="/wp-content/uploads/2018/12/Submit-Job.jpg 651w, /wp-content/uploads/2018/12/Submit-Job-300x129.jpg 300w, /wp-content/uploads/2018/12/Submit-Job-400x172.jpg 400w" sizes="(max-width: 651px) 100vw, 651px" /><figcaption>Submit Job</figcaption></figure></div>



<p>When you submit, you can see that a new Stream Analytics view will get opened and the job will be starting automatically. You can always see the blobs created under your container by going to the cloud explorer.&nbsp;</p>



<figure class="wp-block-image"><img decoding="async" width="650" height="300" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Cloud-Explorer-Blob-Container-View.jpg" alt="" class="wp-image-13471" srcset="/wp-content/uploads/2018/12/Cloud-Explorer-Blob-Container-View.jpg 650w, /wp-content/uploads/2018/12/Cloud-Explorer-Blob-Container-View-300x138.jpg 300w, /wp-content/uploads/2018/12/Cloud-Explorer-Blob-Container-View-400x185.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Cloud Explorer</figcaption></figure>



<p>Now just right click on your solution and select &#8220;Add solution to Source Control and then push the same to your git repository. Once you have added the solution to the source control, your team members can easily update the Input and Output configuration and have a history of the same.&nbsp;</p>



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



<p>In this article, we have learned how to,</p>



<ol class="wp-block-list"><li>set up the Visual Studio for using Data Lake and Stream Analytics tool</li><li>use the Data Lake and Stream Analytics tool</li><li>configure the Input for Stream Analytics</li><li>configure the Stream Analytics Job</li><li>Use the created package in another solution</li></ol>



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



<p>Thanks a lot for reading. I will come back with another post on the same topic very soon.&nbsp;Did I miss anything that you may think which is needed? 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://www.sibeeshpassion.com/azure-stream-analytics-job-and-tools-for-visual-studio/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>An Introduction to Azure Stream Analytics Job</title>
		<link>https://www.sibeeshpassion.com/an-introduction-to-azure-stream-analytics-job/</link>
					<comments>https://www.sibeeshpassion.com/an-introduction-to-azure-stream-analytics-job/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Tue, 11 Dec 2018 14:00:39 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[IoT]]></category>
		<category><![CDATA[Azure IoT]]></category>
		<category><![CDATA[Azure SQL]]></category>
		<category><![CDATA[Configure Stream Analytics with Input and Output]]></category>
		<category><![CDATA[Data Lake]]></category>
		<category><![CDATA[IoT Hub]]></category>
		<category><![CDATA[MXChip]]></category>
		<category><![CDATA[Stream Analytics Job]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13444</guid>

					<description><![CDATA[[toc] Introduction The capability of an Azure Stream Analytics Job is a lot, here in this post we are going to discuss a few of them. An Azure Stream Analytics is basically an engine which processes the events. These events are coming from the devices we have configured, it can be an Azure IoT Dev Kit (MXChip) or a Raspberry Pi and many more. The stream analytics job has two vital parts Input source Output source The input source is the source of your streaming data, in my case, it is my IoT Hub. And the output source is the output [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



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



<p>The capability of an <a href="https://sibeeshpassion.com/category/azure/">Azure</a> Stream Analytics Job is a lot, here in this post we are going to discuss a few of them. An Azure Stream Analytics is basically an engine which processes the events. These events are coming from the devices we have configured, it can be an Azure IoT Dev Kit (MXChip) or a <a href="https://sibeeshpassion.com/category/raspberry-pi/">Raspberry Pi</a> and many more. The stream analytics job has two vital parts</p>



<ul class="wp-block-list"><li>Input source</li><li>Output source</li></ul>



<p>The input source is the source of your streaming data, in my case, it is my IoT Hub. And the output source is the output what you are configuring. I had configured the output to save the data to an Azure SQL database. Let&#8217;s just stop the introduction part now and start creating our own Stream Analytics. </p>



<div class="wp-block-image"><figure class="aligncenter is-resized"><img decoding="async" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/stream-analytics-intro-pipeline.png" alt="" class="wp-image-13445" width="650"/><figcaption>docs.microsoft.com</figcaption></figure></div>



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



<p>I recently got my MXChip (Azure Iot Dev Kit) and I was surprised with the capabilities that device can do.&nbsp;It has a lot of sensors within the device, like temperature, humidity, pressure, magnetometer, security etc. Then I thought it is time to play with the same.&nbsp;So the basic idea here was to,</p>



<ol class="wp-block-list"><li>Configure the device to send the data to the IoT Hub</li><li>Select the IoT Hub as a stream input</li><li>Send the output to an SQL Server database</li></ol>



<p>In this article, we are going to concentrate on how to create a Stream Analytics Job and how you can configure the same to save the stream data to the SQL Server database.&nbsp;</p>



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



<p>To do the wonderful things, we always need some prerequisites.&nbsp;&nbsp;</p>



<ol class="wp-block-list"><li>Azure Subscription</li><li>MXChip Azure IoT Dev Kit&nbsp;</li><li>An active IoT Hubows Driver Kit (WDK) 10</li><li>IoT Core ADK Add-Ons</li><li>Windows 10 IoT Core Packages</li><li>The Raspberry Pi BSP</li><li>Custom FFU image we have created</li></ol>



<h2 class="wp-block-heading">Creating the Azure Stream Analytics Job</h2>



<p>Login to your Azure Portal and click on the Create a resource, and then search for the &#8220;Stream Analytics job&#8221;.&nbsp;</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="520" height="321" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Stream-Analytics-Outputs.jpg" alt="" class="wp-image-13446" srcset="/wp-content/uploads/2018/12/Stream-Analytics-Outputs.jpg 520w, /wp-content/uploads/2018/12/Stream-Analytics-Outputs-300x185.jpg 300w, /wp-content/uploads/2018/12/Stream-Analytics-Outputs-400x247.jpg 400w" sizes="(max-width: 520px) 100vw, 520px" /></figure></div>



<p>Once you clicked on the Create button, it is time to specify the details of your job.</p>



<ol class="wp-block-list"><li>Job Name</li><li>Subscription</li><li>Resource Group</li><li>Location</li><li>Hosting Environment</li><li></li></ol>



<p>I would strongly recommend you to&nbsp;select the same resource group of your IoT Hub for the Stream Analytics Job as well so that you can easily delete the resources when there are not needed. Once the deployment is successful you can go to the resource overview and see the details.</p>



<h3 class="wp-block-heading">Configure Inputs</h3>



<p>In the left menu, you can see a section called Job topology, that&#8217;s where we are going to work. Basically, we will be setting the Inputs and Outputs and then we will be writing a query which can take the inputs and send the values to the configured output.&nbsp;Click on the Inputs label and click on Add stream input and then select the IoT Hub.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="480" height="452" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Configure-the-Input-in-Stream-Analytics.jpg" alt="Configure the Input in Stream Analytics" class="wp-image-13447" srcset="/wp-content/uploads/2018/12/Configure-the-Input-in-Stream-Analytics.jpg 480w, /wp-content/uploads/2018/12/Configure-the-Input-in-Stream-Analytics-300x283.jpg 300w, /wp-content/uploads/2018/12/Configure-the-Input-in-Stream-Analytics-400x377.jpg 400w" sizes="(max-width: 480px) 100vw, 480px" /></figure></div>



<p>In the next screen, you will have options to select the existing IoT hub and to create a new IoT Hub. As I have already created an IoT hub, I would select the existing one. </p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Please be noted that you are allowed to use special characters in the Input alias field, but if you use such, please make sure to include the same inside [] in the query, which we will be creating later.&nbsp;</p><cite>About the special characters in Input alias field</cite></blockquote>



<p>Once you are successfully&nbsp;configured the Inputs, then we can go ahead and configure the outputs. </p>



<h3 class="wp-block-heading">Configure Outputs</h3>



<p>Click on the Outputs from the Job topology section and click Add, and then select <g class="gr_ gr_144 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins replaceWithoutSep" id="144" data-gr-id="144">SQL</g> Database.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="474" height="448" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Configure-the-Output-in-Stream-Analytics.jpg" alt="Configure the Output in Stream Analytics" class="wp-image-13448" srcset="/wp-content/uploads/2018/12/Configure-the-Output-in-Stream-Analytics.jpg 474w, /wp-content/uploads/2018/12/Configure-the-Output-in-Stream-Analytics-300x284.jpg 300w, /wp-content/uploads/2018/12/Configure-the-Output-in-Stream-Analytics-400x378.jpg 400w" sizes="(max-width: 474px) 100vw, 474px" /></figure></div>



<p>You can either create a new Database&nbsp;or select the one you had already created. I used the existing database and table.&nbsp;</p>



<h3 class="wp-block-heading">Configure the Query</h3>



<p>Once you click the label Query on the left pan, you will be given an editor where you can write your queries. I am using the below query.&nbsp;</p>



<pre class="wp-block-code"><code>SELECT
    messageId,
    deviceId,
    temperature,
    humidity,
    pressure,
    pointInfo,
    IoTHub,
    EventEnqueuedUtcTime,
    EventProcessedUtcTime,
    PartitionId
INTO
    streamoutputs
FROM
    streaminputs</code></pre>



<p>As you can see that I am just selecting the fields I may need and saving the same to our stream outputs. You can always select all the fields by using the select * query, but the problem with that is, you will have to set up the table columns in the same order of the stream data. Otherwise, you may get an error as below.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Encountered error trying to write 1 event(s): Failed to locate column &#8216;IoTHub&#8217; at position 6 in the output event</p><cite>Stream analytics query error</cite></blockquote>



<p>If there are any errors, you can see that in the Output details.</p>



<h2 class="wp-block-heading">Run the Stream Analytics Job and See the Data in the Database</h2>



<p>As we have already done the initial set up, we can now start our Stream Analytics Job, please make sure that the IoT Hub is running and the device is sending data to the IoT Hub. If everything is working as expected, you will be able to see the data in the SQL server database. You can either connect your MXChip device to the network and test this or use the custom <a href="https://github.com/Azure-Samples/azure-iot-samples-csharp/tree/master/iot-hub/Tutorials/Routing/SimulatedDevice">simulator app</a>.&nbsp;</p>



<p>If you are using the Simulator console application, make sure that you are giving the device id, key and the IoT hub uri correctly, otherwise you will get an unauthorized error as explained <a href="https://stackoverflow.com/questions/53708530/microsoft-azure-devices-client-exceptions-unauthorizedexception-connect-failed/53708531#53708531">here</a>.&nbsp;</p>



<h3 class="wp-block-heading">Test the Stream Analytics Job Inside the Portal</h3>



<p>You also have an option to test the functionality in the portal itself. The only thing you will have to do is to prepare the sample input data. I have prepared the sample JSON data as follows. </p>



<pre class="wp-block-code"><code>[
  {
    "deviceId": "test-device",
    "humidity": 77.699449415178719,
    "pointInfo": "This is a normal message.",
    "temperature": 32.506656929620846
  },
  {
    "deviceId": "test-device",
    "temperature": 52.506656929620846,
    "humidity": 17.699449415178719,
    "pointInfo": "This is a normal message."
  },
  {
    "deviceId": "test-device",
    "temperature": 42.506656929620846,
    "humidity": 57.699449415178719,
    "pointInfo": "This is a normal message."
  }
]

</code></pre>



<p>Now we can go to the Query section and upload the sample data file for our inputs.&nbsp;</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="650" height="342" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Test-the-Stream-Analytics-with-Sample-Data.jpg" alt="" class="wp-image-13449" srcset="/wp-content/uploads/2018/12/Test-the-Stream-Analytics-with-Sample-Data.jpg 650w, /wp-content/uploads/2018/12/Test-the-Stream-Analytics-with-Sample-Data-300x158.jpg 300w, /wp-content/uploads/2018/12/Test-the-Stream-Analytics-with-Sample-Data-600x315.jpg 600w, /wp-content/uploads/2018/12/Test-the-Stream-Analytics-with-Sample-Data-400x210.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /></figure></div>



<p>In the next window, you can select the JSON option and upload your JSON file.&nbsp;</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="520" height="188" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Upload-the-test-data.jpg" alt="" class="wp-image-13450" srcset="/wp-content/uploads/2018/12/Upload-the-test-data.jpg 520w, /wp-content/uploads/2018/12/Upload-the-test-data-300x108.jpg 300w, /wp-content/uploads/2018/12/Upload-the-test-data-400x145.jpg 400w" sizes="(max-width: 520px) 100vw, 520px" /></figure></div>



<p>Click the Test button, and now you should be able to see the output as below.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="650" height="325" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Test-with-Sample-Data-Output.jpg" alt="" class="wp-image-13451" srcset="/wp-content/uploads/2018/12/Test-with-Sample-Data-Output.jpg 650w, /wp-content/uploads/2018/12/Test-with-Sample-Data-Output-300x150.jpg 300w, /wp-content/uploads/2018/12/Test-with-Sample-Data-Output-400x200.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /></figure></div>



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



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



<ul class="wp-block-list"><li>What is Azure Stream Analytics Job</li><li>how to create Azure Stream Analytics Job</li><li>how to add Inputs to the Azure Stream Analytics</li><li>how to add Outputs to the Azure Stream Analytics</li><li>how to add custom Query in Azure Stream Analytics</li><li>how to Test the Stream Analytics Query with sample data</li></ul>



<p>You can always ready my IoT articles <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://www.sibeeshpassion.com/an-introduction-to-azure-stream-analytics-job/feed/</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
			</item>
		<item>
		<title>Raspberry PI SD Card Provisioning with Windows 10 IoT Core &#8211; Adding Packages to the Existing FFU Image</title>
		<link>https://www.sibeeshpassion.com/raspberry-pi-sd-card-provisioning-with-windows-10-iot-core-adding-packages-to-the-existing-ffu-image/</link>
					<comments>https://www.sibeeshpassion.com/raspberry-pi-sd-card-provisioning-with-windows-10-iot-core-adding-packages-to-the-existing-ffu-image/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Sun, 09 Dec 2018 12:44:17 +0000</pubDate>
				<category><![CDATA[IoT]]></category>
		<category><![CDATA[Raspberry PI]]></category>
		<category><![CDATA[Custom IoT Core FFU Image]]></category>
		<category><![CDATA[FFU]]></category>
		<category><![CDATA[IoT Core]]></category>
		<category><![CDATA[IoT Core OS]]></category>
		<category><![CDATA[Raspberry PI SD Card Provisioning]]></category>
		<category><![CDATA[Windows 10]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13431</guid>

					<description><![CDATA[[toc] Introduction In my previous article, we have seen how to create a basic FFU image which can be flashed to SD cards. Today, we will see how we can package our application and add this to our existing IoT Core OS image. Doesn&#8217;t it sound good? If you haven&#8217;t read my previous articles on the same topic, I strongly recommend you to read so that we can make sure that we both are in the same boat. For now, let&#8217;s just start doing some amazing things. Let&#8217;s just start then. Background Wow, that&#8217;s cool that you have your own FFU [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h2>Introduction</h2>
<p>In my previous article, we have seen how to <a href="https://sibeeshpassion.com/raspberry-pi-sd-card-provisioning-with-windows-10-iot-core-create-ffu-image-and-flash/">create a basic FFU image</a> which can be flashed to SD cards. Today, we will see how we can package our application and add this to our existing IoT Core OS image. Doesn&#8217;t it sound good? If you haven&#8217;t read my previous articles on the same topic, I strongly recommend you to read so that we can make sure that we both are in the same boat. For now, let&#8217;s just start doing some amazing things. Let&#8217;s just start then.</p>
<h2>Background</h2>
<p>Wow, that&#8217;s cool that you have your own FFU image in your SD card now, to make it more custom you may need to add your own application to it so that the same can be run in as many Raspberry Pi device as can, well that&#8217;s called Provisioning right? In this article,</p>
<ol>
<li>we will see how we can create an APPX package of a UWP application</li>
<li>how the APPX package can be added to our FFU image</li>
</ol>
<p>Let&#8217;s start doing the PowerShell commands now then.</p>
<h2>Prerequisites</h2>
<p>To do the wonderful things, we always need some prerequisites.  You can always see all the prerequisites from <a href="https://docs.microsoft.com/en-us/windows-hardware/manufacture/iot/set-up-your-pc-to-customize-iot-core">here</a>. But, in this part, we are going to be needed only the preceding tools.</p>
<ol>
<li>Windows Assessment and Deployment Kit (Windows ADK)</li>
<li>Windows Driver Kit (WDK) 10</li>
<li>IoT Core ADK Add-Ons</li>
<li>Windows 10 IoT Core Packages</li>
<li>The Raspberry Pi BSP</li>
<li>Custom FFU image we have created</li>
</ol>
<h2>Creating the UWP APPX</h2>
<p>For now, I am going to use the Microsoft HelloWorld application, which is already available in the <a href="https://github.com/Microsoft/Windows-iotcore-samples/tree/develop/Samples/HelloWorld">GitHub</a>. Let&#8217;s just clone that application and build the same. If you are getting an error as &#8220;Error Cannot resolve Assembly or Windows Metadata file &#8216;Windows.Foundation.UniversalApiContract.winmd'&#8221;, please make sure that you had set the target version in the application section, you can always see my detailed answer <a href="https://stackoverflow.com/questions/53691306/error-cannot-resolve-assembly-or-windows-metadata-file-windows-foundation-unive/53691307#53691307">here in StackOverflow</a>.</p>
<p>Now let&#8217;s just right click on the project and click on Store &#8211; &gt; Create App Packages.</p>
<p><div id="attachment_13433" style="width: 660px" class="wp-caption aligncenter"><a href="https://sibeeshpassion.com/wp-content/uploads/2018/12/Create-APPX-Menu.jpg"><img decoding="async" aria-describedby="caption-attachment-13433" class="size-full wp-image-13433" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Create-APPX-Menu.jpg" alt="Create APPX Menu" width="650" height="380" srcset="/wp-content/uploads/2018/12/Create-APPX-Menu.jpg 650w, /wp-content/uploads/2018/12/Create-APPX-Menu-300x175.jpg 300w, /wp-content/uploads/2018/12/Create-APPX-Menu-400x234.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-13433" class="wp-caption-text">Create APPX Menu</p></div></p>
<p>Now select the option &#8220;I want to create packages for sideloading&#8221; and click next. In the next screen, you can always automatically increment your application version. In the Generate app bundle option, select Never. And click Create. Now the app will get built and the APPX file will be generated for you.</p>
<p><div id="attachment_13434" style="width: 661px" class="wp-caption aligncenter"><a href="https://sibeeshpassion.com/wp-content/uploads/2018/12/Create-APP-Package.jpg"><img decoding="async" aria-describedby="caption-attachment-13434" class="size-full wp-image-13434" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Create-APP-Package.jpg" alt="Create APP Package" width="651" height="211" srcset="/wp-content/uploads/2018/12/Create-APP-Package.jpg 651w, /wp-content/uploads/2018/12/Create-APP-Package-300x97.jpg 300w, /wp-content/uploads/2018/12/Create-APP-Package-400x130.jpg 400w" sizes="(max-width: 651px) 100vw, 651px" /></a><p id="caption-attachment-13434" class="wp-caption-text">Create APP Package</p></div></p>
<h2>Adding APPX to the Existing FFU</h2>
<p>As we have our own package and FFU image ready, we can go ahead and add this package to our FFU now. To do that open the IoTCorePShell, if you are not sure about how to open this, please check my previous article. Now let&#8217;s create a package for our app.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null">newappxpkg "C:\Users\SibeeshVenu\source\repos\Windows-iotcore-samples.git\Samples\HelloWorld\CS\AppPackages\HelloWorld_1.0.0.0_ARM_Test\HelloWorld_1.0.0.0_ARM.appx" fga Appx.HelloWorld</pre>
<p>Please be noted that the &#8220;fga&#8221; is an indication that your application is a foreground application, if your application is a background application, you should use &#8220;bgt&#8221; instead of &#8220;fga&#8221;.</p>
<blockquote><p>Please make sure that your FFU image has at least one Foreground application in it. You will always see the blue spinning dots after connecting the monitor to the Raspberry Pi if you have only background application in your image.  So you should consider having a registered fgt as well in your image.</p></blockquote>
<p>You will not be able to understand what exactly happens if there any problems if you have only a background application in your image. Trust me, I had spent many hours looking at the blue screen hoping that my application will show up there.</p>
<p>The above command will create a new folder in your workspace, in our case it is at C:\OEE\Source-arm\Packages\Appx.HelloWorld. It will also copy the appx files and its dependencies from the folder we are specifying in the command and generates a customizations.xml file as well as a package xml file that is used to build the package.</p>
<p><div id="attachment_13435" style="width: 584px" class="wp-caption aligncenter"><a href="https://sibeeshpassion.com/wp-content/uploads/2018/12/newappxpkg-output.jpg"><img decoding="async" aria-describedby="caption-attachment-13435" class="size-full wp-image-13435" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/newappxpkg-output.jpg" alt="newappxpkg output" width="574" height="433" srcset="/wp-content/uploads/2018/12/newappxpkg-output.jpg 574w, /wp-content/uploads/2018/12/newappxpkg-output-300x226.jpg 300w, /wp-content/uploads/2018/12/newappxpkg-output-400x302.jpg 400w" sizes="(max-width: 574px) 100vw, 574px" /></a><p id="caption-attachment-13435" class="wp-caption-text">newappxpkg output</p></div></p>
<p>This will also create a new entry as follows in the OEMFM.xml file.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null">&lt;PackageFile Path="%PKGBLD_DIR%" Name="%OEM_NAME%.Appx.HelloWorld.cab"&gt;
        &lt;FeatureIDs&gt;
          &lt;FeatureID&gt;APPX_HELLOWORLD&lt;/FeatureID&gt;
        &lt;/FeatureIDs&gt;
      &lt;/PackageFile&gt;</pre>
<p>Now let&#8217;s just build our package.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null">PS C:\OEE&gt;buildpkg Appx.HelloWorld
Processing Appx.HelloWorld.wm.xml
True
IoTCorePShell arm 10.0.0.0 Test</pre>
<p>Now you should be able to see your package.cab file in the build directory C:\OEE\Build\arm\pkgs.  Let&#8217;s add the feature APPX_HELLOWORLD to our product OEEIoTCore now.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null">PS C:\OEE&gt;addfid OEEIoTCore Test APPX_HELLOWORLD -OEM
IoTCorePShell arm 10.0.0.0 Test</pre>
<p>You can also remove any feature from any product by using &#8220;removefid&#8221; command. As we have added our feature, now it is time to build our image.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null">PS C:\OEE&gt;buildimage OEEIoTCore Test</pre>
<p>Please be noted that this may take some time, and once it is done, you will be getting an output as below.</p>
<p><div id="attachment_13436" style="width: 660px" class="wp-caption aligncenter"><a href="https://sibeeshpassion.com/wp-content/uploads/2018/12/buildimage.png"><img decoding="async" aria-describedby="caption-attachment-13436" class="size-full wp-image-13436" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/buildimage.png" alt="buildimage" width="650" height="479" srcset="/wp-content/uploads/2018/12/buildimage.png 650w, /wp-content/uploads/2018/12/buildimage-300x221.png 300w, /wp-content/uploads/2018/12/buildimage-400x295.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-13436" class="wp-caption-text">buildimage</p></div></p>
<p>The new image will be available in your build folder (C:\OEE\Build\arm\OEEIoTCore\Test). Now you can write this FFU image with your application as <a href="https://sibeeshpassion.com/raspberry-pi-sd-card-provisioning-with-windows-10-iot-core-create-ffu-image-and-flash/#writing-flashing-the-ffu-image-to-sd-card">mentioned in my previous article</a>.</p>
<p>Now that our OS is flashed and it is time to connect the SD card to the Raspberry Pi. Once that is done, you can see that your application is running in <a href="https://sibeeshpassion.com/setting-up-your-raspberry-pi-with-microsoft-windows-10-iot-core/#login-to-device-portal">your device portal</a>.</p>
<p><div id="attachment_13437" style="width: 660px" class="wp-caption aligncenter"><a href="https://sibeeshpassion.com/wp-content/uploads/2018/12/Custom-Package-in-Device-Portal.jpg"><img decoding="async" aria-describedby="caption-attachment-13437" class="size-full wp-image-13437" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Custom-Package-in-Device-Portal.jpg" alt="Custom Package in Device Portal" width="650" height="309" srcset="/wp-content/uploads/2018/12/Custom-Package-in-Device-Portal.jpg 650w, /wp-content/uploads/2018/12/Custom-Package-in-Device-Portal-300x143.jpg 300w, /wp-content/uploads/2018/12/Custom-Package-in-Device-Portal-400x190.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-13437" class="wp-caption-text">Custom Package in Device Portal</p></div></p>
<p>Now let&#8217;s add a background application and follow the same procedure.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null">PS C:\OEE&gt;newappxpkg "C:\Users\SibeeshVenu\SourceCode\OEE\ml.OEE.Pi.Windows\ml.OEE.Pi.Windows.BeaconDetector\AppPackages\ml.OEE.Pi.Windows.BeaconDetector_1.0.3.0_ARM_Test\ml.OEE.Pi.Windows.BeaconDetector_1.0.3.0_ARM.appx" bgt Appx.Beacon</pre>
<p>I am sure you will be able to see your background application in your device portal, once you had followed the steps correctly.</p>
<p><div id="attachment_13442" style="width: 660px" class="wp-caption alignnone"><a href="https://sibeeshpassion.com/wp-content/uploads/2018/12/Background-Application-in-IoT-Device-Portal.jpg"><img decoding="async" aria-describedby="caption-attachment-13442" class="size-full wp-image-13442" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Background-Application-in-IoT-Device-Portal.jpg" alt="Background Application in IoT Device Portal" width="650" height="336" srcset="/wp-content/uploads/2018/12/Background-Application-in-IoT-Device-Portal.jpg 650w, /wp-content/uploads/2018/12/Background-Application-in-IoT-Device-Portal-300x155.jpg 300w, /wp-content/uploads/2018/12/Background-Application-in-IoT-Device-Portal-400x207.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-13442" class="wp-caption-text">Background Application in IoT Device Portal</p></div></p>
<h2>Conclusion</h2>
<p>Wow!. Now we have learned,</p>
<ul>
<li>how we can generate APPX package of our UWP application</li>
<li>how to add the new feature to the existing IoT Core FFU image</li>
<li>how to write the same to an SD card</li>
<li>how to manage the new application in Device Portal</li>
</ul>
<h2><span id="your-turn-what-do-you-think">Your turn. What do you think?</span></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://www.sibeeshpassion.com/raspberry-pi-sd-card-provisioning-with-windows-10-iot-core-adding-packages-to-the-existing-ffu-image/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Raspberry PI SD Card Provisioning with Windows 10 IoT Core &#8211; Create FFU Image and Flash</title>
		<link>https://www.sibeeshpassion.com/raspberry-pi-sd-card-provisioning-with-windows-10-iot-core-create-ffu-image-and-flash/</link>
					<comments>https://www.sibeeshpassion.com/raspberry-pi-sd-card-provisioning-with-windows-10-iot-core-create-ffu-image-and-flash/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Thu, 22 Nov 2018 08:41:04 +0000</pubDate>
				<category><![CDATA[IoT]]></category>
		<category><![CDATA[Raspberry PI]]></category>
		<category><![CDATA[diskpart]]></category>
		<category><![CDATA[DISM]]></category>
		<category><![CDATA[IoT Core]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[Raspberry PI SD Card Provisioning]]></category>
		<category><![CDATA[Windows 10 IoT Core]]></category>
		<category><![CDATA[Windows IoT core by DISM]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13388</guid>

					<description><![CDATA[[toc] Introduction In my previous article, we have seen how to Set Up Your Raspberry PI with Microsoft Windows 10 IoT Core. Yes, we were successful in flashing the Microsoft Windows 10 IoT Core OS to our Raspberry PI, but let&#8217;s try something very handy this time. The main topic we are going to discuss here in this article is SD Card Provisioning. I understand that you have one Raspberry PI with a working OS in it, whether it is a Microsoft IoT  OS or Raspbian. And you might also have an application which runs in your Raspberry Pi. That&#8217;s good. But [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h2>Introduction</h2>
<p>In my previous article, we have seen how to <a href="https://sibeeshpassion.com/setting-up-your-raspberry-pi-with-microsoft-windows-10-iot-core/">Set Up Your Raspberry PI with Microsoft Windows 10 IoT Core</a>. Yes, we were successful in flashing the Microsoft Windows 10 IoT Core OS to our <a href="https://sibeeshpassion.com/category/raspberry-pi/">Raspberry PI</a>, but let&#8217;s try something very handy this time. The main topic we are going to discuss here in this article is <em>SD Card Provisioning.</em> I understand that you have one Raspberry PI with a working OS in it, whether it is a Microsoft IoT  OS or Raspbian. And you might also have an application which runs in your Raspberry Pi. That&#8217;s good. But what if you have 100 Raspberry PI and you need to set up your Raspberry PIs for a production environment? Did you get the difficulties in your mind? In this article, we are going to start a series of articles on SD Card Provisioning. For now, let&#8217;s just start doing some amazing things. Let&#8217;s just start then.</p>
<h2>Background</h2>
<p>Yeah, I am glad that you have a Raspberry PI with Windows 10 IoT core OS. While setting up your OS, you might have downloaded the IoT Dashboard and flashed the IoT OS to your SD card manually. As I mentioned in the Introduction, this is not a normal scenario when you want to connect multiple (let&#8217;s say 100) Raspberry PIs. Flashing the OS by using the Dashboard application might not be a good idea in this case. What should we do then? That&#8217;s where PowerShell come into the play. Yes, we are going to try out some PowerShell commands to do all those mentioned jobs for us.</p>
<h2>Prerequisites</h2>
<p>To do the wonderful things, we always need some prerequisites.  You can always see all the prerequisites from <a href="https://docs.microsoft.com/en-us/windows-hardware/manufacture/iot/set-up-your-pc-to-customize-iot-core">here</a>. But, in this part, we are going to be needed only the preceding tools.</p>
<ol>
<li>Windows Assessment and Deployment Kit (Windows ADK)</li>
<li>Windows Driver Kit (WDK) 10</li>
<li>IoT Core ADK Add-Ons</li>
<li>Windows 10 IoT Core Packages</li>
<li>The Raspberry Pi BSP</li>
</ol>
<h2>Creating the Base Windows IoT FFU Image</h2>
<p>I assume that you had already gone through the Prerequisites and followed the instructions. If not, please check again.</p>
<h3>Create a Workspace</h3>
<p>To get started here, please go to the cloned location of the repository iot-adk-addonkit, where you will find a Windows Command Script IoTCorePShell.cmd. Double click on the same file will open a PowerShell with administrative privilege. Now, this is where the game starts. Once it opens it will do some initial process for us.</p>
<p><div id="attachment_13389" style="width: 661px" class="wp-caption aligncenter"><a href="https://sibeeshpassion.com/wp-content/uploads/2018/11/Running-IoTCorePShell.cmd_.png"><img decoding="async" aria-describedby="caption-attachment-13389" class="size-full wp-image-13389" src="https://sibeeshpassion.com/wp-content/uploads/2018/11/Running-IoTCorePShell.cmd_.png" alt="Running IoTCorePShell.cmd" width="651" height="230" srcset="/wp-content/uploads/2018/11/Running-IoTCorePShell.cmd_.png 651w, /wp-content/uploads/2018/11/Running-IoTCorePShell.cmd_-300x106.png 300w, /wp-content/uploads/2018/11/Running-IoTCorePShell.cmd_-400x141.png 400w" sizes="(max-width: 651px) 100vw, 651px" /></a><p id="caption-attachment-13389" class="wp-caption-text">Running IoTCorePShell.cmd</p></div></p>
<p>Now let&#8217;s create a workspace now.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null">New-IoTWorkspace C:\Workspacefolder oemname arm
(or) new-ws C:\workspacefolder oemname arm</pre>
<p><div id="attachment_13390" style="width: 661px" class="wp-caption aligncenter"><a href="https://sibeeshpassion.com/wp-content/uploads/2018/11/new-ws-command.png"><img decoding="async" aria-describedby="caption-attachment-13390" class="size-full wp-image-13390" src="https://sibeeshpassion.com/wp-content/uploads/2018/11/new-ws-command.png" alt="new-ws command" width="651" height="340" srcset="/wp-content/uploads/2018/11/new-ws-command.png 651w, /wp-content/uploads/2018/11/new-ws-command-300x157.png 300w, /wp-content/uploads/2018/11/new-ws-command-400x209.png 400w" sizes="(max-width: 651px) 100vw, 651px" /></a><p id="caption-attachment-13390" class="wp-caption-text">new-ws command</p></div></p>
<p>Now we have created a workspace successfully. Please be noted that the BSPPKG_DIR is &#8220;C:\Program Files (x86)\Windows Kits\10\MSPackages\retail\arm\fre&#8221;. I strongly recommend you to check that folder whether you have contents in it or not if there is no content you might haven&#8217;t installed the packages mentioned in the prerequisites.</p>
<h3>Build BSP</h3>
<p>Now it is time to think about the BSP aka Board Support Package. As we already know that we are using Raspberry PI, we can directly download the RPi_BSP.zip file from the <a href="https://github.com/ms-iot/iot-adk-addonkit/releases">GitHub release page</a>. Then you can perform the below commands.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null">Import-IoTBSP RPi2 C:\Downloads\RPi_BSP.zip
(or) importbsp RPi2 C:\Downloads\RPi_BSP.zip
buildpkg RPi2</pre>
<p>If everything is right, you should see an output as below.</p>
<p><div id="attachment_13391" style="width: 663px" class="wp-caption aligncenter"><a href="https://sibeeshpassion.com/wp-content/uploads/2018/11/Import-Raspberry-BSP.png"><img decoding="async" aria-describedby="caption-attachment-13391" class="size-full wp-image-13391" src="https://sibeeshpassion.com/wp-content/uploads/2018/11/Import-Raspberry-BSP.png" alt="Import Raspberry BSP" width="653" height="92" srcset="/wp-content/uploads/2018/11/Import-Raspberry-BSP.png 653w, /wp-content/uploads/2018/11/Import-Raspberry-BSP-300x42.png 300w, /wp-content/uploads/2018/11/Import-Raspberry-BSP-400x56.png 400w" sizes="(max-width: 653px) 100vw, 653px" /></a><p id="caption-attachment-13391" class="wp-caption-text">Import Raspberry BSP</p></div></p>
<h3>Build Packages</h3>
<p>Once you have created the workspace and extracted the BSP, it is time to build all of our packages.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null">New-IoTCabPackage All
(or) buildpkg all</pre>
<p>If you miss this step before you go to the next step, you will get an error as follows when you build your image.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null">info: Trying to load file 'C:\OEEWorkspace\Build\arm\InputFMs\OEMFMFileList.xml' as a FM file list ... fatal error : Error: Missing package: C:\OEEWorkspace\Build\arm\pkgs\test.OEM.Sample.cab
info: Trying to load file 'C:\OEEWorkspace\Build\arm\InputFMs\RPi2FMFileList.xml' as a FM file list ... fatal error : Error: Missing package: 
</pre>
<p>You will also end up in the similar <a href="https://github.com/ms-iot/iot-adk-addonkit/issues/139">GitHub issue</a>. Trust me, finding the root cause of this issue took me some hours and at the end, I answered my findings here in <a href="https://stackoverflow.com/questions/53414482/info-trying-to-load-file-oemfmfilelist-xml-as-a-fm-file-list-fatal-error/53414483#53414483">StackOverflow</a>.</p>
<p><div id="attachment_13392" style="width: 436px" class="wp-caption aligncenter"><a href="https://sibeeshpassion.com/wp-content/uploads/2018/11/Building-all-the-packages.png"><img decoding="async" aria-describedby="caption-attachment-13392" class="size-full wp-image-13392" src="https://sibeeshpassion.com/wp-content/uploads/2018/11/Building-all-the-packages.png" alt="Building all the packages" width="426" height="385" srcset="/wp-content/uploads/2018/11/Building-all-the-packages.png 426w, /wp-content/uploads/2018/11/Building-all-the-packages-300x271.png 300w, /wp-content/uploads/2018/11/Building-all-the-packages-400x362.png 400w" sizes="(max-width: 426px) 100vw, 426px" /></a><p id="caption-attachment-13392" class="wp-caption-text">Building all the packages</p></div></p>
<p>Once the build is successful, you should be able to see the cab files in your workspace location, in my case, it is C:\OEE\Build\arm\pkgs.</p>
<h3>Create a Product</h3>
<p>Now let&#8217;s create a new Product, consider this as the device for which we are building an image for. We will be using the BSP we have extracted for this step.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null">Add-IoTProduct ProductA RPi2
(or) newproduct MyProductA RPi2</pre>
<p>You will be asked the Manufacturer Name (OEM Name), Family, SKU, BaseboardManufacturer, and BaseboardProduct. You can get the BaseProductName from your Workspace location, in my case C:\OEE\Source-arm\BSP. You can see the sample command here in the preceding image.</p>
<p><div id="attachment_13393" style="width: 659px" class="wp-caption aligncenter"><a href="https://sibeeshpassion.com/wp-content/uploads/2018/11/Creating-a-new-Product.png"><img decoding="async" aria-describedby="caption-attachment-13393" class="size-full wp-image-13393" src="https://sibeeshpassion.com/wp-content/uploads/2018/11/Creating-a-new-Product.png" alt="Creating a new Product" width="649" height="210" srcset="/wp-content/uploads/2018/11/Creating-a-new-Product.png 649w, /wp-content/uploads/2018/11/Creating-a-new-Product-300x97.png 300w, /wp-content/uploads/2018/11/Creating-a-new-Product-400x129.png 400w" sizes="(max-width: 649px) 100vw, 649px" /></a><p id="caption-attachment-13393" class="wp-caption-text">Creating a new Product</p></div></p>
<p>The command shown in the image will generate a new Product in the Workspace location C:\OEE\Source-arm\Products\OEEIoTCore.</p>
<p><div id="attachment_13394" style="width: 564px" class="wp-caption aligncenter"><a href="https://sibeeshpassion.com/wp-content/uploads/2018/11/Add-IoTProduct-Output.png"><img decoding="async" aria-describedby="caption-attachment-13394" class="size-full wp-image-13394" src="https://sibeeshpassion.com/wp-content/uploads/2018/11/Add-IoTProduct-Output.png" alt="" width="554" height="412" srcset="/wp-content/uploads/2018/11/Add-IoTProduct-Output.png 554w, /wp-content/uploads/2018/11/Add-IoTProduct-Output-300x223.png 300w, /wp-content/uploads/2018/11/Add-IoTProduct-Output-400x297.png 400w" sizes="(max-width: 554px) 100vw, 554px" /></a><p id="caption-attachment-13394" class="wp-caption-text">Add-IoTProduct Output</p></div></p>
<h3>Build the Image</h3>
<p>We are almost done, let&#8217;s eject all the removable devices from the system and then run the below command.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null">New-IoTFFUImage &lt;product name&gt; Test
(or)buildimage &lt;product name&gt; Test</pre>
<p>This command will give you the FFU image with your base image.</p>
<p><div id="attachment_13396" style="width: 660px" class="wp-caption aligncenter"><a href="https://sibeeshpassion.com/wp-content/uploads/2018/11/Building-Image-and-Generate-FFU-File.png"><img decoding="async" aria-describedby="caption-attachment-13396" class="size-full wp-image-13396" src="https://sibeeshpassion.com/wp-content/uploads/2018/11/Building-Image-and-Generate-FFU-File.png" alt="Building Image and Generate FFU File" width="650" height="432" srcset="/wp-content/uploads/2018/11/Building-Image-and-Generate-FFU-File.png 650w, /wp-content/uploads/2018/11/Building-Image-and-Generate-FFU-File-300x199.png 300w, /wp-content/uploads/2018/11/Building-Image-and-Generate-FFU-File-400x266.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-13396" class="wp-caption-text">Building Image and Generate FFU File</p></div></p>
<p>You can also see the logs in your workspace location in the build folder. The generated FFU image(Flash.ffu) will be available at C:\OEE\Build\arm\OEEIoTCore\Test folder.</p>
<h2>Writing/Flashing the FFU Image to SD Card</h2>
<p>Wow!, now we have a fully functional FFU image and the only thing pending is to write some bat commands to flash it to SD card, you can use the <a href="https://docs.microsoft.com/en-us/windows/iot-core/connect-your-device/dism">DISM</a>. Let&#8217;s create a text file called format.txt and write some commands as preceding.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null">select disk 1
clean
create partition primary
select partition 1
active
format fs=fat32 quick
assign
exit
</pre>
<p>As you can see that we are selecting the disk 1, considering the fact that only one removable disk is been connected to your machine.  Then we format the disk. This format.txt file will be used in our bat file write.bat.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null">echo off
REM Start formatting
diskpart /s format.txt &gt;log.txt

REM Start flashing
dism.exe /Apply-Image /ImageFile:Flash.ffu /ApplyDrive:\\.\PhysicalDrive1 /SkipPlatformCheck /Quiet

ECHO Finish
</pre>
<p>The logs will be added to the file called log.txt. The command ImageFile:Flash.ffu is the place where we assign our FFU image. Now let&#8217;s just go to the folder where these three files are been placed and open a command prompt in administrative power.</p>
<ul>
<li>write.bat</li>
<li>format.txt</li>
<li>flash.ffu</li>
</ul>
<p><div id="attachment_13399" style="width: 659px" class="wp-caption aligncenter"><a href="https://sibeeshpassion.com/wp-content/uploads/2018/11/Flash-IoT-Core-by-Commands.png"><img decoding="async" aria-describedby="caption-attachment-13399" class="size-full wp-image-13399" src="https://sibeeshpassion.com/wp-content/uploads/2018/11/Flash-IoT-Core-by-Commands.png" alt="Flash IoT Core by Commands" width="649" height="250" srcset="/wp-content/uploads/2018/11/Flash-IoT-Core-by-Commands.png 649w, /wp-content/uploads/2018/11/Flash-IoT-Core-by-Commands-300x116.png 300w, /wp-content/uploads/2018/11/Flash-IoT-Core-by-Commands-400x154.png 400w" sizes="(max-width: 649px) 100vw, 649px" /></a><p id="caption-attachment-13399" class="wp-caption-text">Flash IoT Core by Commands</p></div></p>
<h2>Connect SD Card to Raspberry PI and then Raspberry PI to the Network</h2>
<p>Now that our OS is flashed and it is time to connect the SD card to the Raspberry PI and connect a monitor, mouse, keyboard, ethernet to the Raspberry PI. You will see the default IoT core application running. You can also check in the device portal using the IoT Dashboard application, if you are not sure how, please read my previous post.</p>
<h2>Conclusion</h2>
<p>Wow!. Now we have learned,</p>
<ul>
<li>how we can generate the IoT core FFU image using PowerShell</li>
<li>how to write the same to an SD card.</li>
</ul>
<p>Is that all? No, in the next article we will learn</p>
<ul>
<li>how we can add our app package to this FFU image which can be used in many Raspberry PI</li>
<li>how to generate the FFU image on demand with some chained PowerShell commands.</li>
<li>how to use other mechanisms to write the FFU image to the disk</li>
</ul>
<h2><span id="your-turn-what-do-you-think">Your turn. What do you think?</span></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://www.sibeeshpassion.com/raspberry-pi-sd-card-provisioning-with-windows-10-iot-core-create-ffu-image-and-flash/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
