C#.NET

Introduction to IoT Hub

December 9, 2016 .NET, AMQP, Analytics, Azure, C#.NET, Cloud to Device, Communication Protocols, Connected, Connectivity, Contrained Networks/Devices, Device to Cloud, Device Twin, Emerging Technologies, Geolocation, HTTP 1.1, Identity of Things (IDoT), Internet Appliance, IoT, IoT Hub, IoT Privacy, IoT Security, KnowledgeBase, machine-to-machine (M2M), Machines, Microsoft, MQTT, Stream Analytics, Visual Studio 2015, Visual Studio 2017, Visual Studio Code, VisualStudio, VS2015, VS2017, Windows, Windows 10, Windowz Azure No comments

IoT Hub is a fully managed service from Microsoft Azure  as part of Azure IoT Suite that enables reliable and secure bi-directional communications between millions of IoT devices and your solution back end.

Azure IoT Hub are designed to provide following capabilities:

  • Multiple device-to-cloud and cloud-to-device communication options, including one-way messaging, file transfer, and request-reply methods.
  • Built-in declarative message routing to other Azure services.
  • A queryable store for device metadata and synchronized state information.
  • Secure communications and access control using per-device security keys or X.509 certificates.
  • Extensive monitoring for device connectivity and device identity management events.
  • Provides device libraries for the most popular languages and platforms.

hubarchitecture

Why IoTHub?

IoT Hub and the device libraries help you to meet the challenges of how to reliably and securely connect devices to the solution back end.

Real-world  IoT devices mostly have the following constaints:

  • Embedded systems.with minimal or no user interaction.
  • Remotely available, with less physical access. .
  • Reachable through the solution back end.
  • Limited power and processing capabilities
  • Intermittent, slow, or expensive network connectivity.
  • Use proprietary, custom, or industry-specific application protocols.
  • Created using a large set of popular hardware and software platforms.

IoT Hub provide solutions to meet all the above constraints of a connected device. In addition it also provides scale,  scalability and reliability. It also addresses most of the connectivity challenges through following capabilities.

  1. Device Twin:  With Device twins, you can store, synchronize, and query device metadata and state information, and these are stored in JSON format.  IoT Hub persists a device twin for each device that you connect to IoT Hub. This feature was introduced in Novemeber’16 with General availability of Iot Hub.
  2. Per-device authentication and secure connectivity. You can provision each device with its own security key to enable it to connect to IoT Hub.There by enabling you to manage or block devices as desired.
  3. Route device-to-cloud messages to Azure services based on declarative rules. IoT Hub enables you to define message routes based on routing rules to control where your hub sends device-to-cloud messages.
  4. Monitoring of device connectivity operations. You can receive detailed operation logs about device identity management operations and device connectivity events.
  5. Device libraries for most of the platforms with support for Programming languages like C#, Java, Python and JavaScript.
  6. Support for latest and widely used IoT protocols and provides extensibility: Protocols such as AMQP 1.1 or HTTP 1.1 and MQTT 3.1 are supported. We could also provide additional protocol translation using Azure IoT Gateway SDK at Device/Field/Protocol  Gateway layer.

Azure IoT Hub can bring more value to organizations to bring in their field devices to cloud with real-time data capture and bi-directional communication. It solves the problem of lack of proper communication infrastructure for devices to communicate or operate on real-time basis.  Pay per use, less investment infrastructure that would let you scale as you grow.

Do you feel some similarities between IoT Hub and Event Hubs service already exists as part of Azure Platform?  In my later articles I would be covering some of the major differences.

Useful References:

Visual Studio 2015 Update 3 – Download

June 27, 2016 .NET, .NET Core 1.0, .NET Framework, .NET Framework 4.5, .NET Framework 4.5.2, .NET Framework 4.6, ASP.NET, ASP.NET 5.0, ASP.NET Core 1.0, ASP.NET MVC, C#.NET, Community, JavaScript, Microsoft, MSDN, Trial Downloads, Updates, Visual Studio 2015, Visual Studio Code, Visual Studio SDK, VisualStudio, VS2015, WCF, Web API v2.0, Windows, Windows 10, Windows 7, Windows 8, Windows 8.1, Windows Azure, Windows Azure Development, Windows Phone Development, Windows Phone SDK, Windows Store Development, WPF, WWF, XAML No comments

Today Microsoft has released Update 3 for Visual Studio 2015. Visual Studio 2015 Update 3 includes a variety of capability improvements and bug fixes. To find out what’s new, see the Visual Studio 2015 Update 3 Release Notes. For a list of fixed bugs and known issues, see the Visual Studio 2015 Update 3 MSDN Article.

