Azure IoT Demo using IoT Hubs, Service Bus and Functions
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

IoT Demo

This is a demo of IoT capabilities in Azure using IoT Hubs, Service Bus and Azure Function Apps.
Messages received at the IoT hub are placed on a Service Bus queue, from the queue they are picked up by the Azure Function and placed into blob storage as CSV files and into a table.


The provided device simulator is written in Node.js and sends simple JSON messages including randomised wind speed data This is just example functionality, the Azure Function could carry out any processing you desire


Use supplied azuredeploy.json ARM template to deploy everything into Azure, or click this button:

Please ensure you provide globally unique names for the IoT Hub, Function App and Service Bus, these are template parameters.
Deployed resources:

  • IoT Hub plus routes and Service Bus endpoints
  • Service Bus and demo queue, plus send & listen access keys
  • Function App plus App Service Plan, the function iotEventsDemo will be auto deployed from this Github repo, and connected to the Service Bus, via a connection string called 'iotdemo-connection'
  • Storage Account used by the Function App


After deployment the ARM template will provide four outputs:

  • iotHubHostname
  • iotHubAccessKey
  • iotHubConnStr
  • storageAccountName
  • storageAccountKey

Two small Node.js apps are provided:

  • RegDevice.js - Register a new device with the IoT hub and get the device key.
  • DeviceSimulator.js - Main device simulator script, sends demo messages on a looping interval.
    After cloning this repo you will need to run npm install to install all the dependencies


The Function App puts outputs two things, both in the deployed storage account:

  • CSV data in blob storage, the output container is called 'iot-messages'. One CSV blob per message.
  • The same message is also added as a row enitity in an Azure Table, output table name is 'iottable'


Register a new device e.g. demo-device-1, with the IoT hub using the connection string (put it in double quotes):

node RegDevice.js "{iotHubConnStr}" demo-device-1

This will return the key for the new device

Run simulation as follows. Provide IoT hub host name, device-id, the device-key from the last command and also a interval in millisecs

node DeviceSimulator.js {iotHubHostname} demo-device-1 {deviceKey} 1000

Some helper CMD batch files are provided. Take copies of the .sample files and edit the sections to match your deployment


Either remove the Azure resource group, or run the cleanup Node.js script; providing storage account name and access-key, this will delete all output CSV files and the table output