Setting up Sublime Text with LESS compile on save in Windows

Setting up Sublime Text and less autocompile in Windows with the less2css plugin can be tricky because most solutions are geared to *nix. Most solutions I found for this include using a random git repo and executing code from them which I don’t trust.

Here are the steps I used:

  1. Install node using the Windows installer: https://nodejs.org/en/
  2. Open a command prompt and navigate to the folder that contains node.exe, you chose this when installing node. Mine is “C:\Program Files\nodejs\”
  3. Install less from command line by running this command:
    npm install less
  4. Install less cleanup plugin by running this command:
    npm install less-plugin-clean-css
  5. Navigate to the less bin folder in explorer, mine is: “C:\Program Files\nodejs\node_modules\less\bin\”
    1. There should be a lessc file in there, if not follow the steps above until there is one
  6. Create a new text file in the less bin folder called “lessc.cmd”
  7. Edit lessc.cmd in a text editor and enter the following line:

    @”C:\Program Files\nodejs\node.exe” “C:\Program Files\nodejs\node_modules\less\bin\lessc” %*

    1. Note: Change the paths to match your local system
  8. Add lessc to the path environment variable.
    1. My entry looks like this:
      ;C:\Program Files\nodejs\node_modules\less\bin
    2. If you have an issue with your path variable being longer than the default 1024 character limit, I recommend using SetEnv: http://www.codeproject.com/Articles/12153/SetEnv
  9. Open a new command prompt and type “lessc”, you should see the various commandline options listed along with some helpful information.
    1. If you see
      ‘lesscc’ is not recognized as an internal or external command,
      Verify each step above to make sure that they all completed successfully. Also make sure to open a NEW command prompt after setting the path variable.
  10. In Sublime Text, open the package manager with ctrl+shift+p, type install, and run Package Control: Install Package
    1. When the prompt comes up type less2css and hit enter
    2. Open a .less file for editing and hit save, it should automatically generate the .css file for you now

Arduino WiFi Shield and Web Server Tutorial

Introduction

I’ve always wanted to extend my web development skills in to the real world. It’s nice to be able to make a useful site, but it doesn’t really change your life for the better when you’re not on a computer. Enter embedded systems, and specifically the Arduino. I’ve been fascinated by embedded systems ever since I was a teenager, but the barriers to entry are high and I focused on other things instead. The Arduino changed all of that by making embedded systems extremely accessible. The story of the Arduino and open source hardware is a long one, too long for this introduction, if you’re interested you should start at their website: http://arduino.cc/en/Guide/Introduction

The goal of this project is to tie in a few sensors around my house and allow them to be read via a webserver onboard the arduino. Here’s how it works:

  1. When the Arduino powers up it will run a setup routine that connects it to my WiFi network
  2. After the setup routine the Arduino enters in to an infinite loop, listening for connections to the onboard webserver.
  3. When a web client connects the Arduino will read data from the sensors and send it to the client.

That’s all there is too it, it’s incredibly simple. As with all things technical I did run in to some bugs, but I was able to get it up and running in an evening. If you’ve ever wanted to explore embedded systems, now is the time! I can’t believe how simple this was. Anyone with a software background should be able to start this project with no experience and have it completed in a few hours.

What you’ll need

Instructions

  1. Download the Arduino IDE if you don’t have it and start it up
  2. Mount the WiFi shield on top of the Arduino. The WiFi shield header pins slide right in to the Arduino headers.
  3. Connect the Arduino via USB to your computer
  4. Open the example sketch WiFi->ScanNetworks and hit the upload arrow to program the board. Then open the Serial Monitor using the magnifying glass button.
  5. Verify that your WiFi SSID is displayed correctly and that it is using one of the supported encryption types shown here: http://arduino.cc/en/Guide/ArduinoWiFiShield
    1. If the SSID isn’t displaying correctly see the troubleshooting section below
  6. If everything looks good load the example sketch ConnectWithWPA, enter your WiFi credentials, and hit the upload arrow. Open the Serial Monitor using the magnifying glass button. Check to make sure that the Arduino connects and gets and IP address. If not see the troubleshooting section below.
  7. If the Arduino is able to connect and get an IP address we’re ready to fire up the webserver. Load the example sketch SimpleWebServerWiFi, enter your WiFi credentials, and hit the upload arrow.
  8. Open up the Serial Monitor again and determine what the Arduino’s IP address is. The IP address consists of 4 numbers separated by periods, here’s an example: 127.0.0.1. Once you have the IP address, you can open a web browser on your computer, and enter the IP address in the address bar and navigate to the page, it should look something like this: http://IP_ADDRESS_GOES_HERE
  9. In your web browser, you should see the readings off of the analog pins on the page. If the webpage doesn’t load check the Troubleshooting Webserver port is not open below. Otherwise, congratulations! You just built a webserver on an embedded system! Depending on the kind of sensors you want to use you’ll need to hook them up to the right pins and use the proper code to read them (there are plenty of code samples on the internet), and now you’ll be able to read them using the webserver. Keep in mind that Digital Pin 7 is used by the WiFi shield and should not be used for sensors.

