Today I will show you how to initiate a manual failover and how to perform a fallback on your IOT-hub

By default, the IoT Hub service provides intra-region High Availability by implementing redundancies in almost all layers of the service. The SLA published by the IoT Hub service is achieved by making use of these redundancies. No additional work is required by the developers of an IoT solution to take advantage of these High Availability features.

Although IoT Hub offers a reasonably high uptime guarantee, transient failures can still be expected as with any distributed computing platform. If you’re just getting started with migrating your solutions to the cloud from an on-premise solution, your focus needs to shift from optimizing “mean time between failures” to “mean time to recover”. In other words, transient failures are to be considered normal while operating with the cloud in the mix. Appropriate retry policies must be built into the components interacting with a cloud application to deal with transient failures.

Manual failover is a feature of the IoT Hub service that allows customers to failover their hub’s operations from a primary region to the corresponding Azure geo-paired region. Manual failover can be done in the event of a regional disaster or an extended service outage. You can also perform a planned failover to test your disaster recovery capabilities, although it is recommended that a test IoT hub is used rather than one running in production as the solution is unavailable during the failover process.

Azure IoT Hub Manual Failover You should note that there is a limit of two failovers and two failbacks per day for an IoT Hub.

Complete the following steps:
1. In your Web browser, to open your Azure portal, navigate to the portal.azure.com. When you log into Azure you will arrive at the Azure portal home page for your Azure account.

2. In the top-left corner of your Azure portal, under Favorites click Resource groups.
3. In the Resource groups blade, select the resource group name you are using.
4. In the Resource group blade, in the list of resources, click the Storage account you have created.
5. Under Resiliency on the IoT Hub blade, click Manual failover (preview).
6. On the Manual Failover pane, read and note the warning: Use this feature to failover your IoT hub to the secondary location. This action will cause down time and telemetry loss to your solution.

This is a long running operation and could take several minutes to finish. Please exercise with caution when using it.

7. On the Manual failover pane, you see the IoT Hub Primary Location and the IoT Hub Secondary Location.

The primary location is initially set to the location you specified when you created the IoT hub, and always indicates the location in which the hub is currently active. The secondary location is the standard Azure geo-paired region that is paired to the primary location. You cannot change the location values.

8. At the top of the Manual failover pane, click Initiate failover.

9. On the Confirm manual failover pane note the warning: Warning! This action can’t be canceled. Your IoT hub will be activated in the secondary location.

In order to move your IoT hub back to the original location, you will have to trigger the failover again after the current operation succeeds.

10. Under Iot hub name, enter the name of your IoT hub and click OK. This confirms your desire to failover.

Note that you can use the mouse to select and copy the IoT hub name from another area of the web page. The amount of time it takes to perform the manual failover is proportional to the number of devices that are registered for your hub. For example, if you have 100,000 devices, it might take 15 minutes, but if you have five million devices, it might take an hour or longer.

While the manual failover process is running, there is a banner on the Manual Failover pane that tells you a manual failover is in progress. After a processing period, you will get a notification that your IoT Hub failover has been completed successfully. After it’s finished, the primary and secondary regions on the Manual Failover page are flipped and the hub is active again. Azure IoT Hub Failback After you have performed a manual failover, you can switch the hub’s operations back to the original primary region – this is called a failback. If you have just performed a failover, you must wait about an hour before you can request a failback. If you try to perform the failback in a shorter amount of time, an error message is displayed.

A failback is performed just like a manual failover.

These are the steps:
1. To perform a failback, return to the Iot Hub pane for your Iot hub.
2. Under Resiliency on the IoT Hub pane, click Manual failover.
3. At the top of the Manual failover pane, click Initiate failover. You see the Confirm manual failover pane.
4. In the Confirm manual failover pane, under Iot hub name, enter the name of your IoT hub and click OK.

As before, the amount of time it takes to perform the manual failover is proportional to the number of devices that are registered for your hub. For example, if you have 100,000 devices, it might take 15 minutes, but if you have five million devices, it might take an hour or longer. While the manual failover process is running, there is a banner on the Manual Failover pane that tells you a manual failover is in progress. After a processing period, you will get a notification that your IoT Hub failover has been completed successfully. After it’s finished, the primary and secondary regions on the Manual Failover page are flipped and the hub is active again.

Verify Device-to-Cloud Communication

