Code Monkey home page Code Monkey logo

iot-edge-python-raspberrypi-connect-transparent-gateway's Introduction

IOT EDGE PYTHON RASPBERRYPI CONNET TRANSPARENT GATEWAY

Real world Azure Edge Hub scenario with raspberry pi as leaf node connects to edge transparent gateway.

Step by Step Guidance

To accomplish this tutorial, user your computer or virtual machime or LattePanda(with Widnows Enterprise) as the Azure IoT Edge transparent gateway. Mac OS support is on the way.

Use the Raspberry Pi 3 as leaf node. Prepare a temperature and humidity sensor if possible. Make sure that your gateway and leaf node correctly setup and connect to the same network.

Follow the steps to setup your Raspbeery Pi as leaft node and your Edge Transparent Gateway.

Gateway

Follow the first two parts in this document to Create an IoT Hub and Register two IoT Edge devices if you don't have any.

Create an edge device for gateway and another edge device for raspberry pi, here I name the gateway panda.

Generate all necessary certificates in gateway following this guidance.

If you has Windows 10 running in your gateway, commands could be summarized as:

git clone https://github.com/azure/azure-iot-sdk-c 
 
cd azure-iot-sdk-c\tools\CACertificates

Set-ExecutionPolicy -ExecutionPolicy Unrestricted

. ./ca-certs.ps1 
 
Test-CACertsPrerequisites 
 
New-CACertsCertChain 
 
New-CACertsEdgeDevice myGateway

Go to Azure portal Azure IoT Hub and navigate to Certificates, add a new certificate, providing the root CA file when prompted (RootCA.pem for powershell, ./certs/azure-iot-test-only.root.ca.cert.pem in Bash)

For the IoT Edge device, you could create the deployment and setup Edge for it with Azure IoT Edge extension:

Azure IoT Edge Extension

Start the IoT Edge runtime (Windows):

iotedgectl setup --connection-string {device connection string}
     --edge-hostname {gateway hostname}
     --device-ca-cert-file {full path}/certs/myGateway-public.pem
     --device-ca-chain-cert-file {full path}/certs/myGateway-all.pem
     --device-ca-private-key-file {full path}/private/myGateway-private.pem
     --owner-ca-cert-file {full path}/RootCA.pem

If you are wokring on Linux gateway, you could find corresponding command in document when you generated the certificates.

Check that you have two docker containers running: edgeAgent, edgeHub.

Raspberry Pi

Plugin a real screen to you raspberry pi or just ssh it.

Generate .crt from the PEM file you generated when step the gateway. Install it to Raspberry Pi, commands for reference:

openssl x509 -in RootCA.pem -inform PEM -out RootCA.crt 
 
sudo cp RootCA.crt /use/local/share/ca-certificates/RootCA.crt 
 
sudo update-ca-certificates 

Follow the steps to clone the python sample from https://github.com/azure-samples/iot-hub-python-raspberrypi-client-app

Follow the instructions to run setup.sh to get python sdk to work.

Run the app.py with device connectionstring appended with GatewayHostName, e.g.:

python app.py "HostName=qisun-iothub.azure-devices.net;DeviceId=pi;SharedAccessKey=XXXXX;GatewayHostName=<gateway host name>"

You could see Raspberry Pi sending messages to Edge Gateway:

pi logs

Verify the gateway receives the messages with dockers log โ€“f edgeHub

edgehub logs

Verify messages goes to iothub with VSCode extension:

Verify messages come in iothub

Note

If there is [ERR] Received message does not contain device id kind of error in edgeHub logs, comment those lines in iot-hub-raspberry-pi-kit-python-get-started#set-up-raspberry-pi/app.py could solve it:

Known Issue

iot-edge-python-raspberrypi-connect-transparent-gateway's People

Contributors

microsoftopensource avatar msftgits avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.