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.

What do you need for an IoT Solution? Part two

  • IoT Software

Like any piece of complex hardware, IoT devices need an operating system in order to be useful. But because IoT devices tend to be small and resource-constrained, operating systems will vary in functionality, memory footprint, and feature set. Devices also need to be programmed–given the instructions they need to do the tasks that engineers need them to do. There are many vendors developing operating systems and programming tools and the choice you make for any given solution will be the product of several factors including:

– Availability of the software you need
– Compatibility of the software with the devices you’ve chosen
– Compatibility with other software/cloud systems in your solution

Of course, your solution may involve devices with a variety of operating systems and development environments. But the more you add to your solution, the more complex development and maintenance becomes so it pays to be mindful of the software choices you make and the implications of each one during the architectural phase of the project.

What Programming Languages should I chose?
When it comes to programming devices, the operating system running on the device may determine what languages can be used to program it. Many modern hardware devices can support multiple languages and board engineers may develop specific flavors of hardware to support various languages. Microsoft’s IoT core, for example, supports most languages that Windows develop in general supports including C#, C++, and JavaScript. Ubuntu Core, on the other hand, supports Python, Ruby, and Node.js.

This makes choosing a programming platform complex and attempting to even outline the matrix of options here would not present an adequate picture. Instead, we can suggest how to approach the decision-making process when it comes to a programming platform. These suggestions build upon the strategies we’ve been seeing throughout this posts, so some items will be familiar and other items will be new.

Determine what data you want to collect.
Your IoT architecture generally will begin by figuring out what problems you’re solving and this, most times, will be characterized in terms of the data you want to collect. This relates to programming languages because the data you want to collect will impact the devices you choose and the programming language(s) you choose will have to work with the device infrastructure you deploy.

Think about your broader software environment.
When you think about what software platform you want to use, it can be helpful to think about the development environment across your business group or enterprise. By using a language that already is deployed in other areas of your business can make tasks like resource balancing, code sharing, source control, hiring, and similar factors more efficient.

Choose a device or devices platform.
Once you’ve figured out what data you want to collect and have thought about your larger ecosystem, you’ll be better informed when it comes to choosing a device platform. As I said before, you may need more than one device platform so choosing platforms that are the most compatible with items above will give you a more efficient overall environment in which to develop your solution.

What about the cloud?
It may go without saying I’ll say it: an essential component of the software platform when making a platform decision is the cloud services you’ll use to support your software and hardware. I think it’s important to call out here as an essential aspect of the decision-making process.