Now you will verify that device-to-cloud communication is taking place by using the Serial Monitor in Visual Studio Code and checking your Azure Portal.

  1. Ensure that you have your GetStarted project opened in Visual Studio Code and that your device is connected to you PC.
  2. In Visual Studio Code, examine the status bar that runs along the bottom of the window.
  3. Hover your mouse pointer over each of the buttons on the status bar. You should see label appear that identifies the purpose associated with the buttons.
  4. Use the button labels to locate the following buttons:
    • Show Board Config
    • Open Serial Monitor
    • Select Serial Port
    The Open Serial Monitor button is the button displaying the icon that looks like a power plug.
  1. In Visual Studio Code, on the bottom status bar, click the Select Serial Port button.
  2. At the top of the Visual Studio Code window, notice the prompt asking you to “Select a serial port”.
  3. At the prompt, select the COM port labeled STMicroelectronics You may recall seeing the STMicroelectronics name pop up when you were configuring your MXChip device. The STMicroelectronics driver is used to communicate with the MXChip AZ3166 device.
  4. On the bottom status bar, click the Baud Rate button, and then click 115200 If your application is running successfully, you see something similar to the following:
  1. Open a browser window and navigate to your Azure portal: portal.azure.com You should see your dashboard and the Resources tile. If you don’t, verify that you are logged in with the Azure account and subscription that you are using.
  2. Open your IoT Hub, and review the information displayed on the Overview blade.
  3. Notice that the IoT Hub Usage tile shows you that messages are arriving at your IoT Hub.

Register Your MXChip Device with IoT Hub

Every IoT hub has an identity registry that stores information about the devices that are permitted to connect to it. Before a device can connect to an IoT hub, there must be an entry for that device in the IoT hub’s identity registry. A device must also authenticate with the IoT hub based on credentials stored in the identity registry.

In this task, you will register your MXChip AZ3166 device with your IoT Hub.

  1. Ensure that you have the GetStarted sample open in Visual Studio Code and that your MXChip AZ3166 device is connected to your PC.
  2. In the Visual Studio Code window, press Ctrl + P.
  3. At the prompt, to select the task that will provision your device, type task c and then click cloud-provision
  1. When prompted within the command line instructions, select the Azure subscription that you are using, and then press Enter The provisioning process will then check your subscription for an IoT Hub that it can use.
  2. When prompted within the command line instructions, select the IoT Hub that you created earlier, and then press Enter. You should see an option to select the hub that you created.
  3. When prompted that the provisioning process is complete, press Enter. You device, which has been named AZ3166, has now been registered with your IoT Hub. You can open you Azure portal to verify that it was created.
  4. Open a browser window and navigate to your Azure portal.
  5. On your dashboard, use your Resources tile to open your IoT Hub. Click the IoT Hub resource to open it.
  6. On the Overview blade, notice that the IoT Hub Usage tile now indicates that you have 1 IoT Device.
  7. On the left-side menu, click *IoT devices.
  8. Notice that a device has been created with the device ID set to “AZ3166”.

Configure the MXCHip Dev Environment

Now it’s time to set up the development environment

  1. Download and install the Arduino IDE
    • Windows: Use Windows Installer version Important: Do not select the installer for the Windows App, select the Windows installer version. The Windows installer is a .exe file that will install the Arduino IDE to the C:\Program Files (x86) folder location.You can download and save the installer before running it if you want – it is named something similar to the following: arduino-1.8.8-windows.exe
  2. Launch Visual Studio Code
  3. Open the Extensions panel with the keyboard shortcut Ctrl + Shift + X
  4. Search for azure workbench
  5. Click on the Azure IoT Device Workbench extension
  6. Click Install
  7. Once the extension is finished installing, click Reload
  8. Open the Visual Studio Code preferences with the keyboard shortcut Ctrl + ,
  9. Click the {} icon in the upper right hand corner of the window to edit the JSON
  10. Add the following JSON to your User settings file.

“arduino.path”: “C:\\Program Files (x86)\\Arduino”, “arduino.additionalUrls”: “https://raw.githubusercontent.com/VSChina/azureiotdevkit_tools/master/package_azureboard_index.json”,

On the File menu, click Save All, and then close and restart Visual Studio Code. When Visual Studio Code restarts you may see some installation tasks launch. Follow the on-screen instruction to complete the installation process if needed.

  1. On the File menu, click Save All, and then close and restart Visual Studio Code. When Visual Studio Code restarts you may see some installation tasks launch. Follow the on-screen instruction to complete the installation process if needed.
  2. Press F1 to open the command palette
  3. Type Board Manager
  4. Select Arduino: Board Manager and press Enter
  5. In the search box, type az3166 Note: There should be one item titled MXChip – Microsoft Azure IoT Developer Kit by Microsoft Developer.
  6. Select the latest version from the drop down, and then click Install

