Skip to content

Instantly share code, notes, and snippets.

@danielscholl
Last active May 7, 2019 18:19
Show Gist options
  • Save danielscholl/2c9648f73a3f282166aace9466e56ab9 to your computer and use it in GitHub Desktop.
Save danielscholl/2c9648f73a3f282166aace9466e56ab9 to your computer and use it in GitHub Desktop.

Demo (Prepare)

Create an Ubuntu Workstation and use VSCode (Insiders) remote-ssh extension to SSH to it.

Install Azure CLI

# Install CLI
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash

# Switch to Gov Cloud and Login
az cloud set --name AzureUSGovernment
az login

# Install the IoT Extension
az extension add --name azure-cli-iot-ext

Install DirEnv

# Install Package
sudo apt-get install direnv

## MODIFY .bashrc ##
vi .bashrc
eval "$(direnv hook bash)"

source .bashrc

Install NodeJS

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt install nodejs
sudo apt-get install build-essential

Install Docker

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

USER=$(whoami)
sudo usermod -aG docker $USER

Clone Repositories

mkdir source
cd source

git clone -b gov https://github.com/danielscholl/iot-resources.git
git clone -b gov https://github.com/danielscholl/iot-device-edge.git
git clone -b gov https://github.com/danielscholl/iot-device-js.git

Demo (Hub)

Provision IoT Resources

cd iot-resources

# Provsion Resources
./provision.sh iot # Initials

Simulate a Device

cd iot-resources

# Terminal Instance 1 -- Device
DEVICE="my-device"
az iot hub device-identity create -n $HUB -d $DEVICE

# Terminal Instance 2 -- Monitor
az iot hub monitor-events -n $HUB

# Terminal Instance 1 -- Simulate Device
az iot device simulate -n $HUB -d $DEVICE --data "Message from device!" --msg-count 5

Build PKI and Create Certificates

cd iot-resources

# Initialize Certificate Management
./init-ca.sh

Demo (Devices)

Create a Service Principal

After creating a Service Principal you MUST add API access for Windows Azure Active Directory and enable the following permissions

  • Read and write all applications
  • Sign in and read user profile
cd iot-devices-js

# Create a Service Principal
Subscription=$(az account show --query id -otsv)
az ad sp create-for-rbac --name "http://IoT-Principal" --role="Owner" --scopes="/subscriptions/$Subscription"

# Expected Result
{
  "appId": "00000000-0000-0000-0000-000000000000",
  "displayName": "Terraform-Principal",
  "name": "http://Terraform-Principal",
  "password": "0000-0000-0000-0000-000000000000",
  "tenant": "00000000-0000-0000-0000-000000000000"
}

appId -> Client id.
password -> Client secret.
tenant -> Tenant id.

Simulate Devices

cd iot-devices-js
npm install

# Simulate Symmetric Key
npm run device
npm start
npm rum monitor     # Terminal Instance 2
npm run clean

# Simulate x509 Self Signed
npm run device:x509
npm start
npm rum monitor     # Terminal Instance 2
npm run clean

# Simulate x509 CA Signed
../iot-resources device $DEVICE
npm run device:ca
npm start
npm rum monitor     # Terminal Instance 2
npm run clean
  • Analyze D2C Messages
  • Analyze C2D Messages
  • Analyze DM Messages

Demo (Edge)

Provision Edge Resources

EDGE_DEVICE="edgegov"

# Create Edge Certificate
cd iot-resources
./device-cert.sh edge $EDGE_DEVICE

# Setup Environment Variables in .envrc
cd iot-device-edge

export GROUP="iot-resources"
export DEVICE="edgegov"
export DNS="danielscholl.info"
export HUB="<your_hub>"

# Provision Edge VM
DEVICE=$EDGE_DEVICE DNS="danielscholl.info" ./provision.sh iot   # Initials

## AFTER reboot ##
ssh <ip> 
./init.sh

Setup DNS CName

Setup Edge Module Routes

cd iot-device-edge
./deploy.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment