To summarize our current location: We’re on the path of building an administration website built using the AngularJS framework, hosted on the BeagleBone Black (BBB). The purpose of the administration site is to allow us to adjust key configuration parameters and launch other applications. Essentially, I want to provide a web interface to the BBB, similar to the one provided for a network router.
Having written a prototype node.js app which provides us near real-time data via the sockets.io module, we are ready to begin building out the application to do more. Because we’re going to do a lot more, we need to better define our development environment.
In this post, I’ll document the development environment I’m using to build out the administration web application then in subsequent posts I’ll delve into discussions on our AngularJS MV* infrastructure and tying Angular to core BBB functions.
Visual Studio: A Most Unconventional Development Environment for BBB
So let’s start. If you don’t have VS2013 already, head to the the Visual Studio website and download it. It’s not a small piece of software, so allow 15-30 minutes to download and install.
Microsoft Visual Studio Community 2013 Website
Before we jump in, I’m also going to add in the Web Essentials 2013 for Visual Studio plugin to give us even more developer friendly tools. Information on Web Essentials is available here, but the download is kept here. Once everything is installed, we’re ready to fire up Visual Studio.
Visual Studio Community Edition
Creating a VS2013 node.js Project
To start, we’ll create a project, but reference our existing work, then we’ll import the relevant files to get to a point where we are ready to work.
Step A – Create Visual Studio Node.js Project
Step B – Import Files into Visual Studio 2013
Step C – Up and Running in Visual Studio with node.js Project
Preparing the VS2013 for Debugging: Reconciling the Required Server Modules
If we try debugging, by pressing the green arrow, we’ll run into two problems:
- Visual Studio will ask us to build the project. VS2013 is not really compiling, but it needs to build a framework for it to support our debugging efforts. This is pretty easy to get around, we just tell VS2013 OK, do what you need to do.
- Our application will fail in the command line, because we’re missing our referenced libraries. To fix this, we need to import the modules into our project.
Specifically, we need the following modules for the server:
- http, fs – since these are included as part of the base node installation, we do not need to install them
- socket.io – we will import this module, using VS2013’s npm package installation tool
- bonescript – we will modify our code to not require this, using node’s fs module instead
We can install socket.io by selecting npm (Node Package Manager) from the Solution Explorer window, right-clicking and selecting the “Install New npm Packages …” option. The first time you do this, it will download all of the available module options (there are a ton), but subsequent times, it will be near instantaneous to get to the window we want.
VS2013 – Install npm Packages
As per our first few lines of the app.js file, we can see the list of modules we need to include. Simply search for the relevant modules and add them, Visual Studio will add them to the project and, optionally, to the package.json file. Make sure that you include the right modules, because there are so many of the same name – if you make a mistake, simply remove them from the Solution Explorer tree.
VS2013 – Install npm Module Dialog
We will also modify our code to use the fs module, instead of the bonescript module, to have a more generic code base.
Running and Debugging our Application
With this complete, we’re ready to test our project. We can select the Debug menu’s “Start debugging” option, press green arrow button on the menu bar or simply press the F5 function key to launch the application. Of course, we won’t see a temperature, because we’re running the application on a PC for the moment, but it will prove that our application is functioning and ready for debugging. We can even use breakpoints and the watch windows if need be.
VS2013 – Project Debugging
Adding Some Polish to the Client-Side Presentation Through the Bootstrap.js Module
To add Bootstrap to our client HTML, we’ll first have to reference it within a script. For simplicity-sake, we’ll use the provided CDN in our HTML header. We can now add some basic commands to make some improvements to our previous gaudy html. Specifically, we’ll throw in a couple of labels to pretty our browser presentation:
Adding Some Basic Bootstrap to our App Client
Running App and Client (with Bootstrap)
Final Step – Upload to the BeagleBone Black
There are two way to manage how our code now gets to the BBB:
- Use GitHub – in this case you’ll add, commit and push the changes to the repository, then pull them down from the BBB. This is the recommended approach
- Use WinSCP – upload the files to BBB directly. This may be faster and more direct. Furthermore, it is possible to set up a directory synchronization task to manage host and target directories automatically.
For this blog entry we will show the second option, using WinSCP’s synchronization functionality. In this method, you’ll might want to omit synchronizing the VS2013 directories and files, as shown below:
Using WinSCP Synchronize Directories Feature
We can PuTTY to the BBB and run our application:
Finally, I’ve updated the repository here: https://github.com/bitstobrowser/AdminApp