Download:
Visual Studio Community 2015 with Update 3 – Web Installer –  ISO
Visual Studio Enterprise 2015 with Update 3 – Web Install –  ISO
Visual Studio Professional 2015 with Update 3 – Web Installer –  ISO
Visual Studio 2015 Update 3 – Web InstallerISO
Visual Studio Team Foundation Server 2015 with Update 3 – Web Installer –  ISO
Visual Studio Test Professional 2015 – Web InstallerISO
Visual Studio Express 2015 for Windows 10 – here
Visual Studio Express 2015 for Web – here
Visual Studio Express 2015 for Desktop – here

.NET Core 1.0 and ASP.NET Core 1.0 released (RTM)

June 27, 2016 .NET, .NET Core 1.0, ASP.NET, ASP.NET Core 1.0, C#.NET, Microsoft No comments

Microsoft has released final version of .NET Core 1.0 and ASP.NET Core 1.0 today. During May 2016, Microsoft has released RC2 version of the same framework hinting the release of final version soon, within a month Microsoft has released final version (Release to Manufacture).

With this release, you can start building your next application today using .NET Core, for Windows, Linux, Android, macOS, and iOS. 

Download .NET Core from https://www.microsoft.com/net/core

Supported Development IDEs:

Go through following links to learn more about .NET Core and Getting Started with Development:

Back to Basics : Singleton Design Pattern using System.Lazy type

June 25, 2015 .NET, .NET Framework, .NET Framework 4.5, .NET Framework 4.5.2, .NET Framework 4.6, Back-2-Bascis, BCL(Base Class Library), C#.NET, Codes, Design Patterns, KnowledgeBase, Microsoft, Portable Class Library, Visual Studio 2013, Visual Studio 2015, VisualStudio, VS2010, VS2012, VS2013, VS2015, Windows No comments

This article takes you to a simpler/alternative approach in making a Singleton Design Pattern implementation using System.Lazy class rather that using our traditional approach.

Singleton Design Pattern implementation without lazy initialization:

  • This code is thread safe enabled
 /// <summary>
    /// Singleton class 
    /// </summary>
    public class AppConfig
    {

        private AppConfig()
        {

        }

        /// <summary>
        /// Gets the current date time.
        /// </summary>
        /// <value>
        /// The current date time.
        /// </value>
        public DateTime CurrentDateTime
        {
            get
            {
                return DateTime.Now;
            }
        }
        /// <summary>
        /// The _config
        /// </summary>
        private static AppConfig _config;

        /// <summary>
        /// The pad lock for maintaining a thread lock.
        /// </summary>
        private static readonly Object padLock = new object();

        /// <summary>
        /// Gets the instance.
        /// </summary>
        /// <value>
        /// The instance.
        /// </value>
        public static AppConfig Instance
        {
            get
            {

                if (_config == null)
                {
                    lock (padLock) // making thread-safe
                    {
                        //{
                        if (_config == null) //second level check to make sure, within the short span, another concurent thread didnt initialize the object. 
                        {
                            _config = new AppConfig();
                        }
                    }
                }
                //}

                return _config;
            }
        }
    }

This approach ensures that only one instance is created and only when the instance is needed. Also, the variable is declared to be volatile to ensure that assignment to the instance variable completes before the instance variable can be accessed. Lastly, this approach uses a padLock instance to lock on, rather than locking on the type itself, to avoid deadlocks.

Another variant using Lazy initialization using static constructor and thread safe since initialization is handled during runtime within readonly variable declaration.  This will be thread-safe any ways.

 /// <summary>
    /// a Simpler version of Singleton class with lazy initialization.
    /// </summary>
    public class AppConfigLazy1
    {
        // static holder for instance, will not get initialized until first use, due to static contructor.
        private static readonly AppConfigLazy1 _instance = new AppConfigLazy1();

        /// <summary>
        /// Prevents a default instance of the <see cref=&quot;AppConfigLazy1&quot;/> class from being created.
        /// </summary>
        private AppConfigLazy1()
        {

        }

        /// <summary>
        /// for Lazy Initializes the <see cref=&quot;AppConfigLazy1&quot;/> class.
        /// </summary>
        static AppConfigLazy1()
        {

        }


        public static AppConfigLazy1 Instance
        {
            get
            {
                return _instance;
            }
        }
    }

Now with .NET 4.0 onwards there is a better way of doing this using .NET Runtime methods using System.Lazy type. System.Lazy type is mainly used in Entity Framework context, but we can use the same in implementing lazy loading where ever we have to deal with memory intensive object or collection of objects.

