Setting up raspberry pi

Here’s a list of things I do to set up my raspberry pi and a small note, the purpose of this list is to help me remember what all I need to setup if and when I start from scratch the next time around.

1. Finding your pi’s IP on the local network!

I don’t have a dedicated monitor and run my pi headless. I used to do this by running a for loop and finding the ips of all my devices on the local network and then sshing into them until I found my pi but this is easier and um.., more scientific!

2. Setup Vim and fish on pi.

I don’t like editing files with nano and so setting up Vim is essential and fish is an awesome replacement to bash/zsh you may want to give it a spin. It’s history management is way better than ohmyzsh.

3. Setup Avahi or Zeroconf

It’s always easier to remember hostnames than it is to remember ips and this is where Avahi shines. Now I can access my pi with pi.local even if it’s local ip changes.

4. Remove Xorg and the desktop packages

I like to run my pi, lean and mean there is no need for the desktop when I run it headless, this saves both the disk space and data with updates

5. Setup a bittorrent web client

The folks at howtogeek have an excellent tutorial on setting up deluge, there are a couple of other alternatives as well but deluge works for me quite well.

6. Give your pi a public ip/domain

What good is your pi if you can only access it over the local internet. The whole point of setting up a bittorrent web ui was to be able to download stuff remotely and watch it after you get home. You can also point your subdomain to your pi as I did in my last post.

7. Set up your external hard drive and samba to share it over the network.

To watch the TV shows or movies that you downloaded on your pc/mac you need to set up samba and also to connect your external hard drive to pi. Connecting the external hard drive is the same as connecting to any other linux box and so I’m omitting the steps here.

I’ll probably add more stuff here in time but this is my barebones pi setup.

Raspberry Pi tip : Map your Subdomain to Pi

After I had my Raspberry Pi setup, I wanted to create a subdomain which would point to it.
This is trivial to set up if you have a static IP but I’m assuming that like me you don’t have that.

The way that I have set this up is by following this excellent post on superuser. First you need to set up a dynamic dns for your pi. I use DNSDynamic for this, a tutorial on how to set this up for your pi can be found here. With dynamic dns set up, it’s like having a static ip.

All you need to do after this is to create a CNAME record which points to your dynamic dns. This can be created using your domain registrar’s web interface. A CNAME is basically a pointer and can point to any IP or domain. In my case I set up pi.nikhilbhardwaj.in to point to my dynamic dns. If you’ve set that up correctly you can use dig to verify this. Here’s what I get, babypi.ssh22.net is my dynamic dns. I’d advice you to choose a better name!

After this it’s a matter of forwarding the right ports on your home router and viola you have a subdomain that points to your pi!

dig pi.nikhilbhardwaj.in

; <<>> DiG 9.8.3-P1 <<>> pi.nikhilbhardwaj.in
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57260
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 2, ADDITIONAL: 4

;; QUESTION SECTION:
;pi.nikhilbhardwaj.in.      IN  A

;; ANSWER SECTION:
pi.nikhilbhardwaj.in.   13171   IN  CNAME   babypi.ssh22.net.
babypi.ssh22.net.   60  IN  A   106.51.135.186

Another partition looms

By the indications that we are getting from the media the state of Andhra Pradesh will be bifurcated, partitioned into two and this saddens me immensely. The parallel with India’s partition at the time of independence is all to evident a state is being carved up in two by the power hungry who will do all that is necessary to remain in power.

India’s partition was engineered by foreign forces as is Andhra Pradeshs’ the former british and the latter italian. It is very easy for a foreigner to divide another persons homeland for they can never understand what it means to those who call that place home, but it isn’t the foreigners who are responsible for both these self inflicted wounds it is us indians who are responsible in both occasions. In 1947 it was Nehru and Jinnah both of whom were power hungry and this time with history repeating itself only the actors are different.

Any partition is a painful ordeal for both parties, be it siblings dividing ancestral property or best friends not being friends anymore. It is never a solution and even after decades the scars of the grave wounds remain, reminders of the futility and foolishness of division.

