I’ve had this project on my list to try for a while. I wanted to turn an LED on/off on a breadboard sitting on my desk when I turned on/off a virtual machine in Azure. Before I got into all the details, here is a video showing it in action. This is at a speed of x2 and I cut out some time waiting for the machine to turn on. You can view the full length video (~ 4 min) here
If you’re curious all the details in what I used as well as the source code are below.
This is the hardware I used for the setup, not all of it is necessarily required, it’s just what I use.
- Raspberry Pi 2
- SanDisk Ultra 64GB Micro SDXC Memory Card
- Raspberry Pi 2 Clear Case
- Edimax Wireless USB Dongle
- Break Out Board and Cable
- Breadboard I had laying around the house from college
- MV54164 LED Bar – Also from the college days
- A bunch of wires – Again from the college days
- An Azure Data Center
The wiring isn’t all that complex, just the Raspberry Pi 2 connect to the header with one of the GPIO pins wired up to the LED…nothing fancy.
First of all, I’m not a developer, so for you developers out there, the code may look a little rough. I welcome any input though on how I could make it better. This is the first time I’ve done any development in Node.js outside of just 3 or 4 lines to play around with an LED and a “Hello World”. I would love to keep going with this to the point where you could select VMs and Map them to either a pin on the Raspberry Pi or two a row of LEDs to monitor multiple VMs of your choosing. Right now, the code is just hard coded to point to one of my VMs. The current source code is here – https://github.com/benstegink/RaspberryPi/blob/master/MonitorAzureVM.js
If you want to see more of what I’ve been playing with, all the Raspberry Pi stuff I’ve done is in the same – https://github.com/benstegink/RaspberryPi
Sample Resource File
In order to pass in the subscription ID and the location of the certificate for the azure-asm-compute module. Fore more information on where to get the certificate see this blog post Here is a sample of what’s in the resource file.
"subscriptionID": "[Subscription ID GUID]",
"AzureComputeCertPath": "certs/[cert file name].pem"
The Modules in the Code
The modules I used in the code are:
Other Required Software
Azure CLI (for setting up certificates – see post here. There is a TON of great stuff in here! Especially if you want to manage Azure from a non-PowerShell enabled machine (mac and linux). For this project I needed this in order to get the certificates configured for the azure-asm-compute module.
Quick2Wire (access to GPIO) – you shouldn’t need this per the documentation with the onoff module. However, I still had issues accessing the pins and this seemed to solve the issue. There are a bunch of ways you can install it, I think this was the way I used – http://quick2wire.com/articles/how-to-add-quick2wire-as-a-raspbian-software-source/ If you want a sample program just to test out access to GPIO see the LEDFlash.js file here.
SDKs and Other Handy References
All possible statuses your VM could return – https://msdn.microsoft.com/en-us/library/azure/ee460804.aspx. In the video you see at one point in time my VM returns a status of “RoleStateUnknown”. This is documented, but is returned from my VM fairly frequently.
Windows Azure SDK for Node.js – http://dl.windowsazure.com/nodedocs/
Windows Azure SDK for Node.js – Compute Management – https://github.com/Azure/azure-sdk-for-node/blob/master/lib/services/computeManagement/README.md
Just a few things I would like to do next:
- Get the same thing working with VMs in ARM Mode as well.
- See if I can get the LED flashing more consistently. This could be difficult just based on how Node.js works
- Create a configuration to be able to select which VM/VMs you want to monitor and be able to have multiple LEDs monitoring multiple VMs.