Synpse
🤖 Devices⚡ ApplicationsTry Synpse!
  • Intro to Synpse
  • Start here
    • Quick Start (web user)
    • Quick Start (CLI)
  • Agent
    • Install
      • Raspberry Pi
      • Linux (Docker)
      • MacOS
      • NVIDIA Jetson
      • Headless (Ubuntu)
      • BeagleBoard AI
      • Bulk Provisioning
      • 🪄Beta - Universal Synpse image
      • Containerized agent
      • Configuration
    • Uninstall
  • CLI
    • Install & Usage
  • synpse core
    • Devices
      • Device Provisioning
      • HTTPS Tunnel Access
      • SSH Access
      • Device Labels
      • Environment Variables
      • Proxy Application Ports
      • OS & Architectures
      • Operations
      • Device API
    • Applications
      • Deploy
      • Secrets
      • Environment variables
      • Substitution (dynamic templates)
      • Volumes
      • Networking
      • Scheduling
      • Registry authentication
      • Using GPUs
      • Tips & Tricks
      • Logs and status
      • Application specification (API reference)
    • Account
      • Personal Access Tokens
      • Service (Robot) Accounts
      • Teams (Share Devices)
    • Monitoring (beta)
      • Device Monitoring
      • Application Monitoring
  • Manage
    • Projects
    • Namespaces
    • Quotas
  • Examples
    • 🏠Home Automation
      • Gladys Assistant
      • Home Assistant
    • 🛠️Preparing OS Images
      • Synpse CLI Builder
      • Build a custom Raspberry Pi image
      • Cloud-init (advanced)
    • 💡Dynamic Templates
    • ☁️Public Cloud IoT
      • AWS IoT Core
      • Azure IoT Hub
      • GCP IoT Core
    • 🚀Device management
      • VNC to remove devices
      • Ansible
  • On-prem Deployment
    • 🐳Docker Compose
    • 🌤️kubernetes
  • Resources
    • API Documentation
    • Deployment patterns
    • Security & Tech
Powered by GitBook
On this page
  • Technologies used
  • Azure IoT Hub
  • Deploy an application

Was this helpful?

  1. Examples
  2. Public Cloud IoT

Azure IoT Hub

Example for the Azure IoT hub application on Synps

PreviousAWS IoT CoreNextGCP IoT Core

Last updated 3 years ago

Was this helpful?

In this tutorial, we will deploy a simple open-source application that collects metrics and send them to AWS IoT Core for further processing. All code for this blog post can be found at:

- Sample metrics application - Azure IoT Hub example

Technologies used

  1. - manage devices and deploy applications to them

  2. - a lightweight message broker that can run on-prem

  3. - message broker between all devices and Azure

Steps:

  1. Create Azure IoT hub

  2. Configure rules to forward results into Azure blob storage

  3. Create Azure "Thing"/IoT device for Synpse

  4. Demo Synpse application from 3 microservices - Metrics demo, NATs messaging, Azure IoT python forwarder containers

Azure IoT Hub

Create Azure IoT hub:

az iot hub create --resource-group MyResourceGroup --name MyIotHub --location eastus --tags synpse=true

Create certificate based on .

Upload the certificates for Azure device by creating "device-identity"

Thumbprint 1: SHA1 Fingerprint=56:0E:78:56:74:F1:1B:60:73:AA:7C:8E:12:73:C4:62:01:D5:A3:10 
Thumbprint 2: SHA1 Fingerprint=81:EB:0B:27:BB:3F:BB:D8:91:AF:38:28:BE:83:E5:46:C3:0F:4D:DE

# remove colons ':' from the fingerprints

az iot hub device-identity create -n MyIotHub -d synpse --am x509_thumbprint --ptp "560E785674F11B6073AA7C8E1273C46201D5A310" --stp "81EB0B27BB3FBBD891AF3828BE83E546C30F4DDE"

For this example we gonna create message route to the storage account blob.

Create storage account:

az storage account create -n MyStorageAccountName -g MyResourceGroup -l eastus

Create container/bucket for results:

az storage container create --account-name MyStorageAccountName -n metrics

Create IoT hub endpoint for message routing:

storageConnectionString=$(az storage account show-connection-string --name MyStorageAccountName --query connectionString -o tsv)

az iot hub routing-endpoint create --resource-group MyResourceGroup --hub-name MyIotHub \
        --endpoint-name storage --endpoint-type azurestoragecontainer --endpoint-resource-group MyResourceGroup \
        --endpoint-subscription-id $(az account show | jq -r .id) --connection-string $storageConnectionString \
        --container-name metrics --batch-frequency 60 --chunk-size 10 \
        --ff {iothub}-{partition}-{YYYY}-{MM}-{DD}-{HH}-{mm}

Use routing in question with our HUB (endpoint name is same as --endpoint-name)

az iot hub route create -g MyResourceGroup --hub-name MyIotHub --endpoint-name storage --source-type DeviceMessages --route-name Route --condition true --enabled true

Deploy an application

Deploy an application. Modify application YAML with your thing endpoint.

Create certificate secrets

synpse secret create azure-crt -f device1.crt
synpse secret create azure-key -f device1.key

Deploy the application. You will need to modify other values inside YAML file.

synpse deploy -f synpse-azure-example.yaml

where synpse-azure-example.yaml is

name: Azure-IoT-Hub
description: Azure IoT Hub Synpse example
scheduling:
  type: Conditional
  selectors:
    # device selector
    azure: iot
spec:
  containers:
    - name: nats
      image: nats
      restartPolicy: {}
    - name: metrics
      image: quay.io/synpse/metrics-nats-example-app
      restartPolicy: {}
    - name: azure-iot
      image: quay.io/synpse/azure-iot-hub-example
      command: /server/azure.py
      env:
        - name: NATS_HOSTNAME
          value: nats
        - name: HOSTNAME
          # IoT hub DNS name
          value: "mj-hub.azure-devices.net"
        - name: DEVICE_ID
          # device id used when creating a device
          value: "synpse"
      secrets:
      - name: azure-crt
        filepath: /server/device1.crt
      - name: azure-key
        filepath: /server/device1.key
      restartPolicy: {}

You should see messages coming into the Azure IoT Hub

Once running, you should see application running and data coming into Azure storage account blob.

☁️
https://github.com/synpse-hq/metrics-nats-example-app
https://github.com/synpse-hq/azure-iot-hub-example
Synpse
NATs
Azure IoT Hub
Azure documentation