I’m not from Andhra Pradesh so I can’t claim to be an expert on Telangana but I’ve stayed in Hyderabad and Secunderabad for some time, I have a few friends from the state none of them are radicals so it is possible that my analysis is wrong all together. But I can’t see a single reason for dividing the state except for those motivated by political considerations, the people of the state are mainly from the same linguistic community with no regional community dominating other communities.

The solution to the problem that people are protesting about does not lie in dividing the state into pieces but does so in better governance and empowerment of the people. I wonder how much longer will politics of appeasement drive the future of our country. It hardly matters now though, tonight is probably the last when Andhra Pradesh will be one state come tomorrow another partiton looms large.

Meteor.js

It’s been a while since I last blogged, sort of lost the interest didn’t know what to write about but you don’t really care about that do you! Lets get to the point and I’ll tell you what has me so excited about Meteor.

New programming languages and frameworks keep coming along faster than the speed of light in the world of technology but most of them just whiz by and hardly interest me. There are however a few which stand out amongst the crowd and Meteor is one of them. I’ve had a bittersweet relationship with JavaScript, back in the day when I had only gotten started with programming with C++ in school I found it like a breath of fresh air. It could add that fancy rollover effect to pages or a bouncing ball on a webpage, I was amazed by it. But the cross browser issues, quirky behavior and it being a nightmare to debug I gave up on JavaScript.

For a few years it stayed that way, I taught myself some php got bored by it and moved to ruby tried dipping my feet in rails but without much luck as it was too magical. I boarded the Sinatra bandwagon, it is an awesome framework. No magic, no nonsense simply rest but then again Sinatra itself isn’t enough to make nice websites you need something for the front end too and that’s when I started to dive into jQuery rediscovering my love for JavaScript. I read a couple of books on jQuery embraced the asynchronous and restful nature of the web and it was such a joy to make web applications again.

After that for the last couple of years things have been slowed down, sure there have been performance enhancements in jQuery and node.js came along too. I had a brief look at node.js but really didn’t see how much more of a value add it was over Sinatra. Similarly Knockout.js didn’t really knock me out neither did backbone have that much of a backbone for me. Meanwhile at work I used GWT which in my opinion isn’t the best way to write a web application today(It may have been 5 years ago, not anymore). Had I discovered the ultimate framework? Had I achieved nirvana? I sure thought so.

That was untill a week ago when I was struck by meteor.js, I had watched the introductory video and my head was abuzz with such excitement after a long time indeed. I watched the second video and boy was I jumping up and down. Meteor isn’t just an evolutionary framework it’s revolutionary! It doesn’t split the client and server parts of your web app but presents them together. It’s how you would develop any application, sure you need to know about the security aspects but when you’re developing something it should be fun, you shouldn’t be spending time on downloading jQuery and your favorite bootstrap framework and other trivial details. Ideally you should be able to focus on the core of your application and all the secondary things should be dead easy to implement. I also like the social focus of meteor, it couldn’t be easier to integrate your app with Facebook/twitter or for that matter any other social networking site.

What trumps all those minor features and enhancements is it’s publish subscribe feature, if you asked me what was the one single feature that defines meteor. You don’t need to implement polling to write a fluid always up to date interface, this isn’t the 1980s. Meteor just works where most other frameworks make you do too much unnecessary work! Also the package management is pretty sleek, it compares and in some cases surpasses the ruby gems which I consider the ideal package manager.

Having heaped so much praise on meteor I still have a few doubts, the most important is about how well will meteor scale? This is one factor that will probably decide meteors future in the years to come. Will it end up as a toy for prototyping stuff or will it dislodge rails from its pedestal remains to be seen. From a technical perspective it’ll be curious to see what strategy they eventually take to scale and perform under high load. Another thing that is probably on meteor’s roadmap is to support the various other nosql stores other than mongo db. It’ll be interesting to see how they implement this, right now the syntax is quite specific to mongo it’d be better if it was neutral so that there could be support for stores like dynamo db with no change in the existing application code. One last thing that would be absolutely awesome is integration with Native Mobile Apps, even though web apps work well on mobile devices native apps are miles ahead. It remains to be seen how easily can one write the app in meteor and then hook up the presentation onto the native platforms. Boy would that be sweet!

