Getting started with CFS using MX Chip – Capturing IoT Alerts from MX Chip

***Azure IoT Central (as defined by Microsoft) is a fully managed SaaS solution that makes it easy to connect, monitor and manage your IoT assets at scale. It simplifies the initial setup of your IoT solution and reduces the management burden, operational costs, and overhead of a typical IoT project.***

Read on further at: https://azure.microsoft.com/en-in/services/iot-central/

From the above words, it is quite evident that anyone with no background of coding can do a simple integration of MXChip – Azure IoT Central with Dynamics 365 Connected Field Service You can have look at http://mxchip.com/az3166 to know what capabilities the device can offer.

This is how a MXChip IoT DevKit – AZ3166 look like:

Integration Scenarios:

  1. Using the MXChip IoT DevKit, monitor the surrounding temperature.
  2. On the MXChip IoT DevKit, when we press button B – it will create a in IoT alert in Dynamics 365 Connected Field Service.

Let’s see how we can achieve this. Follow the steps below:

Step 1: Getting Started with Azure IoT Central

You will need:

  1. Dynamic 365 instance with Field Service Add-on included (if you don’t have, sign up at https://trials.dynamics.com )
  2. <Optional> Azure subscription (if you don’t have a azure subscription, sign up at https://portal.azure.com )

Step 2: Create Application at Azure IoT Central

Navigate to https://apps.azureiotcentral.com and click on ‘New Application’

You can choose either ‘Trial’ or ‘Pay-As-You-Go’. Either plans will have its own capabilities. It’s obvious that ‘Pay-As-You-Go’ will need a valid Azure Subscription. For now, we’ll choose ‘Pay-As-You-Go’. Pay-As-You-Go applications are charged per device, with the first 5 devices free.

Select ‘Sample Devkits’ since we already have a MXChip device with us.

More info on application templates below:

Sample Contoso: Creates an application that includes a device template already created for a Refrigerated Vending Machine. Use this template to get started exploring Azure IoT Central.

Sample Devkits: Creates an application with device templates ready for you to connect an MXChip or Raspberry Pi device. Use this template if you are a device developer experimenting with any of these devices.

Custom application: Creates an empty application for you to populate with your own device templates and devices.

The Application name and URL are automatically generated.

Further, you need to select your Directory, Azure Subscription, and Region:

Directory is the Azure Active Directory (AD) to create your application. It contains user identities, credentials, and other organizational information. If you don’t have an Azure AD, one is created for you when you create an Azure subscription.

An Azure Subscription enables you to create instances of Azure services. IoT Central will provision resources in your subscription. If you don’t have an Azure subscription, you can create one on the Azure sign-up page. After you create the Azure subscription, navigate back to the Create Application page. Your new subscription appears in the Azure Subscription drop-down.

Region is the physical location where you’d like to create your application. Typically, you should choose the region that is physically closest to your devices to get optimal performance. You can see the regions in which Azure IoT Central is available on the Products available by region page. Once you choose a region, you can’t later move your application to a different region.

Once above 3 items are selected, click on ‘Create’

The Dashboard of Azure IoT Central is shown:

Go to ‘Device Explorer’, select ‘MXChip (1.0.0)’ and select ‘Real’

The device page with status as ‘Provisioned’ is shown. Now, click on ‘Connect’

The created device’s connection properties is shown as below. Copy down all the IDs to a notepad, you will need it later.

Step 3: Setting up the MX Chip

We need to load the IoT Central firmware to the MX Chip.

Connect the IoT device to your p.c (windows OS). It will open up in a separate disk drive with the device name AZ3166. Open the drive folder and copy the firmware file here.

The firmware file ‘AZ3166-IoT-Central-2.1.0.bin’ is available for download here: https://we.tl/t-YckLL4kuob

Once copied, the folder will be automatically closed. The IoT device will reboot as well.

You should see a Access Point name on the screen of MX Chip that you can connect to via the p.c Wi-Fi. Go to p.c Wi-Fi connections and look for the connection name ‘AZ3166_SRSDC’. Click on ‘Connect’.

This will help us to connect to the device.

In the browser, open the url: http://192.168.0.1 and click on ‘Here’

The Azure IoT Central Device Config page is shown as below:

Click on the first dropdown item on the page to look for available Wifi connections for the IoT device to connect. For now, I will use my mobile HOTSPOT.

Device Pin Code: 4584 (as shown on the screen of IoT device)

Scope ID, Device ID, Primary/Secondary Key are available in the notepad, which you copied earlier.   You can select ‘SAS Key’ and check ‘Temperature’ alone as we will only monitor temperature

Further, click on ‘Configure Device’.

Device configuration is now completed. It is not needed to press ‘Reset’ button as the page says.

Quickly look at the IoT device, it will be trying to connect to the Wi-Fi network you just configured.

Once connected, it will start to send the temperature data to Azure IoT Central.

To view the data, go to Azure IoT Central, select ‘Device Explorer’ -> MXChip (1.0.0) and select the MXChip with ID we just created.

Go to ‘Measurements’ tab, scroll down until you see ‘temperature’ and click on the eye icon (Visibility) to view the temperature data being streamed into Azure IoT Central from the IoT device. (In the pic below: hover the mouse cursor on the black line, 27.50 degrees is the temperature data being sent from the IoT device)

The device will keep sending the temperature data every 12 seconds to Azure IoT Central.

All good now. This covers scenario 1.

For scenario 2, if you look at the IoT device, there’s button with name ‘B’. When we press this, we create an IoT alert in CRM. To achieve this, IoT central has got its down Out-of-the-Box device templates.

Headover to Azure IOT Central -> Device Templates and select ‘MXChip’

Go to ‘Rules’ tab. Click on ‘New Rule’

Further, click on ‘Sample Rule’

For instance, give rule name as ‘Button B pressed’, make sure ‘Enable rule for all devices of this template’ is enabled. In the Conditions, choose ‘Button B pressed’.

Click on ‘Save’

So, when the button B is pressed, we need to create IoT alert in CRM. We will make use of Microsoft Flow for this purpose.

Under Actions -> Click on “ + “, scroll all the way down until you see ‘Microsoft Flow’

Microsoft Flow page is opened up (Note: If you are not signed-in, it may ask you to sign in, please do so). Click on ‘Explore Templates’.

Look for the flow ‘Create CFS Alerts from IOT Central’ and click on it.

Ensure both Dyanmics 365 and Azure IOT Central are having same account and two green tick marks are there as below.

Further, click on ‘Continue’

The flow configuration page is shown:

Application: Ensure that application is chosen from the dropdown with applicate we created earlier.

Rule: It will be Button B pressed as we created earlier

Organization name: your current org (choose from the dropdown)

Entity name: IoT Alerts (OOB Entity – no need to choose. It is chosen by default)

Description: You can leave it as it is you may customize as per your wish.

Once above details are entered, click on ‘Save’ (You may also use ‘Flow Checker’ to validate your flow).

Click on ‘Done’ The configured rule on the device will now look like below:

Head over to the device, click on Button B.

Now, come to your CRM instance and open ‘Connected Field Service’ app

Go to My Work -> IoT Alerts

There you go! We can see the IoT alert being created! WOW!

At-last, we have our Scenario 2 covered as well.

Well, this is just a tip of the iceberg. The possibilities are endless. You may wish to bring in your own scenarios as per the capability of the device.

Additional links:

https://dev.to/azure/azure-iot-central-and-mxchip-hands-on-lab-328i

https://www.hanselman.com/blog/DidILeaveTheGarageDoorOpenANocodeProjectWithAzureIoTCentralAndTheMXChipDevKit.aspx

Do leave a comment if you face any challenge in doing the above operations.

Also, let me know your feedback on the blog as its my first post.  

Thank you for your time!

Cheers

***Lets make CRM Simple Silly***