Monday, March 19, 2012

Multiple SSID on OpenWRT with bandwidth limit

If you're a network junkie and not been living under the rocks, you must have heard of OpenWRT. It's a Linux distribution for embedded devices (routers) and gives you power to do things usually impossible or difficult with inbuilt router firmware. Wireless Freedom indeed.

This was my scenario: I had to create two wireless APs for my office, one for the guests (no password but bandwidth limited) and another for non-guest users (password protected but no limit on bandwidth). That way the visitors will have free wireless internet, but with limited bandwidth. The office staffs will have to connect to a password protected wifi for unrestricted bandwidth.

The requirements for the APs are,

Free Wifi for visitors
- SSID: FreeWifi
- Password: none
- Bandwidth limit: 256Kbps uplink, 128Kbps downlink

Office Wifi for staffs
- SSID: OfficeAP
- Password: 1234567890
- Encryption: WPA2
- Bandwidth limit: none

Here's how I did it on OpenWRT. Connect to OpenWRT shell.

1. First create two wireless APs with above configuration. Add the following lines to /etc/config/wireless (Remove any existing 'wifi-iface' configurations)

# Free Wifi
config 'wifi-iface'
        option 'device' 'wifi0'
        option 'ssid' 'FreeWifi'
        option 'mode' 'ap'
        option 'network' 'lan'

# Office Wifi
config 'wifi-iface'
        option 'device' 'wifi0'
        option 'ssid' 'OfficeAP'
        option 'mode' 'ap'
        option 'network' 'lan'
        option 'encryption' 'psk2'
        option 'key' '1234567890'

As simple as that! Now to enable the wifi, go to shell and

# wifi down; wifi up

2. Now to limit bandwidth, we'll be using wondershaper. To install:

# opkg update
# opkg install wshaper

3. Now find which interface is the FreeWifi assigned to

# iwconfig

On mine, it was on ath0

4. Modify /etc/config/wshaper and start wondershaper

config 'wshaper' 'settings'
    option 'network' 'ath0'
    option 'downlink' '256'
    option 'uplink' '128'

Now, start wondershaper.

# /etc/init.d/wshaper start

5. By default, wshaper isnt enabled at startup. so,

# ln -s /etc/init.d/wshaper /etc/rc.d/S99wshaper

Monday, December 26, 2011

LinuxMint Debian and adjustments

I recently moved to Linux Mint Debian after using Ubuntu for since quite a while. (Reason: Like many, I'm not so much fond of Unity)

However, Debian is not as polished as Ubuntu. Here are some of the fixes I made:

Installing 686-pae kernel

LM Debian comes with 486 kernel, which has support for single CPU only. The first thing to do is install 686-pae kernel

# apt-get install linux-image-686-pae

Reboot and choose the new kernel.

Installing Virtualbox

Virtualbox is available in the repository.

# apt-get install virtualbox

However, virtualbox wont work because of the newly installed 686-pae kernel, so we need to rebuild the vboxdrv modules. This requires linux headers for 686-pae kernel.

# apt-get install linux-headers-686-pae

This should rebuild the vboxdrv modules automatically, post installation. But if it doesnt, do the following:

# dpkg-reconfigure virtualbox-dkms

Installing Wine

Unfortunately, Wine is not available in the repo. Use the repo at

Add the following line to /etc/apt/sources.list, or via Synaptic - Settings - Repositories - Other Software - Add

deb squeeze main

Then update and install.

# apt-get update
# apt-get install wine

Fixing Mint-X themes

There are two Mint themes, Mint-X and Mint-X-Metal, which are very soothing and greenish. However there's a little glitch with expander plus (+) signs (eg, visible while installing software using Synaptic). To fix, open /usr/share/themes/Mint-X/gtk-2.0/gtkrc file (as root) and remove the following line:

GtkExpander::expander_spacing = 16

Do the same for /usr/share/themes/Mint-X-Metal/gtk-2.0/gtkrc too.

Also, if you want to change the font size for panels, look for font_name variable in this gtkrc file.

Few other changes

You might also wanna install ttf-devanagari-fonts and ttf-mscorefonts-installer. Also download the latest Firefox (currently 9.0) and install it to /opt/firefox/

# tar -jxf firefox-9.0.tar.bz2 -C /opt/

Thursday, October 13, 2011

RIP Dennis Ritchie (1941-2011)

My life revolves around tools and technology, the foundation of which you laid. I've loved and enjoyed The C Programming Language more than any computer text so far. May you rest in peace..

#include <stdio.h>

  printf("RIP, Dennis Ritchie!");

Monday, October 10, 2011

Gosaikunda Trek

Travelogue after a long time. Not that I haven't been traveling, but have been too lazy to write. However recently I went to Langtang trail upto Gosaikunda, the memoir of which is worth mentioning. The scenery along the trail is just superb and the Gosaikunda and other lakes around are just magnificent!

We (Rajendra, Subash and me) started from Sundarijal and ended up at Dhunche via Gosaikunda. Took 5 days (29th Sept - 3rd Oct, 2011) and trekked up to a height of 4730m.

Day 1
We started from Sundarijal. Actually the plan was to go to Dunche / Syabrubesi first and start from there, but since the bus tickets were hard to get due to Dashain we decided to start from the opposite end.

The Sundarijal - Chisapani was quite familiar trail. We started around noon and reached there by evening. Apart from few downhills, the trail is all the way up.

Elevation: 2194m

Day 2
Headed towards Chipling Danda. But first we went all the way downhill to Chipling Phedi then a *tough* climb to Chipling Danda. Stayed there for a while for lunch and for much needed rest.

Then towards Kutumsang, the next stop. Not as tough climb as before but still it was all the way uphill. Finally reached Kutumsang. Had some noodles there.

It was already getting late so we were in a dilemma whether to head towards Magengoth or not. But we still thought to give it a shot.

However we got caught on the way due to magnificent scenery of sunset along the way. By the time we were done taking snaps, it was already dark. Plus met a women who was the owner of a hotel at the next stop. Even she advised us to return back to Kutumsang.

Night at Kutumsang. Elevation: 3630m

Day 3:
Chilly morning, but the cute little daughter of the owner of the hotel made it interesting. She was perky, talkative and fun.

After breakfast we headed towards Magengoth. And it was tough climb. Took 3 hours to reach there. Rested for a while and we had Dhido there, which I regretted as the curry was too chilly and burned my stomach later.

Headed off to Tharepati then. Little elevated road but not that tough. Took 2 and half hour to reach there. The view of the mountains was supposed to be amazing from there, but unfortunately it was raining when we reached there. Stopped by a hotel there and had some tea.

Then off to Ghopte. The trail was all the way downhill and rocky. It was so steep we wondered how the trekkers taking the opposite route would climb that. On the way you come across a spring and a giant boulder you cannot miss.

Finally Ghopte. Had no energy to move beyond. Elevation: 3430m

Day 4:

Chilly and shivering night. We moved early in the morning. What was ahead was perhaps the toughest road we've encountered so far.

Ghopte to Laurebina Phedi was a series of tough ups and downs. The hotels at phedi are visible from quite a distance, but it took us almost 3 hours to reach there. Even the pass at the top starts being visible, but is yet too far.

Finally reached Laurebina Phedi (elevation: 3700m). Had some lunch and prepped for the final climb. We were climbing upto 4700m next so had the garlics and chocolates ready. It was supposed to take us 3-4 hours to climb. And if we're not careful enough, we might even catch altitude sickness!

Toughest climb so far! The landscape started changing rapidly, from greenish to barren rocks. Even noticed Danphe (Lophophorus) along the way. And since the air was getting thinner, it was a slow and steady climb. Sounds of own footsteps, long breaths and wilderness. Thankfully the air was misty. Also met couple of tourists returning from the pass. Stopped by a hotel along the way for some tea! Cant believe there was a hotel in that altitude (4100m). The owner was extremely nice and the tea was cheap.

Started walking again. We all started getting headache due to cold and altitude. Finally reached the top. Frozen snow of the mountain!! And all of a sudden, the sky cleared up and it was sunny. Played with snow and took lots of photographs. Then crossed the pass (~4700m)!

Then another wonder happened. As soon as we crossed the pass, it got cloudy again and it started snowing!! Amidst the snowfall, we walked along Surya Kunda (lake), Ganesh Kunda and several others. Finally reached Gosaikunda. It goes without saying, the lake and surrounding is beautiful.

Stayed for the night there. Elevation: 4300m

Day 5:
Took a lot of snaps around Gosaikunda early in the morning. Some breakfast and then headed towards Dhunche, all the way downhill.

Took us a whole day to reach Dhunche via Laurebinayak and Sing Gompa. Having walked uphill for 4 days, the downhill walk was knee-aching. Reached Dhunche in the evening. Elevation: 1950m!

We were supposed to stay there for the night and return Kathmandu the other day, but due to festive season the buses were hard to get. Fortunately we got a jeep returning back to Kathmandu and we jumped in. Returning Kathmandu the same day (although hurriedly) seemed wiser to us than staying there for the night and getting lost the next day)

Reached Kathmandu by 10pm. Elevation: 1400m :)