ST-Link Configuration

The USB interface used to communicate with your MXChip is ST-Link.

Windows

Download and install USB driver from STMicro.

Next time i will show you how to register your MXChip device with IoT hub.

Prepare MXChip device to communicate with Azure IoT Hub

Configure the MXCHip Dev Environment

In this task, you will perform the initial setup for the MXChip device.

  1. If you haven’t already, unpack your MXChip AZ3166 device. The kit includes the AZ3166 controller board and a Micro USB cable that you will use to power it.
  2. Use the micro USB cable to power up your device. The Micro USB cable plugs into the Micro USB port at the top-right of the board. During the initial setup, you will use a USB port on your computer to supply power to your MXChip device. You can use a different USB power supply (like the power supply for your Raspberry Pi), but for the setup process and when you are programming the device, you will need to be connected to a PC or another IP enabled device.
  3. While your computer is running, plug in the USB cable into a free USB port on your computer. Note: The Power light should come on when both ends of the cable are connected.
  1. Locate the B and Reset buttons on the device. The reset button is a smaller button that is located close to the micro USB power connector.
  2. To begin the process for entering AP Mode on the MXChip, press and hold the B button.
  3. While still pressing the B button, press and release the Reset button, and then release the B button. You should see a message similar to the following:

Using a laptop, connect to the WiFi network that is being broadcast by your device.

The device ID for your device is used as the name of the network, so it should be easy to recognize.

For example, in the case shown above our device ID is AZ-c89346841929. When we use a laptop to check for available Wi-Fi networks, we find a new network available with an SSID of AZ-c89346841929. We then click the Connect button to connect to the network being broadcast by our device.

Once you have connected your laptop to the device network, use your laptop to open a browser window, and then navigate to http://192.168.0.1

You should see a page that is similar to the following:


When you have finished it should look like this:

  1. Select your Wi-Fi network, enter the password, and then click Connect
  2. Verify that the MXChip display is now showing a message similar to the following:
  1. On the laptop connected to your MXCHip device, to download the latest firmware, open a browser and navigate to the following address: Download
  2. Save the .bin file to your PC. The file will have a name that is similar to the following: devkit-firmware-1.6.0.71.bin
  3. Open the File Explorer app on your laptop.
  4. Notice that the AZ3166 device is now listed as a storage location connected to your laptop.
  5. Use a drag-and-drop operation to copy the saved .bin file to AZ3166 device location. Once the file has been copied, the DevKit will reboot to the latest firmware. You should see that the latest firmware version displayed on the MXChip device.

To test the sensors on your device, press button B.

Continue pressing and releasing the button B to cycle through each sensor.

In next blogpost i will show you how to configure the MXCHip Dev Environment 🙂

How to set up your IoT-hub so you can receive data from your device

In this section I will show you how to set up an IoT-hub that will manage your data that come from your device that we set up in next blogpost.

There is some thing you must think about and I will guide you throw the steps and explain things for you.

First, you have to setup an azure-account and you have possibility to choose a free trial for 12 months with $200 free credits.
https://azure.microsoft.com/sv-se/free/
When this is done you will see following screen.

Choose then “Create a resource” in upper left corner

Then market place shows up for you and in the search-box write IoT Hub and click it.

Click on “Create”

Then you should see this screen

Here you must be a little bit careful.

1) Subscription Choose how you want the payment Check here how Microsoft set the price https://azure.microsoft.com/sv-se/pricing/details/iot-hub/
2) Resource group Here you can choose to have multiple iot-hubs in one resource depending on how you want your solution. For now, you choose “Create new” and choose a proper name for your group. Then Azure set up a resource group for you.
3) Region Here you choose the region that is nearest to where you are.
4) IoT hub name This must be an unique name and once you have name it you can not change the name so be careful when you choose your name.

This is how it look for me now

If you think everything looks great you just have to press “Review + Create” If it is looking how you want it just to click “Create”

In upper right corner you can now see that distribution is on the way

Now you can go away for a while and pick some coffee or take a short nap. When the distribution is finished you will have this message

Now you have your own IoT-Hub “Congratulation” You are on the cool way……….

