Waldemar Sakalus
Published © MIT

Azure IoT Edge "for Dummies" - Blink an LED

Azure IoT Edge is a very powerful way to containerize cloud workloads. This project shows the basic concepts and steps to blink an LED.

AdvancedFull instructions provided4 hours2,372
Azure IoT Edge "for Dummies" - Blink an LED

Things used in this project

Hardware components

MicroSD 16GB class 10
×1
LED (generic)
LED (generic)
×1
Raspberry Pi 3 Model B (+)
with 2.5A power supply
×1
Resistor 330 Ohm
×1

Story

Read more

Schematics

Raspberry Pi with Azure IoT Edge

Code

deployment.template.json

JSON
{
  "moduleContent": {
    "$edgeAgent": {
      "properties.desired": {
        "schemaVersion": "1.0",
        "runtime": {
          "type": "docker",
          "settings": {
            "minDockerVersion": "v1.25",
            "loggingOptions": "",
            "registryCredentials": {
              "garage": {
                "username": "$CONTAINER_REGISTRY_USERNAME_blinkcr",
                "password": "$CONTAINER_REGISTRY_PASSWORD_blinkcr",
                "address": "blinkcr.azurecr.io"
              }
            }
          }
        },
        "systemModules": {
          "edgeAgent": {
            "type": "docker",
            "settings": {
              "image": "mcr.microsoft.com/azureiotedge-agent:1.0",
              "createOptions": ""
            }
          },
          "edgeHub": {
            "type": "docker",
            "status": "running",
            "restartPolicy": "always",
            "settings": {
              "image": "mcr.microsoft.com/azureiotedge-hub:1.0",
              "createOptions": "{\"HostConfig\":{\"PortBindings\":{\"8883/tcp\":[{\"HostPort\":\"8883\"}],\"443/tcp\":[{\"HostPort\":\"443\"}]}}}"
            }
          }
        },
        "modules": {
          "blinkled": {
            "version": "1.0",
            "type": "docker",
            "status": "running",
            "restartPolicy": "always",
            "settings": {
              "image": "${MODULES.blinkled.arm32v7}",
              "createOptions": "{\"HostConfig\":{\"Privileged\": true}}"
            }
          }
        }
      }
    },
    "$edgeHub": {
      "properties.desired": {
        "schemaVersion": "1.0",
        "routes": {},
        "storeAndForwardConfiguration": {
          "timeToLiveSecs": 7200
        }
      }
    }
  }
}

Dockerfile.arm32v7

Dockerfile
FROM resin/raspberrypi3-debian:stretch

WORKDIR /app

# disable python buffering to console out (https://docs.python.org/2/using/cmdline.html#envvar-PYTHONUNBUFFERED)
ENV PYTHONUNBUFFERED=1

# Install dependencies
RUN echo "deb http://deb.debian.org/debian jessie main" >> /etc/apt/sources.list
RUN apt-get update && apt-get install -y \
    build-essential \
    python-dev \
    python-pip \
    python-setuptools \
    swig \
    zlib1g-dev

COPY requirements.txt ./
RUN pip install --upgrade pip
RUN pip install -r requirements.txt \
    RPi.GPIO

COPY . /app/

ENTRYPOINT [ "python", "main.py" ]

main.py

Python
import RPi.GPIO as GPIO
import time

# Configure the PIN # 18
GPIO.setmode(GPIO.BOARD)
GPIO.setup(18, GPIO.OUT)
GPIO.setwarnings(False)

# Blink Interval 
blink_interval = .5 #Time interval in Seconds

# Blinker Loop
while True:
 GPIO.output(18, True)
 time.sleep(blink_interval)
 GPIO.output(18, False)
 time.sleep(blink_interval)

# Release Resources
GPIO.cleanup()

module.json

JSON
{
    "$schema-version": "0.0.1",
    "description": "",
    "image": {
        "repository": "blinkcr.azurecr.io/blinkled",
        "tag": {
            "version": "0.0.1",
            "platforms": {
                "arm32v7": "./Dockerfile.arm32v7"
            }
        },
        "buildOptions": []
    },
    "language": "python"
}

Credits

Waldemar Sakalus

Waldemar Sakalus

4 projects • 18 followers

Comments