Skip to content

Latest commit

 

History

History
128 lines (92 loc) · 13.6 KB

README.md

File metadata and controls

128 lines (92 loc) · 13.6 KB

IoT Workshop 2017 - Australia

Welcome to our IoT workshop!

We are so glad to have you with us today. We put together this workshop to give you some hands-on experience with the Microsoft Azure IoT suite. Our goal is to get you up-to-speed on the latest developments so you can take the knowledge back to your office and start implementing IoT solutions with them.

Prerequisites and Course Materials

This is a technical workshop and you're expected to be comfortable writing and understanding code (we will chiefly use Node.js throughout). Also, you're expected to be comfortable around Linux, be able to SSH in and know how to use text editors (such as vi or nano). Basic understanding of Azure is essential, but not critical.

Please make sure to complete the following prerequisites prior to coming to the workshop

  • Install PuTTY (Windows users only)
  • Download Azure IoT Device Explorer (Windows only) or Install a command line utility
  • Activate a free trial Azure subscription and familiarise yourself with the Azure Portal. Spin up a linux VM, SSH in, resize it and don't forget to tear it or shut it down. Explore how to use keyboard shortcuts - they save time!
  • Download Level 300 slides for your reference

Agenda

Day 1:

  • Azure IoT Suite: Level 300 intro
  • Environment setup: azure subscription, SSH access to your Raspberry PI, set up prerequisites
  • Lab 1: Azure IoT Device Management
  • Lab 2: Azure IoT Gateway SDK
  • Coming up with problems to solve on Day 2

Day 2:

  • Hacking away!
  • Wrap-up

Getting Started

Each group will be provided with a Raspberry Pi 3 running Raspbian Jessie, a Texas Instruments(TI) Bluetooth Low Energy (BLE) Sensor Tag, and an Azure Subscription.

We are presenting two labs today, one for Azure IoT Device Management and one for the Azure IoT Gateway SDK. The Azure IoT Device Management lab will introduce you to the concepts of Device Twins and Direct Methods. The Azure IoT Gateway SDK lab will introduce you to the open source SDK for building IoT Gateway devices enabling, for instance, non-internet connected device to send data to Azure IoT.

Proctors are available to help you work through these workshops, answer questions or talk tech.

Your Raspberry Pis comes with a stock standard version of Raspbian, with the SDKs preloaded, compiled and located in:

  • Device SDK: /home/pi/azure-iot-sdks
  • Gateway SDK: /home/pi/azure-iot-gateway-sdk

VNC server has been enabled, you can access you RPI's GUI using VNC Viewer.

To save time, please skip all sections to do with installing raspbian, cloning git repos and compiling SDKs. Feel free to download the Raspbian image (warning - 8GB) we use here and write it to an SD card following these instructions. In case you want to resize the image to make use of your (potentially larger than 8G) SD card, use the raspi-config utility or follow the instructions here.

Lab 1: Azure IoT Device Management

This lab will demonstrate the Device Twins and Direct Methods features and is available here.

The Device SDK GitHub repo has been cloned to /home/pi/azure-iot-sdks/. In the interest of time, Step 1: Prerequisites, Step 2: Prepare Device and the sudo c/build_all/linux/setup.sh step in Step 3: Build and Run the Device Twins Sample can be skipped.

Please make sure you set the correct timezone by running sudo raspi-config

Please make sure the time is synchronised by running sudo service ntp stop; sudo ntpdate 0.ubuntu.pool.ntp.org; sudo service ntp start

Lab 2: Azure IoT Gateway SDK

This lab will demonstrate the open source Azure IoT Gateway SDK using a Bluetooth Low Energy (BLE) Sensor Tag, Raspberry Pi and Node.js.

The Azure IoT Gateway SDK lab is available here.

Please read the architectural introduction before jumping to the "Enable connectivity to the Sensor Tag device from your Raspberry Pi 3 device" section to configure your TI BLE Sensor Tag.

The Azure IoT Gateway SDK GitHub repo has been cloned to /home/pi/azure-iot-gateway-sdk and compiled. Steps that can be skipped are called out in the lab. The raw data values read from the SensorTag temperature sensor are: die (ambience) temperature and object temperature.

Bonus Challenges

You are likely an overachiever, so we've included a few extra challenges! Please make sure you complete the Azure IoT Gateway SDK lab first.

