How to set up “How to increase revenue by harnessing IoT data in digital transformation solutions” lab
This lab features lots of visual demonstrations and interactions with its various components (wireless IoT device, IoT Central portal, PowerApps mobile application) and is aimed at people interested in getting an overview of Microsoft and its IoT partner ecosystem’s offering, using a logistics / track & trace use case as an example. It is not aimed at developers, and a typical audience is line-of-business managers, executives, or sales professional.
However, if you are reading this you are interested in setting up the lab for your own audience. Rest assured that in doing that you will learn a lot about how to build a logistics / asset tracking solution, where your participants will be focusing on what needs to be done, and why.
The preparation for this lab is split into four different parts:
- Cloning this repository ;
- Setting up Azure tenant, subscription, and resources (IoT Central) ;
- Sourcing, assembling, and flashing the IoT devices ;
- Setting up PowerApps subscription and solution ;
- Finalizing IoT Central setup.
1. Cloning this repository
As this Github repository contains some useful scripts and resources that you will be using to help you setup the lab, you should start by cloning this repository on your machine
git clone https://github.com/kartben/Inspire-E2E-IoT-Workshop
2. Setting up your Azure environment
It is recommended that you create a dedicated Azure tenant for the workshop. This allows to create an environment that doesn’t require your students to come with an existing Azure and PowerApps subscription, and more importantly it makes it easier to tell a .
➔ Creating an Azure Active Directory tenant
In this step, you are going to create a brand new Azure tenant that will eventually host all the resources (mainly an Azure IoT central application) and user accounts for our fictional company Contoso Art Shipping. You will be using your existing Azure credentials and will setup a new Azure Active Directory tenant, with its own subscription, that will be used for hosting your users and cloud resources.
-
Log into the Azure Portal using your credentials. Reminder: you need to be setup as the Owner of the existing subscription you plan on using for your new tenant. If that is not the case please use Option 2 below.
-
Open the “Azure Active Directory” (AAD) blade, and select “Create a Directory”.
- In the “Create directory” form, type the following information:
- Organization name: Contoso Art Shipping Inc.
- Initial domain name: contosoartshippinginc (Note: initial domain names are globally unique, so you will probably need to use variants of “contosoartshipping”, such as “contosoartshipping-lab” or “contosoartshipping-2019”)
- Country or region: this determines the data center for your AAD directory, pick your preferred country/region.
-
Once the form is complete, select the “Create” button.
-
The creation of the directory may take a few minutes. When the creation is completed, follow the link that invites you to manage your new directory.
- Notice that you while you are still logged in with the same principal you used earlier, you are now in your newly created AAD directory (see screen capture below).
Create a new subscription
-
Navigate to the “Cost Management + Billing” blade, and select “New subscription”.
-
If you never signed up for a Free Trial, apply for it and follow the instructions. If you’ve already benefited from a Free Trial, you will want to proceed with setting up a Pay-as-You-Go subscription.
-
Once your subscription has been created, you should see it in “My subscriptions” in the Cost Management center.
Creating user accounts for your lab participants
Note: If you don’t already have the Azure command-line interface on your machine, install it by following these instructions.
In this step, you are going to create accounts in the form of user001@yourdomain.com
for the participants to your lab.
-
Open a terminal session and log into your newly created Azure tenant using
az login
-
Execute the script
./lab-setup/scripts/createUsers.sh [domain] [password] [nbAccounts]
.- Replace
[domain]
by your directory’s domain name, ex. contosoartshipping-2019.onmicrosoft.com - Replace
[password]
by the password you’d like to set for the users, ex. P@ssword - Replace
[nbAccounts]
by the number of users you’d like to create, ex. 100
- Replace
Setting up an Azure IoT Central application
Next, you’re going to setup the Azure IoT Central application that is going to be used by Contoso Art Shipping to connect their asset trackers to, allow them to monitor their fleet in real-time and, more importantly, provide them with a way to feed the data and extracted insights (e.g “Shipment XYZ has been tampered!”) into their .
In order to bootstrap the IoT Central application quickly, you will be using an existing application template.
-
Open https://apps.azureiotcentral.com/create?appTemplate=7533e8f0-af2c-40a3-838d-23321c3d6b09 in your browser
- In the “Create an application” form, enter the following information:
- Choose a payment plan: Pay-As-You-Go.
- Application Name: Contoso Art Shipping.
- URL: contoso-art-shipping-XYZ (XYZ being a unique suffix of your liking, as IoT Central application URLs should be globally unique).
- Directory: select the Azure AD you have created earlier.
- Azure subscription: select the Azure subscription you have created for your Azure AD.
- Region: select the region closest to where you expect your users/devices to be.
-
Submit the form by clicking on “Create”, and wait a few seconds for your application to be created.
-
Navigate to the Administration / Users page.
-
By clicking on “Add user”, grant access to your lab participants by adding their email (e.g
user001@domain.com
) and giving them the “Application Operator” role. -
Navigate to the Administration / Device Connection page, and note the “Scope ID” and the “Primary Key” values, as you will need this information when preparing the asset tracking devices.
- Finally, navigate to the “Device Explorer”, and note the “Template ID” for the Asset Tracker template.
3. Preparing the Hardware
The device used in this lab is built with the Arduino platform, an open-source electronics platform based on easy-to-use hardware and software. You will need to acquire the equipment listed below in order to prepare the kits for your participants.
Note: depending on your geographical location, you may want to use other suppliers than the ones listed below as examples.
Bill of Materials
Arduino MKR GSM 1400
- Retail price: USD 69.90
- Buy from: Arduino Store, Mouser
- For small quantities, you may want to consider getting your MKR GSM with a SIM card directly from Arduino (in partnership with Arm Pelion), here (USD 70.90).
Note: you will want to check that your MKR GSM board comes with a GSM antenna.
Arduino MKR ENV Shield
- Retail price: USD 34.40
- Buy from: Arduino Store, Mouser
Touchscreen enclosure for Arduino MKR
- Retail price: EUR 60
- Buy from: Zihatec
Arm Pelion SIM card
As mentioned before, for small amount of participants (less than 12), you should consider getting Arduino MKR GSM 1400 with SIM cards directly from Arduino. For larger quantities, it is recommended you directly contact Arm.
Flashing your Arduino MKR1400 GSM
Follow the instructions at https://github.com/kartben/contoso_asset_tracker in order to flash the proper IoT Central firmware into your Arduino device.
As of July 2019, the provisioning of the device is performed using group keys, therefore make sure to update the config files with the proper values for connecting to IoT Central, i.e configure the scope ID, group key, and modelID that you’ve retrieved when setting up the IoT Central application.
Note: In a future version of this lab, the provisioning of the device will be performed using the X.509 certificates contained in the Arm Pelion SIM cards, and the device will be exposing its capabilities using Plug-and-Play. Provisioning will then be truly zero touch, as the Arduino firmware will be completely generic, and the only bootstrapping step required for the devices will be to set the scope ID, which can be done over e.g. SMS.
Assembling the parts
-
Gather the following parts: Arduitouch, MKR1400 GSM, MKRENV Shield, GSM Antenna, SIM Card.
-
Insert the Micro SIM card into the MKR1400 GSM
-
Insert the MKR1400 GSM and MKRENV shield into their dedicated slots. You might need to force slightly.
-
Plug the GSM antenna into the dedicated connector on the MKR1400 GSM.
-
You can now close your Arduitouch enclosure! You should be able to slip the antenna through one of the wider slits of the back panel as you are doing so.
4. Setting up your PowerApps environment
In this section, you are going to setup your PowerApps environment. You’re going to setup PowerApps trial accounts for all your participants, and you will be deploying a PowerApps solution template that already contains an app and some Common Data Service (CDS) entities for managing the shipments, their incidents, etc.
During the lab, your participants will get to see an overview of how one to create a PowerApp, how to extend CDS with custom entities, and finally how to manipulate CDS entities from MS Flow rules triggered by IoT Central (e.g log a new incident for a shipment on reception of the event “shipmentTampered”).
-
Open admin.microsoft.com in your web browser, and sign in as ‘admin’ if prompted.
-
Navigate to the “Users” section. The list of active users should contain all the users you’ve created earlier.
-
Navigate to “Billing / Purchase services”, and in the search field enter “powerapps”.
-
Select “Microsoft PowerApps Plan 2”
-
Select “Get free trial”
-
Confirm your order by clicking “Try now”.
-
You should be getting a confirmation shortly. Click on “Users” to go back to the Users page where you will need to assign your Contoso users the newly created trial subscriptions.
-
On the Active Users page, select all your users, then open the “…” menu. Then, click on “Manage product licenses”.
-
Select “Replace existing product license assignments”, then click “Next”.
-
Select “Microsoft PowerApps Plan 2”, then click “Replace”
-
The PowerApps 2 licenses should have been correctly assigned, you can now click “Close”.
Provisioning the Common Data Service database
As Contoso is building their solution on top of CDS, you need to initialize a database in your default environment.
-
Open https://powerapps.com in your web browser, and sign in as ‘admin’ if prompted. You will be taken to the PowerApps homepage.
-
Open “Admin Center” from the navigation bar. It will open in a new tab.
-
Select the “Contoso Art Shipping Inc.” environment.
-
Select “Create my Database” to initiate the creation of the Common Data Service database. In the popup that opens, select “USD” as “Currency” and “English” as “Language”.
-
Provisioning the database will take 3-5 minutes. When provisioning is complete, the “Provisioning database…” popup will automatically disappear.
-
Close the browser tab and go back to the previous tab where powerapps.com is open.
Importing Contoso’s solution (PowerApp & CDS entities)
In this step, you are going to import an existing PowerApps solution into your environment.
-
Now that you are back on the powerapps.com homepage, select the Solutions tab and click on “Import”.
-
In the popup that open, click on “Choose file”, select the
ContosoAssetTracking_1_0_2_4.zip
from thelab-setup/powerapps/
folder of the cloned Git repository of the lab, then click “Next”.
-
Confirm that you want to proceed with the import by clicking “Import”
-
The import process will take a few minutes. A popup will keep you informed of the progression.
-
When the import is complete, dismiss the popup by clicking “Close”.
-
Let’s now have a quick look at what has been imported. For this, select “Contoso Asset Tracking” and click “Edit”.
- Notice that your solution is made up of three components:
- “Contoso Shipment Tracker”: the Canvas App that allows to browse shipments and their associated incidents.
- “Incident”: CDS entity that models incidents. An incident is attached to a given shipment, has a cause, and can also capture information about the geographical position.
- “Shipment”: CDS entitiy that models shipments. A shipment has a shipping date, a delivery date, a photo, and is of course uniquely identified.
-
Select the “Contoso Shipment Tracker” Canvas App and click “Play”.
-
As this is the first time you are launching the app, you need to grant access to 1/ your CDS entities 2/ your camera (the application features a barcode scanner, and although you can’t use it in the web version of the application, permission is listed nevertheless).
- The application should now be loading without any error. And yes, it doesn’t show any shipment just yet, as you are going to create them in a moment!
Adding new shipments into CDS
In this step, you are going to use an Excel file that has all the information about the shipments to populate the CDS Shipment
table. You will be leveraging MS Flow support for both Excel Online and CDS to easily convert our Excel file into new entries in the Shipment
table.
-
Open the
contoso-artwork.xlsx
file you will find in the current folder in Excel. Adjust the number of rows to reflect the number of users you have setup in the Contoso company (i.e. the number of attendees to your lab), and update thetrackerID
column with the ICCIDs of the SIM cards you have sourced for the lab and put in the MKR1400 devices. -
Move the Excel file over to your personal OneDrive folder so that you can access it from MS Flow in the following steps
-
Open https://flow.microsoft.com in your web browser, and sign in as ‘admin’ if prompted. You will be taken to the PowerApps homepage.
-
Go to “My Flow”, and select “Import”.
-
Select
import-contoso-artwork-msflow.zip
and click “Import”. Wait for the import to complete. -
In the ‘Related Resources’ section, you need to make sure to associate the “Excel” connection with your personal account (where you have stored the Excel file) by clicking on the tool icon.
-
Select “New Connection” and enter “excel” in the search field. In the now filtered list of connections, select “Excel Online (business)”.
-
Click “Create” and finalize the connection to the account where you’ve stored the Excel file.
-
Back in the import package screen, select the “tool” icon in front of the CDS connection and make sure and bind the flow to the existing connection that shows up.
-
Click “Import” to finalize the import.
-
As you get confirmation the “All package resources were successfully imported”, click “Open flow”.
-
In the “List rows present in a table” section of the flow, update the “File” attribute to reflect the location of the Excel file in your OneDrive. Click on the folder icon to navigate through your OneDrive folders and select the file.
-
Save the flow, and go back to the previous screen.
-
Run the flow!
Over the next couple minutes, the flow will go through the following steps (you can go back to editing the flow to have a closer look at how each of them is implemented, if you’re interested), before reporting it successfully completed:
- Delete any existing Shipment in CDS by iterating over every existing record
- Enumerate all the rows in the Excel file and, for each:
- Download the thumbnail for the painting which URL is stored in the
picture
column - Create a new
Shipment
entry in CDS, using the values found in the row as well as the picture that was just downloaded to populate its various field.
- Download the thumbnail for the painting which URL is stored in the
Publishing the application
The last step will now be to make sure our PowerApps is available to all the members of your Contoso organization, by publishing it.
-
Open https://make.powerapps.com and edit the “Contoso Shipment Tracker” application (from the list of recent apps, open the “…” contextual menu to find the “Edit” command).
-
Confirm that your application now lists the shipments on its home screen.
-
Open the “File” menu of the PowerApps editor (don’t confuse it with the file menu of your browser!), and click “Publish”
5. Finalizing IoT Central setup
TODO (this step shall explain how to setup the MS Flow rule that creates new “Incidents” when “onTampered” event is fired).