Conclusion

You made it! This is more of a stepping off point than anything. The possibilities available to you with a knowledge of programming and an embedded system with RF connectivity are mind boggling. For starters, check out Making Things Talk: Using Sensors, Networks, and Arduino to see, hear, and feel your world and Physical Computing

Troubleshooting WiFi Shield Wont Connect, shows wrong SSID during scan

I ran in to an issue where the Arduino couldn’t connect to my router for two reasons. The first was the my router had a Guest network that it broadcasts a separate SSID for on the same channel, and this confuses the Arduino WiFi library. It showed up as a really long string in the WiFi scanner sketch. I was able to fix this by disabling it in my router, if you are seeing this you’ll need to figure out how to disable the guest network setting on your router.

After resolving the first issue I noticed that the WiFi scanner was concatenating my SSID with the next SSID in the list. This appears to be an issue with the WiFi library when reading long SSID names which causes it to overflow in to the next SSID name before finding a terminating character. The fix is simple, shorten your SSID. Hopefully the Arduino folks fix this some day.

Fixing both of these issues allowed me to connect just fine.

Troubleshooting Webserver port is not open / connection refused / Upgrading Arduino WiFi firmware

Although the sketch ran just fine, when I tried to visit the page nothing happened. When I tried connecting via telnet I got connection refused on port 80, at which point we know that the webserver is not actually running/listening on that port. This was due to an old version of the Arduino WiFi shield firmware, mine shipped to me with version 1.0. To check what version of the firmware is on your WiFi shield, add the following lines to the Webserver sketch in the setup function:

Serial.print(F("Firmware Version:"));
Serial.println(WiFi.firmwareVersion());

If you see a version that is older than 1.1, you need to upgrade. Here are the instructions for doing this on OSX:

  1. Install Ports if you don’t have it, see here: http://www.macports.org/install.php
  2. Make sure you have the latest version of the Arduino IDE installed, as of this writing it is 1.5. The Arduino IDE has a newer version of the firmware in the Resources directory.
  3. For some reason the dfu scripts look in a different directory than what the Arduino IDE has, copy the folder /Applications/Arduino.app/Contents/Resources/Java//hardware/arduino/firmwares/wifishield/binary to /Applications/Arduino.app/Contents/Resources/Java//hardware/arduino/firmwares/wifi-shield
  4. Using ports, install the dfu-programmer in a terminal window
    sudo port install dfu-programmer
  5. Now you can do the upgrade. To prepare unplug/power down the Arduino.
  6. Remove the Arduino WiFi shield from the Arduino.
  7. BEFORE connecting the WiFi shield to your computer, move the jumper J3 so that the pins are connected. There is only one on the board, so it’s easy.
  8. Connect the WiFi shield to your computer via a mini usb cable.
  9. In a terminal window
    cd /Applications/Arduino.app/Contents/Resources/Java//hardware/arduino/firmwares/wifishield/scripts
    
    sudo sh ArduinoWifiShield_upgrade_mac.sh -a /Applications/Arduino.app/Contents/Resources/Java -f shield
  10. That command should end with
    Done. Remove the J3 jumper and press the RESET button on the shield.
    Thank you!
  11. If there are any errors, such as No Such File you need to make sure you copied the folders correctly in step 3. Otherwise do what the message says, remove the J3 jumper, and hit the reset button. Disconnect the shield from your computer, and pop it back in the Arduino.

After doing all of that I was able to hit the webserver.

Amazon Autoscaling Tutorial

Amazon’s EC2 with autoscaling is a great way to maximize performance and minimize costs. Unfortunately the amazon autoscaling setup is only configurable via commandline which can make it seem a little daunting at first. Basic autoscaling is very simple, you only need a few items:

  • Launch Config – controls the ami, security group, and instance size
  • Autoscaling Group – controls the region, load balancer to attach to, minimum number of servers, and maximum number of servers
  • An EC2 server image to autoscale
  • An EC2 loadbalancer