If you press “Go to resource” you can see all information about your IoT-hub.

In a later blogpost I will explain a little bit deeper about IoT-hub and what you can do here. In the next blogpost I will teach you how to configure a device and connect it to your IoT-hub. Check out 🙂

What do you need for an IoT Solution? Part three

  •  Cloud Service Components

In the third and last blogpost in this series I talk about Cloud Service Components

The cloud services you choose is an essential part of your overall solution. In fact, the cloud services used in your solution constitutes the ‘I’ in IoT. There are options from many of the larger companies participating in this space as well as offerings from startups and medium-sized businesses. Now we have to look at categories of services these companies offer to give you an idea of how cloud services fit into an overall IoT architecture.

Cloud Gateways

The concept of a field gateway–a piece of hardware that brokers communication between IoT devices and cloud services. Cloud gateways do more than broker communication. They provide a set of services that devices can run either locally or in the cloud. Cloud gateways can provide workloads such as (among others):
– Authentication and authorization
– Message brokering
– Data storage and filtering
– Data analytics Data Storage Options

Given the centrality of data in an IoT solution, figuring out the right cloud-based data storage and retrieval options ranks high on the list in terms of importance. IoT devices can generate enormous amounts of data very quickly and storing high volumes of data in the cloud cannot become expensive but also unwieldy–you must be able to do something with the data and too much of it can make analytics and decision-making harder.

Data is often time series data and is required to be stored where it can be used in visualization and reporting as well as later accessed for additional processing. It is common to have data split into “warm” and “cold” data stores. The warm data store holds recent data that needs to be accessed with low latency. Data stored in cold storage is typically historical data. Most often the cold storage database solution chosen will be cheaper in cost but offer fewer query and reporting features than the warm database solution.

A common implementation for storage is to keep a recent range (e.g. the last day, week, or month) of telemetry data in warm storage and to store historical data in cold storage. With this implementation, the application has access to the most recent data and can quickly observe recent telemetry data and trends. Retrieving historical information for devices can be accomplished using cold storage, generally with higher latency than if the data were in warm storage.

Analytics Services and Data Visualization

Analytics

Once data is captured and stored, it only becomes useful when it provides insights into the physical world from which your IoT devices have captured the data. This is where analytic services come into play.

Azure Analysis Services, for example, enable architects to use advanced mashup and modeling features to combine data from multiple data sources, define metrics, and secure data in a single, trusted tabular semantic data model. The data model provides an easier and faster way for users to browse massive amounts of data for ad-hoc data analysis.

Without analytics, data collected from IoT would be too voluminous and unstructured to visualize or gain insights. Analytic services enable architects to build meaningful relationships between sets of data to make it easier to manage. For example, Azure Stream Analytics can take stream data from IoT devices and engineers can specify a transformation query that defines how to look for data, patterns, or relationships. The transformation query leverages a SQL-like query language that is used to filter, sort, aggregate, and join streaming data over a period of time.

Data Visualization

Stream analytics can help condition data so it´s easier to manage and provides models that give insight into what you need to understand or learn. Once the data is conditioned and you’ve created the right models, the data can be visualized using tools like Microsoft’s PowerBI so it can be acted upon.

Data visualization tools can take input from various data streams and combine them into “dashboards” that can be used to tell a story about the data that was collected. Ultimately, this is the goal of IoT.

Machine Learning

Machine Learning (ML) is one of the more exciting developments in modern computer science. It’s a complex field but one that is producing significant positive results with large datasets. IoT devices produces large large volumes of data. Analytic systems help engineers to model the existing data in meaningful ways. Machine learning takes this a step further and can actually make predictions about what new data will show and provide insights that would not be possible without the machine learning algorithms.

As the name states, the technology gives computers the ability to “learn” (predict) from data by expressing trends or a direction future data will take. This can provide engineers with a powerful mechanism for enabling a wide variety of scenarios.

Using big data and machine learning to predict purchasing decisions is one simple example. Suppose a retailer has warehouse space in various cities and needs to determine which items to stock in those cities in order to be able to get products to customers in the most efficient and timely way. Using machine learning the retailer can predict, for example, that a given set of users that purchase a specific television tend to buy a particular type of cable and other accessories like tv stands and audio equipment. This would allow the retailer to keep those items in the warehouse near where those television sales are popular so that if a customer orders the cable or other accessory, the item can be shipped more and get to the customer more quickly.