Editor's note: I am pleased to bring you a new young blogger on Planet Analog, Tyler Deuty. He will be occasionally blogging and bringing us a really good perspective from the younger generation. I bring his Open-Source/Linux-related blog to Planet Analog because it is so intertwined with Analog applications and the IoT. We have seen many IoT applications using Linux that are Analog-related such as Voice, Wireless or Infrared Control? and The Electronics Cooperative Concept, Part 1 and many more as well, so I think this is a good thing for Analog designers to at least consider in this new Millenium of electronic design. It’s another tool in our design tool-belt. Please share with our audience, in the comment section below, more ideas of Analog/IoT applications within this Linux app realm.
In November 2016, Microsoft joined the Linux Foundation. With the Anniversary Update for Windows 10 they also provided the result of their partnership with Canonical in the form of a Bash shell that runs on Ubuntu on Windows 10; a.k.a. the WSL or Windows Subsystem for Linux. This has opened the door for the long-sought possibility of using the Windows and Visual Studio pairing that developers are comfortable with to develop using the g++ compiler and GNU Project DeBugger (GDB) debugging. Another key advantage is that all of this can be done without the need for setting up a resource-heavy virtual machine.
I found this to be the main reason to switch to developing using the WSL due to my mobile development platform having a high-DPI screen that can be a pain to get a Linux Virtual Machine (VM) to make good use of as well as not having a lot of disk space for a virtual hard drive. I probably don’t need to tell you that being able to work on the Windows operating system but compile and debug using g++ and GDB is a groundbreaking and powerful capability. Compiling with g++ of course means that the application will be able to run on devices using the *nix operating systems, including many IoT devices.
This is one way to develop applications for the IoT in the Windows environment. Utilizing the WSL will allow you to push your code out to Raspberry Pi devices and other small form-factor devices that run *nix operating systems, without having to learn or re-learn how to setup and work in a Linux environment and IDE.
Below is the entire step-by-step process for getting started developing Linux applications with one computer running Windows 10. I have assumed that you already have Visual Studio 2015 installed as well as the Anniversary Update for Windows 10 or higher, which comes through Windows Update.
Installing the Windows Subsystem for Linux (WSL)
1. The first step is to make sure that you prepare your machine for development. To do this, go to Start -> Settings icon (gear) -> Update and Security -> For developers, then select the radio button for “Developer mode.”
2. Now we can install the subsystem. Right-click the start button and choose Programs and Features from the top of the list. On the left-hand side of the window, click “Turn Windows Features on or off” and then scroll down to Windows Subsystem for Linux (Beta). You’ll notice that it is in beta; it may well be that a lot of this tutorial will no longer be needed with future updates to this system. Windows will need to restart before you can continue with the installation.
3. After logging back in from a restart, go ahead and open a command line (Right-click start and select command prompt) and type in ‘bash’ without the single quotes. Type in ‘y’ to accept the install and then watch as Ubuntu is installed to your Windows 10 computer. Also, follow the prompts for creating a UNIX user.
4. You should now be able to hit start and type in ‘bash’ and pin Bash anywhere that is easily accessible for you in Windows. See this article for more info on how you can better integrate the WSL into your normal workflow on Windows.
Note: If you use Bitdefender firewall, you should disable it fully before you can update your WSL environment. You can safely re-enable and still SSH in with Visual Studio. This may also apply to any other anti-virus software.
Configuring SSH in the WSL
Now that you have a Linux environment living on your computer, it’s time to take advantage of it. For Visual Studio to compile and debug your code in WSL, it must be able to SSH into it. If you’ve never edited files in a Linux command line interface before, here is an exemplary tutorial on how to use VIM.
1. The first step is quite counter-intuitive: uninstall the SSH server program. To do this, open your bash shell and type:
2. In some cases, it’s necessary to ensure that your WSL is fully updated.
3. Now you’ll need it back, this time with a fresh install. Type the following to install it from bash:
4. The configuration for SSH needs to be adjusted to allow connections. Make the following changes in sshd_config (path to file in below command). If the line already exists, just comment it out and change its value. If it doesn’t, add it anywhere in the file. Add your new UNIX username in the place of ‘user.’ You can use any port for SSH that isn’t already used by something else.
5. Restarting the ssh service will apply these new changes to the configuration.
Your bash shell is now ready to accept incoming SSH connections from the local machine. You can download Putty here and try a connection to 127.0.0.1 using your custom port and see if it works. If it works here, there’s a good chance Visual Studio is now able to connect.