Remote IoT Development with VS Code

Gibin Francis
3 min readJun 22, 2021

--

Development environment for IoT or Docker based application will be time consuming and error prone setup. To avoid the same we can configure a remote VM and connect the same from your VS code. This will help to avoid the repetition of steps and also avoiding errors white recreating the same.

In our case, we are using Linux OS as our Remote Machine. We can use both Linux or Windows based local machine to connect to the Remote VM

Prerequisites

VS Code
Remote-SSH ( VS Code Extension)

Creating SSH Public Key

Windows users can start from the step 1 and Linux users can start from step4

  1. Open PowerShell command
  2. Run below command
    Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
  3. Close the PowerShell
  4. Open PowerShell in windows or Command window in Linux. This will generate a new public token for you.
    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  5. This will request you to enter a passphrase for the key
  6. To view the token generated from last step, use script below.
    cat C:\Users\<your_user>\.ssh\id_rsa.pub
  7. Please copy and keep the key with you, we need the same while creating new Linux VM on cloud.

Creating Linux VM on Azure

We can create a normal Ubuntu Server VM for the purpose.

  1. Login To Azure Portal
  2. Create new VM
  3. Select Ubuntu Server
  4. Choose any location and SKU based on your need
  5. Select the authentication as “SSH Public Key”
  6. The it will bring a new text area to paste your public key.
  7. Paste the key which you copied from previous section

Connecting to VM from VS Code

Now you are ready to connect your VS code to the Linux VM

  1. Open VS Code and open Command palette by “ctrl+shft+p”
  2. search for “Remote-SSH: Add New SSH Host”
  3. enter below value on the popped box
    ssh user@hostname
  4. Then you will be requested to enter the passphrase, you can enter the passphrase which you used while creating the public key
  5. Open the command palette again
  6. search for “Remote-SSH: Connect to host”

Now you are ready with the setup to start your IoT or docker based application. Now the VS Code commands will be executing the same in the Linux VM

for advanced steps or more you can refer below link
https://code.visualstudio.com/docs/remote/ssh

Configure the VM

Now we can configure the VM, you can run the commands from the VS Code terminal

# Install Docker
sudo apt update
sudo apt install -y docker.io

# Configure Docker
sudo usermod -aG docker $USER
sudo reboot

# Install .NET Core and its dependencies
sudo apt-get install -y apt-transport-https
wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt update
sudo apt-get install -y dotnet-sdk-3.1

# Install docker-compose and its dependencies
sudo apt install -y curl
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

# Install IoT Edge Hub Dev Simulator and its dependencies
sudo apt install -y python3-pip
python3 -m pip install --upgrade pip
sudo -H python3 -m pip install --upgrade pip
sudo -H python3 -m pip install --ignore-installed PyYAML
sudo -H python3 -m pip install --upgrade iotedgehubdev

Now you are ready to do the Azure IoT Edge Development

Happy coding

--

--

Gibin Francis
Gibin Francis

Written by Gibin Francis

Technical guy interested in MIcrosoft Technologies, IoT, Azure, Docker, UI framework, and more

No responses yet