rezasherafat / edge-proxy

4 stars 1 forks source link

Edge proxy is an IoT Edge module that enables end-to-end connectivity to your Edge device using device streams. Ensure your IoT Hub/edge is provisioned in one of the supported regions.

To set up edge proxy for trial purposes, you need to:

alt text

To set up IoT edge in a Vagrant VM

Once done, check that IoT Edge runtime is active and edgeAgent is running:

# SSH to your vagrant VM
vagrant ssh

# Output of command below should show the daemon is in 'active (running)' state
sudo systemctl status iotedge

# Output of command below should show 'edgeAgent' module in 'running' state
# Note that it may take a few minutes for the module to be downloaded
sudo iotedge list

To build the edge proxy image

In your cloned repository folder, run:

docker build -t <image_name> .
docker push <image_name>

You can skip this step and use pre-built image rezas/edgeproxy:0.40_mqtt that is published here.

To deploy edge proxy to IoT edge

  1. Register a regular IoT device and remember the device name and the connection string

  2. Register and create IoT Edge device, make sure it's running ok

  3. Add a deployment module using Set modules

  4. In Image URI, fill in rezas/edgeproxy:0.40_mqtt to use the pre-published image or use the image_name you porvided here

  5. In Environment Variables, add these three fields

    Name Value Comment
    TARGET_IP 172.17.0.1 This is the local IP address of the host as seen by an IoT Edge module/container
    TARGET_PORT 22 Port for SSH
    CONNECTIONSTRING <Connection string of the regular device your created in step 1> This module has its own connection to IoT Hub for the Hackathon
  6. Click next, next, next, then Submit

  7. It'll take a while to pull the image, so wait a while till you see the module is running

SSH using edge proxy and Azure CLI

  1. Follow instructions to sideload the extension and login

  2. Proxy the stream:

    az iot hub proxy -n [hub] -d [device created earlier] --port [port]
  3. Open another terminal window

  4. Use a valid username and credentials to SSH to your IoT edge device.

    ssh -p [port] username@localhost

    For the case of vagrant, use ssh -i .vagrant/machines/default/virtualbox/private_key -p 2222 vagrant@localhost. Note you need to use the private key of your Vagrant VM (this is usually stored in your provisioned VM folder under .vagrant/machines/default/virtualbox/private_key.

Run edge proxy in docker


# Use a valid device connection string
CONNECTIONSTRING=""

# Default value is localhost (container itself)
export TARGET_IP=$HOSTNAME

# Default value is 22
export TARGET_PORT=22

docker run \
    --env CONNECTIONSTRING="$CONNECTIONSTRING" \
    --env TARGET_IP="$TARGET_IP" \
    --env TARGET_PORT="$TARGET_IP" \
    -it \
    <image_name>