Strict Standards: Non-static method Configure::getInstance() should not be called statically in /usr/www/bchalk/public/cake/bootstrap.php on line 38
Home - Brandon Chalk
Brandon Chalk
  • University of Washington, Seattle
  • University of Washington, Tacoma
  • M.S. in Electrical Engineering
  • B.S. in Computer Engineer & Systems
  • B.S. in Computing & Software Systems
  • Minor in Mathematics
  • Python on a Web Role for Microsoft Azure

    July 13, 2011, 9:46 am
    I had no idea this would be so difficult. If anyone has any suggestions to make this easier, I'd be very interested to hear them.

    Quite simply all I wanted was Python support on Azure without doing anything after an instance is initiated.

    What about a Web Cgi Role? That sounds right! How do they do it with PHP?

    Simple, add this in your Web.config:
        <add name="FastGGI Handler"
    path="{file or extension, ex: *.php}"
    scriptProcessor="%RoleRoot%\approot\cgi-handler.exe|arg1 arg2 ..."
    resourceType="Unspecified" />

    And this in your Web.roleconfig:
    <application fullPath="%RoleRoot%\approot\cgi-handler.exe" arguments="arg1 arg2 ..." />

    Okay, but what about something that isn't fastCGI? I could never get Python to work under FastCGI and it doesn't look like I'm alone going through the IIS forums. But it works as a regular CgiModule, so that's what I did. After a lot of trial and error this is what I have come up with.

    Added to my Web.config:
        <add name="Python"
    scriptProcessor="D:\python27\python.exe %s %s"
    resourceType="Unspecified" />

    Now this has a problem, how do we get Python installed first and how do we get it added to our isapiCgiRestriction white-list? You can only set fastCGI applications in Web.roleconfig.

    Startup scripts!

    Credit goes to Steve Marx who created Smarx Role which is on CodePlex for the idea and a head start on how to design the scripts.

    Now Smarx as far as I can tell never adds the handler to IIS so I was on my own for that. So lets take a look at the project's file layout and the startup scripts I used:

    Okay so there are two major parts here, downloading the files and installing them.

    Lets take a look at how we download our files, again credit goes to Steve Marx for this.

    cd /d "%~dp0"
    powershell -c "set-executionpolicy unrestricted"
    powershell .\downloadstuff.ps1

    function download([string]$url) {
    $dest = $url.substring($url.lastindexof('/')+1)
    if (!(test-path $dest)) {
    (new-object$url, $dest);
    foreach ($url in (
    )) { download $url }

    And the next script will install Python and add it to our isapiCgiRestriction white-list so that IIS will actually use it.

    cd /d "%~dp0"
    setlocal enableextensions enabledelayedexpansion

    msiexec /i python-2.7.2.msi /qn TARGETDIR="%PYTHONPATH%" /log installPython.log

    %PYTHONPATH%\python -c "import sys, os; sys.path.insert(0, os.path.abspath('setuptools-0.6c11-py2.7.egg')); from setuptools.command.easy_install import bootstrap; sys.exit(bootstrap())"
    %PYTHONPATH%\scripts\easy_install pip

    echo y| cacls "%PYTHONPATH%" /grant everyone:f /t

    "%systemroot%\system32\inetsrv\AppCmd.exe" set config -section:system.webServer/security/isapiCgiRestriction /+"[path='%PYTHONPATH%\python.exe %%s %%s',allowed='true']" /commit:apphost

    exit /b 0

    And to make sure our startup tasks are launched we have to make changes to our Service Definition file.

    <?xml version="1.0" encoding="utf-8"?>
    <ServiceDefinition name="WindowsAzureProject1" xmlns="">
    <WebRole name="WebCgiRole1" enableNativeCodeExecution="true">
    <Task commandLine="startup\downloadstuff.cmd" executionContext="elevated" />
    <Task commandLine="startup\installPython.cmd" executionContext="elevated" />
    <Site name="Web">
    <Binding name="Endpoint1" endpointName="Endpoint1" />
    <InputEndpoint name="Endpoint1" protocol="http" port="80" />
    <Import moduleName="Diagnostics" />
    <Import moduleName="RemoteAccess" />
    <Import moduleName="RemoteForwarder" />

    And with that all done we should have Python support when the server starts. To test, lets add our
    #!/usr/bin/env python
    # -*- coding: UTF-8 -*-

    # enable debugging
    import cgitb

    print "Content-Type: text/plain;charset=utf-8"

    print "Hello World!"

    Should work! If you have any problems, make sure to RDP in to the server and turn on all extended error pages in the IIS configuration to see if it's something simple.
  • Quickstart guide to getting a VM Role on Azure

    July 13, 2011, 8:39 am
    Well this was a fun one, I had a VMWare image I wanted to get on Azure in the VM Role. One, quick note, don't. Convert it over to Hyper-V or don't bother.

    I'm not saying this is the best way, this is just how I did it and I now have my VM live in Azure so it works.

    I ended up giving up and just installed a fresh copy of Windows 2008 R2 with the Hyper-V role on my personal laptop on a spare hard drive I had laying around and I can just use that to make the image and it works a million times easier with no conversions.

    Plus the ability to do a base VHD + incremental change VHDs a later time to only have small uploads to Azure is very nice if I figure out how to do it right.

    1. Create the VHD by following directions here:

    Notes and helpful hints:
    • Do not skip installing utilities and sysprep or you'll just have to do it again
    • Small instance CANNOT be greater than 35GB, do not use a 40GB HDD setting unless you are planning on using a Medium or larger instance. VHDs greater than 65GB cannot be on Azure period. A side note, converting a 40GB Windows install on VMware to a 35GB is way harder than it should be.
    • Use Hyper-V if at all possible, when using VMware the following apply:
    SubID;CertificateThumbprint=Certag -LiteralPath Path

    7. Watch it run! See that wasn't so bad.

    Helpful Sites I found along the way:
  • Project Power

    May 7, 2011, 11:50 pm
    It's been a long time since I've updated my blog. I have been busy with work, school, and life. I am going to try and get some updates of my senior project for my degree.

    Project Power is a device I am creating that is designed to be a standalone device to monitor and graph power usage of typical household devices in real time.

    Goals for the project:
    • 2 Independent channels
    • Live on screen graphing of power, should auto scale
    • SD card logging to export to Excel
    • Standalone device capable of running without a PC
    • Real-Time Clock for timestamps
    • Accuracy within 5%
    • Buttons to change sample interval and toggle SD logging

    In the first stages I did quite a few mockups, tested components, and put the pieces of the puzzle together.

    First mockup of the hardware (sorry for poor quality pictures):

    And as I realized my display and components wouldn't fit in the cramped box I moved to a larger project box with a quick mockup of what I wanted on the display:

    Pieces were cut and the display was mounted:

    Now to get a little bit back to the testing of components, I wanted to test the LCD and well it was quite a pain to do a breadboard (although I did) so I put together a small LCD Driver board:

    And I tested the current sensors:

    And the Real-Time Clock:

    Put it all together and you get a massive PCB:

    Populate all the components and wire up the 12awg (excessive I know) for the outlets:

    And well not that we actually have real 120VAC going through our current and voltage sensors lets take a look at what we are actually reading on an oscilloscope, this is actually a laptop power supply plugged in:

    This is a 40W incandescent lightbulb with voltage * current displayed for instantaneous power:

    At this point I'm pretty happy with the hardware and I want to get focused on some software, I've got a good start with autoscaling, SD support, RTC support, and one channel visible here:

    I wish I was updating this as I went, unfortunately I just have not had the time. I will try and make things coherent and do this article again in the Work section when I finish the project and have time to do a proper write-up with all of the details I know I'm leaving out. This has all been done over the last 6 months basically in the spare time I've set aside for the project, lots of the testing stages were completely omitted in this post, hopefully I can add some of it in at a later time.
  • Baking an HP TX2500Z Tablet Motherboard

    November 5, 2010, 11:43 pm
    Edit: Stopped working again. Now it has a cracked screen, not sure how that happened.

    About a week ago my laptop died. No it didn't make any funny noises, emit smoke, or do anything interesting, it just stopped working. Turn on the power button and the num lock and caps lock lights flash and blink once indicating a CPU error according to the HP support website.

    After some research I learned it is almost never the CPU itself that goes, but rather the motherboard... And it's quite common in this model. Well that's no good the cheapest refurb motherboard was almost $150, why not try something crazy first? I've heard of it working for other laptops, I've heard of it working on video cards. I baked it. 380F in the Over for about 6 minutes when turned the oven off and I opened the door to let it slowly cool.

    Getting ready for the oven:

    And guess what? It actually worked. I was shocked. The laptop now boots.

    Great now I have to take my SSD back from my PC. I figured since it wasn't much use just sitting in a dead laptop, I have it in the desktop running in a RAID 0 with my other SSD (Yes, it flies in RAID 0, Photoshop CS5 opens in under 3 seconds). Anyway, just sharing a success story.

    Here it is still in pieces, but working:
  • Prototype Mode

    November 5, 2010, 1:26 pm
    With the body taken off and some quick testing software for the controller board we hooked up the microcontroller to the Pololu Dual Channel H-Bridge Power Driver for the motors, connected the Atari joystick and got everything to work.

    Wireless parental override controls and steering control is still to come. All of the teams seem to be progressing on their parts, the wireless controls are impressive. I'm interested in see the steering prototype work, we are using I2C to communicated between two boards for control of the steering. Should be fun to see how it finishes.

    The cart works very well, lots of torque and with no weight without a child or the body on paired with a slick floor it had a hard time moving any where, adding the weight from a backpack really helped.
  • Lab - Soldering

    October 21, 2010, 11:47 am

    Flickr: AA7JC

    Well pursuant to the Computer Hardware Engineer part of my self proclaimed title, I had my lab yesterday for class and volunteered to give a quick demonstration on how to solder. We were just soldering some leads on to a motor, easy.

    Apparently it's not as intuitive as I thought that you have to heat up the part you are soldering, not just the solder. Perhaps the years and years of soldering during electronic experiments and hours of sitting upside down in my car working under the dash or even the years of building RC Cars, but some stuff I would think is just common sense.

    Takes practice I guess .