Here is list of steps to get it up and running:

  1. Make an AMI of the server that you want to autoscale. Make sure that you can deploy code to it on the fly, using a tool such as Beanstalk for example.
  2. Make a loadbalancer if you don’t already have one
  3. Download the amazon autoscaling tools, the zip is named something like AutoScaling-1.0.61.0.zip
  4. Open the folder in the commandline
  5. Set your environment variables
    export AWS_AUTO_SCALING_HOME=/PATH/TO/AutoScaling-1.0.61.0/
    export JAVA_HOME=/PATH/TO/JAVA
    You can find java home by running which java in *nix
  6. ./as-create-launch-config ProdLaunchConfigV1 –image-id ami-123abc –instance-type m1.small –key YOUR_SECURITY_KEY –group YOUR_GROUP –I YOUR_KEY –S YOUR_SECRET
  7. ./as-create-auto-scaling-group ProdAutoScaleGroupV1 –launch-configuration ProdLaunchConfigV1 –availability-zones us-east-1b –min-size 1 –max-size 10 –load-balancers loadbalancer1 –I YOUR_KEY –S YOUR_SECRET

Side note: If you have to change the settings, you wont be able to delete the autoscaling group until all the instances are terminated, which is impossible unless you modify the autoscaling group with a minimum of 0 servers. Example:

  1. ./as-describe-launch-configs –I YOUR_KEY –S YOUR_SECRET
  2. ./as-describe-auto-scaling-groups –I YOUR_KEY –S YOUR_SECRET
  3. ./as-update-auto-scaling-group ProdAutoScaleGroupV1 –min-size 0 –max-size 0  –I YOUR_KEY –S YOUR_SECRET
  4. ./as-delete-auto-scaling-group ProdAutoScaleGroupV1 –I YOUR_KEY –S YOUR_SECRET
  5. ./as-delete-launch-config ProdLaunchConfigV1 –I YOUR_KEY –S YOUR_SECRET

Then terminate your instances and do what you need to do.

Throttling bandwidth with OSX

If you’ve ever needed to limit bandwidth on a certain port in OSX you’ll be happy to know that OSX comes with the ipfw firewall of FreeBSD fame.

Here’s how to use it to limit bandwidth on a port:

Create a pipe:

sudo ipfw pipe 1 config bw 50Kbit

Attach the pipe to port 80:

sudo ipfw add 1 pipe 1 src-port 80

To delete it:

sudo ipfw delete 1

 

jQuery Validate – Override default messages

If you need to override the default error messages in the jQuery Validate plugin it’s hard to find the information in the documentation. Depending on which message you want to override the statement will be a variation of
jQuery.validator.messages.TypeToChange = ‘whatever’;

For example, to change the invalid email message use:
jQuery.validator.messages.email = “Invalid Email.”;

Setting up a NATed VirtualBox FTP and Webserver with ProFTPD

A few quick steps to setting up a NATed VirtualBox FTP and Webserver for development. I’m going to assume you’re using some variant of linux.

  1. Install ProFTPD – for debian this would be apt-get install proftpd
  2. Add a user using the useradd command. Ex: useradd username -p password -d /apps -s /bin/false
  3. Edit the following lines in /etc/proftpd/proftpd.conf
    PassivePorts                  65532 65534 #Change the range as necessary, but keep it small
    RequireValidShell               off #If you disabled their shell using the command above make sure this is set to off, this is important for PASV
    MasqueradeAddress               127.0.0.1 #Or whatever address you have set for your guest IP, this is important for PASV
  4. Restart your ProFTPD server /etc/init.d/proftpd restart
  5. In VirtualBox go to Devices->Network Adapters and click on port forwarding and create the following rules:
    Name,Protocol,HostIP,Host Port,Guest IP,Guest Port
    ftp,,21,,21
    ftpdata1,,65532,,65532
    ftpdata2,,65533,,65534
    ftpdata3,,65534,,65534
    web,,80,,80

That’s it! You should be able to connect to the guest webserver and ftp server. Make sure you check PASV for your FTP client.

LaCie 2big Unresponsive/Wont Wake Up – Fix

Just a quick note because I couldn’t find any good answers on other forums. I purchased a LaCie 2big NAS recently and it seemed to have some really killer features such as automatic dynamic dns updates and a built in SFTP server.

I immediately noticed one huge problem though, every night the system went in to some kind of dormancy mode that it would never wake up from and became completely unresponsive. If you are experiencing the same issue, here is how I fixed it:

  • Log in to the web interface
  • Click on Eco Management
  • Uncheck Deep Sleep Enabled
  • Set turn off Hard Drives to Never