Demo #3 — Azure
In the first chapter, we connected a WM2000 to a wireless network and securely transmitted data polled from the WM2000EV's integrated light and temperature sensors to the cloud. In the second chapter, we configured the WM2000 to associate with a Wi-Fi network automatically, enabled wireless debugging, loaded an application, and directly controlled the WM2000EV's onboard RGB LED via a web interface.
In this chapter, we'll update TiOS on your WM2000 and then connect it to the Microsoft Azure cloud services platform and securely transmit sensor data. As Azure supports controlling edge devices from the cloud, we'll also configure your module to receive and execute commands — such as activating the WM2000's onboard RGB LED.
In this chapter, you'll need to copy long strings of text from a website into the L.U.I.S. (Loadable User Interface System) app. To simplify this process, Tibbo strongly recommends that you use a single device for the entire tutorial. This may be either a smartphone (tablet), or a computer equipped with a Bluetooth 4.0 interface (adapter).
L.U.I.S. is available as a smartphone app for iOS and Android, or as a web app.
Due to the limitations of the Web Bluetooth API, the web app only works in recent versions of the Chrome, Chromium, Edge or Opera web browsers running on a Mac or Windows 10 (version 1703 and later) computer equipped with a Bluetooth 4.0 adapter.
Updating TiOS on Your WM2000
The project for this demonstration (located in the IotCentral folder of the WM2000EV Project Repository) requires a TiOS version of at least 4.01.02 To simplify uploading the application, we supply a Tibbo Composite Uncompressed (TCU) file — azureiot_demo-wm2000.tcu — containing the correct firmware, the Companion App, and this project. The following instructions use our BLE Firmware Updater web app, but this upgrade can also be accomplished with the Tibbo Updater smartphone app (available for iOS and Android).
1. Place your WM2000 in the update mode's BLE phase. The Monitor/Loader V4 Flowchart shows how to do this. Alternatively, follow this infographic that summarizes the steps:
2. Open the BLE Firmware Updater (click here to open the web app in a new tab/window).
3. Click on the button labeled 4 at the bottom. Then click on Connect a device.
4. Select your WM2000 from the pop-up dialog and click Pair.
5. Click on Update Firmware From Local File.
6. In the dialog, find and select the azureiot_demo-wm2000.tcu file in the repo. Then click on Open.
7. The firmware update, Companion App, and demo project will be uploaded to the device.
Do not power off the device.
8. When the update is complete, the device will reboot automatically.
Connecting Your WM2000 to Azure
As this demonstration uses Azure IoT Central, it goes without saying that you'll need an Azure account. If you do not already have an account, Microsoft currently offers a free trial of Azure services. Note that a credit card is required for identity verification. The following instructions assume that you will be setting up a new account. If you already have one, skip to step number 6.
These instructions also assume that you have already configured your WM2000 to associate with a Wi-Fi network automatically and enabled wireless debugging. If you need help doing so, see the previous chapter for guidance.
1. Open a new browser window/tab and navigate to azure.microsoft.com.
2. Click on Try Azure for free.
3. Click on Start free.
4. Sign in or create a Microsoft account, or use one of the alternate sign-in options.
5. Fill out the form to create your Azure account, then click Next. Microsoft will then verify your identity via text message or phone call. You might also be asked to input your tax information, depending on your local laws and regulations. Finally, you will have to provide a credit card for the final verification of your identity. When you're done, click Sign up.
Note: Tibbo is not affiliated with Microsoft. We chose Azure for this demonstration because it is one of the world's largest cloud services platforms and is commonly used for Internet of Things (IoT) applications.
As the Microsoft Azure website states, your credit card won't be charged unless you upgrade. If you have any unintended charges associated with Azure, please contact Microsoft directly for assistance.
6. After your account is created, you will be at a screen that reads: "You're ready to start with Azure." Next, click on Build in the portal.
If you already had an Azure account, log in and then click on Portal from the Azure homepage.
7. Search for "IoT Central Applications."
8. Click on Create.
9. You'll need to give your application a name, which must be unique as it will be used for an URL.
For the Resource group field, you will need to create an entry if you don't already have one.
Under Template, choose custom application.
For Location, you'll likely want to pick whichever choice is closest geographically to your deployment location. When you're done, click on Create.
10. At the "Your deployment is complete" screen, click on Go to resource.
11. Click on IoT Central Application URL.
12. You will be at the dashboard for your application. Click on Device templates.
13. For the device type, select IoT Device and then click on Next: Customize.
14. Give the template a name. Do not check "This is a gateway device" and click Next: Review.
15. At the review screen, click on Create.
16. At the create a model screen, click on Import a model. In the dialog, find and select the wm2000evm.json file included in the WM2000EV Project Repository and then click Open.
17. Leave the default settings included in the imported model. Click on Views.
18. Click on Generate default views.
19. Leave the defaults unchanged (all should be On). Click on Generate default dashboard view(s).
20. You will be returned to the device template you're configuring. Click on Publish.
21. You will be presented with a summary of what will be published. Click on Publish.
22. In the left-hand menu, click on Devices. Then click on Create a device.
23. Leave the default values for Device name and Device ID. Make sure that the Device template field matches the name of your template. Then click on Create.
24. You'll be taken to the devices page. Click on the name of your device.
25. On the details page for your device, click on Connect.
This demo project requires a TiOS version of 4.01.02 or newer. If your device is running an older version, attempting to connect it with Azure will result in continuous reboots.
If you haven't already, Tibbo strongly recommends that you follow the BLE update process detailed in the previous section before you continue.
26. Power on your device and open the L.U.I.S. app (click here to open the web version in a new tab/window). Pair the app with your WM2000.
Microsoft Azure |
L.U.I.S. |
27. Click the blue button next to the ID scope field to copy its value. |
28. Paste the string you copied into the Scope ID field. |
29. Click the blue button next to the Device ID field to copy its value. |
30. Paste the string you copied into the Device ID field. |
31. Click the blue button next to the Primary key field to copy its value. |
32. Paste the string you copied into the Primary key field. |
33. Click on Save. |
|
34. Click on Reboot. |
35. Back in your Azure portal, click on Devices and then select your device.
36. Click on the Overview tab. You'll be presented with a graph of the data transmitted from your device. This graph is updated in real time — it will refresh whenever new data is collected.
Note: Azure requires multiple data points to provide a graph and averages. You may need to wait a few minutes for the device to transmit sufficient data for the platform to visualize it.
Controlling Your WM2000 From Azure
As we mentioned at the start of this tutorial, your WM2000 can receive and executive commands sent via Azure. The device template included with this demonstration is preconfigured to send a command to your module, which will turn on the WM2000EV's RGB LED in a pattern you determine. The following instructions will enable this functionality on your device and demonstrate how to use the command function.
1. Open TIDE on your computer.
2. Open the demo project in TIDE (the file is IotCentral.tpr).
3. In the Files pane, look for iothub.xtxt under Resource Files and double-click it.
4. On line 3 of the file, input the following exactly:
- >>LedTest
- Tab five times
- C
- Tab two times
- {Pattern},{}
- Enter
5. Find "#define IOTHUB_COMMAND_NUM 0" on line 10. Change the 0 to 1. This switch enables your device to process commands received via Azure.
6. Save your changes.
7. Upload the updated app to your WM2000.
8. In the left-hand menu of your Azure portal, click on Devices and select your device.
9. Click on the Command tab. Here, you can input a pattern that will be transmitted to your module, which will trigger the RGB LED. This pattern has the same syntax as the pat.play method, except that the "B" represents the color blue.
10. Enter "R-G-B-" and click on Run. Your WM2000EV's RGB LED will flash red, green, and blue before turning off. Feel free to experiment with other patterns.
Note that if you don't end with "-" (dash), the LED will remain on at the last color in the pattern.