All in all this makes meteor a very interesting framework to watch out for even if you don’t write too much JavaScript, it has so much potential where it will be in two or three years time is an open question. Regardless of how it ends, the ride along the way promises to be a lot of fun. I don’t know about you but I’m boarding it right now!

Downgrade grub2 to grub

There was this weird issue that I’ve been facing for some time with both ubuntu 12.10 and 12.04, what happens is that my Acer Aspire One 722 netbook doesn’t boot into linux at times. The first couple of times I dismissed it as a one off but that didn’t stop the problem from recurring. Then I blamed my exotic grub2 setup wherein I had installed grub2 to /dev/sda5 and then was using the windows 7 bootloader to chainload it.
Continue reading

Keep Windows and Linux time in sync

Every time I log into windows after having used linux on my netbook there is a problem with the system time. It is because linux treats the time set in your BIOS clock to use the UTC clock, this is a problem as windows treats it to be set to your local time. If you’re using only one OS then both of these choices are acceptable design choices but when you use it becomes a problem. When I’m online it’s not a problem as both windows and linux sync their times with the internet but when offline it’s irritating to look at the clock and see a time that makes no sense.

Fortunately you can tell linux to follows the convention that windows follows, telling windows to behave like linux on the other hand is significantly harder. The best thing about linux is that it makes it’s assumptions and lets you change them to suit your preference. We need to edit this file /etc/default/rcS for ubuntu 12.10


# assume that the BIOS clock is set to UTC time (recommended)
UTC=no

By default the option is yes but we need to change it to no and from the next reboot the problem is solved!

Reliance Netconnect+ Settings for Ubuntu

I had written a post on how we can easily get MTS Mblaze to work under linux and as it turns out, the Reliance Netconnect+ is equally easy to set up and use. Instead of repeating the entire procedure which I have already mentioned here, I’ll just post the relevant wvdial configuration file. You need to add the following snippet to your /etc/wvdial.conf

[Dialer netconnect] 
New PPPD = yes 
Init1 = ATZ 
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 
Modem Type = USB Modem
Baud = 460800 
New PPPD = yes 
Modem = /dev/ttyUSB0 
ISDN = 0 
Username = 9388****** 
Password = 9388****** 
Phone = #777 
Stupid Mode = 1 

It goes without saying that you need to replace the username and password with your netconnect phone no. To connect simply type this in a terminal

sudo wvdial netconnect

Here’s what I get

 ➜  ~  sudo wvdial netconnect 
--> WvDial: Internet dialer version 1.61 
--> Initializing modem. --> Sending: ATZ OK 
--> Sending: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 OK 
--> Modem initialized. 
--> Sending: ATDT#777 
--> Waiting for carrier. ATDT#777 CONNECT 3100000 
--> Carrier detected.  Starting PPP immediately. 
--> Starting pppd at Mon Dec  3 15:45:39 2012 
--> Pid of pppd: 3981 
--> Using interface ppp0 
--> local  IP address 115.242.128.198 
--> remote IP address 220.224.141.145 
--> primary   DNS address 220.226.6.104 
--> secondary DNS address 220.226.100.40
 

Happy browsing with Reliance Netconnect+, I suspect that the MTS device and the Reliance device are actually identical, the only difference being the firmware. As usual let me know in the comments if this helped or if you have some clarifications.

gprs and wvdial over bluetooth

I must say that the network manager handles ppp connections rather poorly, sometimes they work but most of the times they don’t. The situation is worse still with mobile phones, I have a nokia series 40 mobile phone and when my mts subscription expires, I need to use it for a couple of days. I’ll walk you through the steps that allowed me to connect to the internet using my tata docomo gprs connection over bluetooth.

Continue reading

The online journal of Nikhil Bhardwaj