Other Useful Links:
1. Few photos on Flickr:
2. Map: (although I suggest you buy a paper map with contours and all, if you're planning to trek)
3. Detail Guide:

Sunday, September 11, 2011

Reprojection to EPSG:900913 using MapServer

If you are embedding a map on some web page (read: OpenLayers) and need to add layers from some third party GIS server, you're most likely to come across the word "Mercator" and its myriads of standards. Web based mapping services use Spherical Mercator, however commercial GIS services (like, Esri) might use some other standards like EPSG:4326. This incompatibility leads to a lot of trouble as OpenLayers only accepts Spherical Mercator.

From OpenLayers Docs:
Spherical Mercator is a de facto term used inside the OpenLayers community – and also the other existing Open Source GIS community – to describe the projection used by Google Maps, Microsoft Virtual Earth, Yahoo Maps, and other commercial API providers.

This term is used to refer to the fact that these providers use a Mercator projection which treats the earth as a sphere, rather than a projection which treats the earth as an ellipsoid. This affects calculations done based on treating the map as a flat plane, and is therefore important to be aware of when working with these map providers.

In order to properly overlay data on top of the maps provided by the commerical API providers, it is neccesary to use this projection. This applies primarily to displaying raster tiles over the commercial API layers – such as TMS, WMS, or other similar tiles.

In order to work well with the existing commercial APIs, many users who create data designed for use within Google Maps will also use this projection. One prime example is OpenStreetMap, whose raster map tiles are all projected into the ‘spherical mercator’ projection.

Projections in GIS are commonly referred to by their “EPSG” codes, identifiers managed by the European Petroleum Survey Group. One common identifier is “EPSG:4326”, which describes maps where latitude and longitude are treated as X/Y values. Spherical Mercator has an official designation of EPSG:3857. However, before this was established, a large amount of software used the identifier EPSG:900913. This is an unofficial code, but is still the commonly used code in OpenLayers. Any time you see the string “EPSG:4326”, you can assume it describes latitude/longitude coordinates. Any time you see the string “EPSG:900913”, it will be describing coordinates in meters in x/y.

If you are to overlay third party GIS layer, which is not in spherical mercator, you'll have to reproject the layer.
One of the reasons that the Spherical Mercator projection is so important is that it is the only projection which will allow for overlaying image data on top of commercial layers like Google Maps correctly. When using raster images, in the browser, it is not possible to reproject the images in the same way it might be in a ‘thick’ GIS client. Instead, all images must be in the same projection.

There are several tools for reprojection, but the popular (and free) one is MapServer. The process is explained here. The process works like this:

However this doesn't work. It turned out, MapServer doesn't reproject to 900913 properly (even after adding the 900913 reprojection line to /usr/share/proj/epsg). Maybe a bug.

So here's the hack: MapServer does reproject to EPSG:3857. But EPSG:3857 and EPSG:900913 are same thing. So we need to write an intermediate proxy which takes WMS request for 900913, replaces the 900913 to 3857 in the WMS request URL and redirects the request to MapServer.

Here's the PHP script (reproject.php) to act as proxy:

header("Location: http://{mapserver_address}/cgi-bin/mapserv?" . str_ireplace("epsg%3A900913","epsg%3A3857",$_SERVER['QUERY_STRING']));

1. Install MapServer. In Ubuntu,

sudo apt-get install apache2 php5 cgi-mapserver mapserver-bin

for verification, check http://localhost/cgi-bin/mapserv

2. Put the reproject.php file to web root (/var/www)

3. Write a configuration file (say, and place it in the same folder as mapserv (usually at /usr/lib/cgi-bin/)


NAME "reprojected_wms"

IMAGEPATH "/var/www/docs_maps/"
IMAGEURL "http://{mapserver_address}/docs_maps/"

"wms_title" "Reprojected WMS
"wms_onlineresource" "http://{mapserver_address}/reproject.php?"
"wms_srs" "EPSG:3857"
"wms_server_version" "1.1.1"

EXTENT 8865484.246776307 3016430.900654626 9864020.0791919 3587377.91450212

NAME "My Layer
CONNECTION "http://{GIS_Server}/WMSServer?"
"wms_title" "GIS Layer"
"wms_srs" "EPSG:3857"
"wms_name" "1"
"wms_server_version" "1.1.1"
"wms_format" "image/png"
"wms_cache_to_disk" "1"

CONFIG "PROJ_LIB" "/usr/share/proj"


Now use the WMS URL http://{mapserver_address}/reproject.php? wherever needed.

Many thanks to Prabhas for devising the steps and helping me with this blog.