Decode Telemetry

  • The SensorTag temperature telemetry requires decoding (i.e. conversion to JSON). The raw data comes as a 4-byte array consisting ot two unsigned 16 bit integers, one for the die (ambience) temperature and one for the object temperature measured using the IR temperature sensor. You have more than one option to decode it:
    • Wire up an Azure Function using your IoT Hub's Event Hub endpoint to convert temperature readings coming from the SensorTag and publish them to an Event Hub for further processing by Azure Stream Analytics. Use this Google query for inspiration code samples, this blog for instructions and this link for implementation details. Some more reading material here. Okay, if you're feeling lazy just grab the code from this repo
    • (Hardcore!) You can even do it on the gateway by building a new module in Node.JS. Refer to Node.js Printer to understand how to consume messages and to Node.js Simulated Device to get an idea how to publish values. The flow can be be SensorTag -> mapper -> Converter -> IoTHub or SensorTag -> Converter -> mapper -> IoTHub. You will need to understand how the identity mapper and the IoTHub writer work, the documentation can be found here and here. If you succeed at doing it then you can wrap the telemetry in a JSON message and connect Azure Stream Analytics directly to the IoT Hub.

Create an Azure Stream Analytics Query

  • Create an Azure Stream Analytics query that selects all the data from your Event Hub or IoT Hub (if you chose the hardcore path) and outputs the results to Power BI, displaying aggregate metrics and sending emails or texts (e.g. when temperature exceeds 37 degrees for longer that 15 consecutive seconds). Experiment with the ASA windowing functions and Azure Logic Apps to achieve it.
  • How about making this threshold dynamic? Hint: store it as reference data and use it in your queries.
  • How about closing the loop and sending Cloud-to-device messages when the temperature is above a threshold... say, lighting up the red LED on the TI Tag? Hint: connect ASA to an Event Hub or Storage Queue and create a triggered Azure Function to push out the C2D message. Don't forget to implement the logic for turning the light off!

Create a Power BI Dashboard

  • Create a Power BI Dashboard that visualizes your TI Sensor Tag data in creative ways. Feel free to use any of the Power BI Custom Visuals available here. You can learn how to create Power BI Dashboards from a Stream Analytics Output here.

Time Series Insights (Preview)

Enable More Sensors!

  • Using the GATT table - and the TI SensorTag phone application explore what other sensors are available... feel free to update the gateway config to enable them (hint - this will likely to have an impact on your decoder function)

Machine Learning? Easy!

  • Enable the humidity sensor and have your ASA (Azure Stream Analytics) job invoke a weather prediction model. In case you don't feel like enabling additional sensors (mind you, enabling a new sensor also requires modifications to the decoder function), you can always generate some pseudorandom humidity values and feed those along with the real temperature data to the ML model. Think of at least two services where you can generate humidity data.

OPC Publisher Module

You can use the OPC Publisher module as a base for implementing your own Azure IoT Edge modules (instructions assume a windows host is used)

  1. Run git clone –recursive https://github.com/Azure/iot-edge-opc-publisher.git
  2. Install .NET Core 1.0 Preview 2 3131 – required to build the .NET Core Gateway/Edge module in OPC Publisher:
    • Download Windows 64 bit SDK Binary so that .NET Core 1.0 Preview 2 3131 can co-exist with the latest version of .NET Core which is required to run Azure IoT Edge OPC Proxy sample
      • Extract the zip onto a folder on C:\
      • When you compile the OPC Publisher module, reference dotnet.exe in the folder which you extracted, e.g., c:\dotnet
    • Other SDK binaries are available here, in case you need the SDK binaries for other OS
  3. Install Docker – follow the instructions here
  4. Configure the OPC Publisher module:
    • Modules are chained up in the gatewayconfig.json file
      • 2 modules; IoTHub module as Native C, and OPCUAPublisher module as .NET Core app
      • You can chain up more modules written in the programming language of your choice. For starters, you could just standardize your modules as .NET Core apps
    • The main gateway entry/binary is written as a .NET Core app available here
  5. Building the Docker container – review/modify the Dockerfile and follow instructions here

IoT Hub Additional Reading

Programmability, Consuming and Processing Telemetry in Code

Azure Stream Analytics (ASA) + Azure Machine Learning

Azure Functions

Have Fun!