Sensor Telemetry 2.0.1 – Advanced Temperature Monitoring with Azure IoT Hub
Sensor Telemetry 2.0.1 delivers real‑time temperature data from an MCP9808 sensor to Microsoft Azure IoT Hub. The system processes telemetry with Azure Stream Analytics, stores results in Azure SQL, and visualises history in a Windows Universal mobile app. Updated 17 May 2017.
Story
UPDATE: Sensor Telemetry has been remastered and renamed to 2.0.1.
Introduction
Overview
This project showcases how to read a high‑accuracy MCP9808 temperature sensor on a Raspberry Pi, send telemetry to Azure IoT Hub, process the data with Stream Analytics, and persist readings in Azure SQL. A UWP mobile app displays the sensor history and allows remote control via SignalR.
The Application
Two UWP apps share ~99% of their code: one runs on the Raspberry Pi (IoT side) and the other on a PC (client side). The IoT app sends sensor data to IoT Hub and SignalR, while the client app subscribes to SignalR for real‑time updates and can issue commands back to the device.
Technologies
The codebase follows MVVM with Prism (Prism.Unity for IoC) and Prism.Event for a loosely‑coupled event system. SignalR powers real‑time communication across app instances.
Architecture
The core MCP9808 library is a reusable UWP component. In the client app, Views are paired with ViewModels; three repositories handle settings, debug logs, and sensor data. The Mcp9808TemperatureRepository publishes a temperature‑changed event only when the reading changes. Background services handle telemetry, timers, alert pin monitoring, LED control, push‑button handling, notification relays, and debug logging.
Telemetry Service
Listens for temperature changes and forwards messages to Azure Service Bus Event Hub.
Timer Service
Publishes a 500 ms tick; used for UI time display and sensor polling (1 s intervals).
Alert Pin Monitoring Service
Detects GPIO changes on the MCP9808 alert pin and publishes events.
LED Service
Controls LEDs based on temperature alerts.
Push Button Monitoring Service
Handles manual alert reset via a GPIO push button.
Notification Relay Service
Maps internal events to SignalR messages, enabling inter‑app communication.
Debug Console Service
Collects and exposes debugging events for the UI.
Application Initialization
The app launches StartPage, which bootstraps services before navigating to the main view.
Getting Started
Circuit Requirements
- Large solderless breadboard (Vilros T‑shaped cobbler optional)
- MCP9808 breakout (Adafruit)
- 4 LEDs, 220 Ω resistors, 10 k Ω pull‑ups, momentary push button
Assembly
- Connect LEDs to GPIO 18 (blue), 23 (green), 12 (red), 16 (yellow) with 220 Ω to 3.3 V.
- MCP9808: VDD→3.3 V, GND→GND, SCL→GPIO 5, SDA→GPIO 3, ALERT→GPIO 6, pull‑up 10 k Ω to 3.3 V.
- Push button: one side to GPIO 5, other side to GND, pull‑up 10 k Ω to 3.3 V.
Photos of the finished breadboard are available in the gallery below.
Microsoft Azure Requirements
Create a free Azure account (USD 200 credit) at azure.com. Sign in to portal.azure.com.
Azure IoT Hub Setup
- New → Internet of Things → IoT Hub
- Unique name, subscription, resource group (create new), location (same region)
- Pricing tier: F1 Free (single free tier per account)
- Wait for deployment, then review hub overview.
Create a Device
- Download Azure IoT SDK for C# from GitHub and open DeviceExplorer in Visual Studio.
- Paste IoT Hub connection string (from hub > Shared access policies > iothubowner).
- Create a device (e.g., TemperatureDevice1) with auto‑generated keys.
Azure SQL Database Setup
- SQL Databases → Add → Name: SensorTelemetry.
- Use existing resource group; create new server with a unique name, admin username/password, Basic tier, same region.
- Configure firewall to allow your IP.
Create the Database Table
- Open SQL Server Object Explorer in Visual Studio, connect to the Azure SQL server.
- Run the provided CREATE TABLE script to create
SensorReadings.
Create App Service Plan & Mobile App
- App Service plans → New, name, existing resource group, location, Basic tier B1.
- New → Web+Mobile → Mobile App, name, subscription, existing resource group, chosen App Service plan.
Azure Stream Analytics Setup
- New → Data + Analytics → Stream Analytics Job.
- Configure input as the IoT Hub, output as the Azure SQL table.
- Use query: SELECT [TimestampUtc], Source, Temperature, IsCritical, IsAboveUpperThreshold, IsBelowLowerThreshold INTO [YourOutputAlias] FROM [YourInputAlias];
- Start the job.
Configuring the Software
Download the source from the repository link and open the solution in Visual Studio.
Publish the Mobile App
- Right‑click Web project → Publish → Microsoft Azure App Service → select your App Service.
- Copy the Azure SQL connection string (ADO.NET) and paste into
MS_TableConnectionStringin the project, updating username/password. - Publish; the web site launches automatically.
Enter IoT Hub Credentials
- In
App.xamlof the UWP project, replace{YOUR CONNECTION STRING HERE}with the device connection string from Device Explorer. - Replace
{YOUR DEVICE ID HERE}with the device ID you created.
Enter Mobile App URL
- In
UnityConfiguration.cs, paste the App Service URL (copied from the Azure portal) into{YOUR MOBILE SERVICES URL HERE}.
For detailed instructions, see the full Sensor Telemetry 2.0.1 documentation.
Manufacturing process
- Sensor Calibration Explained: Definition, Methods, and Key Applications
- Heartbeat Sensor: How It Works & Practical Applications
- TMP006 Infrared Temperature Sensor with Raspberry Pi: Python Library & Setup Guide
- Build a Raspberry Pi Home Temperature Monitor with MCP9808, InfluxDB & Grafana
- Emotion Sensor & EEG: Low-Cost Hardware for Real-Time Emotion Detection
- UnifiedWater v1 – Complete Arduino Water Quality Sensor Kit
- River Health Monitor: Arduino-Based Water Quality System
- Build a Smart Wristband with Arduino MKR GSM 1400 & Hologram IoT
- Smart Hydroponic System Using Arduino Mega 2560 & Sensors
- Master Vibration Detection with Arduino: A Simple Sensor & LED Setup