System.Lazy type  guarantees thread-safe lazy-construction. (By default, all public and protected members of the Lazy class are thread safe and may be used concurrently from multiple threads.)

.NET Framework Support in: 4.6, 4.5, 4
/// <summary>
    /// a Simpler version of Singleton class with lazy initialization.
    /// </summary>
    public class AppConfigLazy2
    {
        // static holder for instance, need to use lambda to construct since constructor private
        private static readonly Lazy<AppConfigLazy2> _instance = new Lazy<AppConfigLazy2>(() => new AppConfigLazy2());

        /// <summary>
        /// Prevents a default instance of the <see cref=&quot;AppConfigLazy2&quot;/> class from being created.
        /// </summary>
        private AppConfigLazy2()
        {

        }
        
        public static AppConfigLazy2 Instance
        {
            get
            {
                return _instance.Value;
            }
        }


        /// <summary>
        /// Gets the current date time.
        /// </summary>
        /// <value>
        /// The current date time.
        /// </value>
        public DateTime CurrentDateTime
        {
            get
            {
                return DateTime.Now;
            }
        }
    }
    

That’s more than one way doing Singleton Pattern Implementation right?, hope that was helpful to you  Some reference links are given below:

Static vs Singleton Classes

May 20, 2015 .NET, .NET Framework, C#.NET, Design Patterns, Interview Qns, KnowledgeBase, Microsoft No comments

Recently while I was attending an interview I came across a question Static vs Singleton. Though I know the differences I couldn’t answer it properly, as I was not refreshed my programming knowledge before the interview.

I would like to quote a reference to Jalpesh’s blog article (www.dotnetjalps.com) explaining the difference:

Difference between Static and Singleton classes:

  1. A singleton classes allowed to create a only single instance or particular class. That instance can be treated as normal object. You can pass that object to a method as parameter or you can call the class method with that Singleton object. While static class can have only static methods and you can not pass static class as parameter.
  2. We can implement the interfaces with the Singleton class while we can not implement the interfaces with static classes.
  3. We can clone the object of Singleton classes we can not clone the object of static classes.
  4. Singleton objects stored on heap while static class stored in stack.
  5. A Singleton class can extend the classes(support inheritance) while static class can not inherit classes.
  6. Singleton class can initialize lazy way while static class initialize when it loaded first
  7. Static classes are sealed class while Single ton classes are not sealed.

Credits to Jalpesh Vadgama  – “Computer Geek, Developer, Mentor, Life long learner, 10+ Years of Experience in Microsoft.NET Technologies, Awarded Microsoft Mvp(C#) for year 2010,11 and 2012.”

Microsoft Developer Program for IoT & Windows 10 IoT Core Insider Preview

May 3, 2015 .NET, .NET Framework, C#.NET, Cloud Computing, Embedded, Internet of Things, IoT, Microsoft, Tech-Trends, Virtualization, VisualStudio, VS2015, Windows, Windows 10, Windows 8.1 No comments

Microsoft has introduced a new developer program to enable the developers working on Internet of Things(IoT) based implementations.  As part of this program developers would be able to try out – Windows 10 IoT Core Insider Preview.

If you are an enthusiast working on IoT, you can signup @ https://www.windowsondevices.com/signup.aspx allows you to be early adopters of Windows on  Devices program.

Following Devices are currently supported by Windows 10 IoT Core Insider Preview.

<code>  &lt;p&gt;&lt;a href="http://go.microsoft.com/fwlink/p/?linkID=532948"&gt;Learn more about Windows IoT devices&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="github.io/content/GetStarted.htm" target="_blank"&gt;Microsoft Github repository&lt;/a&gt; for IoT, where you can find lots of samples and documentation. &lt;a title="http://ms-iot.github.io/content/GetStarted.htm" href="http://ms-iot.github.io/content/GetStarted.htm"&gt;http://ms-iot.&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;What is Internet of Things?&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.nitrix-reloaded.com/wp-content/uploads/2015/05/theinternetofthings.jpg"&gt;&lt;img title="Print" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="Print" src="http://www.nitrix-reloaded.com/wp-content/uploads/2015/05/theinternetofthings_thumb.jpg" width="386" height="235"/&gt;&lt;/a&gt;&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;Part of the &lt;a href="/wp-content/uploads/2015/05/Cloud-computing"&gt;Cloud computing&lt;/a&gt; glossary: 
</code>

The Internet of Things (IoT) is a scenario in which objects, animals or people are provided with unique identifiers and the ability to transfer data over a network without requiring human-to-human or human-to-computer interaction. IoT has evolved from the convergence of wireless technologies, micro-electromechanical systems (MEMS) and the Internet.

Below is a high level technology roadmap as per Wikipedia: