I’m preparing some material for a webinar on Azure IoT in mid-October (you are signed up, aren’t you?) and thought I’d do a quick intro to the basic concepts and moving parts.

Azure IoT Hub is a cloud-scale service for managing and securely communicating with large numbers of field devices (potentially millions at once); communication can occur from device to cloud, and also from cloud to device (for issuing commands or queries to devices). It’s standards-based so it works with many device types, a number of communications protocols and guest operating systems, and supports various network topologies. It also supports custom gateways for edge analytics, traffic optimization, etc. Finally, it integrates with a number of existing Azure services like Stream Analytics, Machine Learning, and Event Hubs to maximize scale and minimize time to insight.

Let’s walk through a sample Azure IoT Hub-based solution and see it in action. I live in Atlanta, GA USA and our public transit system provides geolocation and other metadata about buses and trains; we’ll use the bus data to simulate device activity in the field (each bus == a device) and use IoT Hubs, Stream Analytics, Azure Storage, DocumentDB, and some custom code to collect and present that data in a meaningful way.

Here’s a diagram of the high-level architecture we want to achieve:


To simulate data coming from multiple buses driving around in the city, a worker process will periodically poll the transit data, do some minor scrubbing, and push new values into the IoT Hub endpoint. The IoT hub itself is configured with three consumer groups (in essence, three copies of the incoming data). A permanent log of all raw incoming device activity is often useful for tracing, debugging, and downstream analytics; for this we’ll configure a Stream Analytics job to listen on the ‘history’ consumer group and forward all traffic to Azure blob storage:



Then we’ll keep a copy of the most recent message from each device in “hot” storage (you’ll see why in a moment); for this we’ll configure another Stream Analytics job to listen on the ‘info’ consumer group and forward the messages to a DocumentDB collection:


Next, we’ll hook up some custom listener code to the third consumer group (‘location’) and forward a subset of that incoming data to a custom web app, which will continuously display the bus locations using an embedded Google map control and ASP.NET SignalR. This custom code uses the EventProcessorHost API and IoT Hubs built-in support for the Event Hub programming model to listen for incoming messages and POST them to the web app, like so:

public async Task ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages)
// configure REST client
var client = new HttpClient();
client.BaseAddress = new Uri(ConfigurationManager.AppSettings["webUrl"]);
var save = false;
// process incoming messages
foreach (var msg in messages)
// get BusInfo from incoming message
var json = Encoding.UTF8.GetString(msg.GetBytes());
var bus = JsonConvert.DeserializeObject<BusInfo>(json);
// create metadata object from busInfo to POST to web app
var info = new
id = bus.VehicleId,
lat = bus.Latitude,
lng = bus.Longitude,
timepoint = bus.Timepoint
var content = new StringContent(JsonConvert.SerializeObject(info));
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
await client.PostAsync("api/listener", content);
save = true;
// if we successfully processed the messages, make note of that for all other consumers
if (save)
await context.CheckpointAsync();

Finally, the web app will display the Google map with continuously updating markers for bus locations:


Clicking on a marker will pop up a small window with additional information about that bus; the information is queried on-demand from the DocumentDB store by bus ID and returned to the browser from an HTTP GET call:

public class MapController : ApiController
public object Get(int id)
var uri = new Uri(ConfigurationManager.AppSettings["docdbUri"]);
var key = ConfigurationManager.AppSettings["docdbKey"];
var dbName = ConfigurationManager.AppSettings["docdbDatabaseName"];
var collName = ConfigurationManager.AppSettings["docdbCollName"];
var client = new DocumentClient(uri, key);
var query = client.CreateDocumentQuery<BusInfo>(UriFactory.CreateDocumentCollectionUri(dbName, collName),
new FeedOptions { MaxItemCount = 1 })
.Where(bi => bi.VehicleId == id);
var result = query.AsEnumerable().FirstOrDefault();
return result != null
? new
tripid = result.TripId,
route = result.RouteShortName,
vehicleid = result.VehicleId,
timeliness = result.Timeliness.ToString()
: null;

This is a very simple example of the power of Azure IoT Hub; check out the code on GitHub if you’d like to play around with it yourself:


There’s more to explore in Azure IoT… I haven’t touched on device management, cloud-to-device communication, or IoT gateways. Want to hear more? Attend my webinar on Thursday, October 13 at 11 AM EST and learn all about IoT in the Azure cloud!

Until then!