SSH-ing into the Raspberry Pi over the internet.

Sure, it’s easy to SSH into your Raspberry pi when you’re on the same network as the pi itself. You just do an nmap scan to map out the active IP addresses in your network, and you try them out one by one and eventually you’ll gain access. Once you gain access, you can set up your Pi to have a static IP so that you don’t have to bust your ass with nmap every time, and voila, you’re done. (To avoid nmap, one could also go to your router’s page and check all clients under the DHCP service. But this is only possible if you have access to the router.)

But what’s the fun in that?

Once you leave your network, you can’t access your Pi at all. So unless you’re a fat neckbeard spending your whole time in your mom’s basement, the above isn’t very exciting.

In order to get SSH access to my Pi from anywhere in the world, from what I could gather, these were the steps.

  1. Set up a static IP address for your Pi.
  2. Go to your router and forward a port. This is like punching a tiny hole in your firewall to allow any incoming connections from the internet (on the port you forwarded) to go through to the IP address in your home network.
  3. FInd out your network’s public IP
  4. SSH into your Pi!

The second step was the most irritating of all. I went to my routers page, and forwarded port 22 to my raspberry pi, and set up a static IP, and did everything else. But it just wouldn’t connect! I had no idea what to do.

I then searched for alternatives, and I found this amazing service called Weaved. Weaved is a service which basically cuts down all the irritating stuff you have to do in order to get your own connected Internet of Things. This was exactly what I wanted.

So I went ahead and made a Weaved account, and set up everything as shown here. It was very snappy and quick.

The next day I went to work, and opened up my Weaved page, and clicked on my devices which were online.

untitled1

After clicking on my device, I found this.

Untitled2

I just followed the instructions and there I was, controlling my Raspberry pi from work. Oh man the sweetness.

But life rarely is so easy. The next day I came to work and did the same thing, and I got the dreaded “connection closed by foreign host” error, after being frustrated for a while, I gave up.

The next day I came and it worked! I didn’t know how but it worked. It was as if the universe was playing a cruel joke on me. Anyways, this kept happening. For no apparent reason, I’d get an erraneous ssh_exchange_identification, and for no apparent reason again, everything would go to normal. I searched high and low for an explanation, but I couldn’t get anything partly because Weaved is a new product and not many people are using it yet. So there wasn’t that big a community I could reach out to.

But nonetheless, the people at Weaved were kind enough (or rather, the person running the Weaved twitter handle) to note my excessive wailings on twitter, so they reached out to me, apologized for the inconvenience I was facing, and offered to bump up my account to allow 2 hour connections (previously it was just 30 minutes, which was even more frustrating). I was so touched.

But soon I got very frustrated and searched again for an alternative. Then I found this answer on the raspberry pi stackexchange and found the keyword “ngrok.com”.

This was really the answer to all of my problems.

Ngrok is a tool which creates secure tunnels to your localhost. For ssh, I needed TCP tunnels. To install ngrok on the Pi, I just had to download the Linux/ARM zip file on the pi, and unzip it. That’s it. Now to open a secure TCP tunnel to the localhost on port 22, type in the following.

                ./ngrok tcp 22

Once you have a Tunnel Status = Online, you should see a hostname and port in the “Forwarding” section, which, for an example, looks like

       0.tcp.ngrok.io:510xx

Now this tunnel is forwarded to the localhost. So to ssh into your Raspberry pi over the internet, fire up PuTTY when you’re at work, and enter the hostname and port and the username “pi”, or type in

ssh pi@0.tcp.ngrok.io –p 510xx

and you should be through. This was even more beautiful! It is recommended to use ngrok with a terminal multiplexer such a screen or tmux. I personally used tmux.

A tmux session running a ngrok tcp tunnel to my localhost on prt 22.
A tmux session running a ngrok tcp tunnel to my localhost on p0rt 22.

That was that! For now I’m able to SSH into it pretty cleanly. I just hope this doesn’t die on me.

Lutyens’ Delhi.

A while back, I came across a blog post (of whose content I now have no recollection of), which just focused on praise of one particular thing. It was such a joy reading it, how the words flowed so smoothly out in praise…

That blog post made such a big impression on me that I decided to write something like it myself. I researched on what these types of rhetoric were called, and came across the encomium, which was supposedly the eight exercise in Progymnasmata, a series of rhetorical exercises for the students in Ancient Greece. But the problem was, what was I to write about?

There wasn’t anything which moved me to such an extent that I could write and write about it. Even if I did find something, would I have the skill to just go on and on about it without exhausting everything I could say about it? Like almost everything in my life, I just let this be, and moved on.

Today, however, we (a couple of brothers and I) went on an impromptu tour of Lutyens’ Delhi, and boy, did that shake me up. I wasn’t really a stranger to being shaken up as such, for instance, there was this time where I stood at the very edge of Mumbai, and gazed at it’s skyline, to spot, to my utter shock, Mukesh Ambani’s house. I couldn’t believe it. How rich must one be to have one’s house as a part of the Mumbai skyline? Somehow this filled me with a feeling of contempt, this tingling feeling of unpleasantness at the pit of my stomach.

But today I felt something similar, but it left me with such a drugging combination of emotions that I couldn’t help not recording it.

Looking up at the majesty of Rashtrapati Bhavan and Sansad Bhavan first sent a wave of patriotic pride across, and it made me feel small, almost puny. I felt as though I had reached the very heart of India itself.  All those times when I gazed at these things in movie screens or in pictures, and finally here it in real life, and I had NO idea it was like how it was. Then I looked at perfect it was, the architecture, and the symmetry. Rashtrapati bhavan on one end, and India Gate at the other, and Rajpath connecting them, so beautifully standing in tribute to the genius of Edwin Lutyens.

How to get “useless gaps” between windows in Awesome window manager.

Maybe the title is best explained in pictures. This blog post will show you how to get the gaps between windows as shown below. These are called “useless gaps”.

2015-06-14-120032_1366x768_scrot

2015-06-14-120309_1366x768_scrot

To do this we’ll need a module for awesome called Lain. It provides a set of new layouts and widgets, and among the layouts are the “useless” layouts, that is, layouts which provide windows with useless gaps. I also recommend Lain for it’s widgets for weather and file system size. Really really cool. Anyways, follow these steps to get the useless gap layouts.

  • Click here for instructions on how to install and use Lain. If you use Arch, then you can find Lain in the AUR. For other distros, you’ll need to clone the git repo.
  • Once cloning is done, you can find instructions on how to use the use the useless gap layouts here.

After updating to awesome 3.5.6, I would get a compile error which would say “attempt to perform n%0”, everytime I used to use uselessgap layours. Then the windows would refuse to tile, and would instead spawn one on top of another. One fix was to not use useless gap layouts, but then useless gaps are so pretty! So I looked for another fix, and found one too. To fix this, I followed this code change.

Raspberry Pi

The Raspberry pi is a tiny credit card sized computer which can run a whole variety of Linux distributions on it. The latest model, the Raspberry Pi 2 comes with a quad core ARM CPU and 1 GB of RAM, and is extremely low on power consumption. Very very impressive.

The Pi also has a series of pins called the GPIO pins which can interact with real life electronics. This is one reason for the craze around it. This feature makes it applicabile in a myriad of different real life projects.

I bought my Raspberry Pi in March, and have had installed the standard Raspbian (a flavour of Debian GNU/Linux) on it. As I was very busy for the next few months, I really didn’t do much with it. It was quite recently that I set it up again and have been tinkering with it.

Here are a few things I’ve done with it. The list shall hopefully increase in size and I’ll keep adding more stuff to it as I tinker more.

  1. Installed Raspbian, and accessed the Pi over my local network from my laptop via SSH. The first time I bought the Pi, I thought one needed a keyboard to work with it, but it was only after I installed it that I realized that Raspbian sets up an SSH server on the pi upon the first boot. The default username is “pi” and the password is “raspberry“. So this eliminates the need for a keyboard and mouse completely, (although having them would make things easier)
  2. Accessed the Pi from work. This was one thing I struggled to do many times. Essentially I found that there were two ways to do this. The difficult way was to first assign a static IP address to the Pi, set up an SSH server on the Pi, install a dynamic DNS client (I used No IP), and finally go to your router and set up port forwarding so that the router will pass any incoming SSH request on the specified port to the Pi. I did all of these things, yet I couldn’t access it from work. The easy way was to use an application called Weaved, which made things very very simple. But the downside was that Weaved only allows for 30 minute connections, which is bumped up to 2 hours if you use the Weaved iOS app. I personally liked Weaved, but then I still was facing the annoying “Connection closed by host” problem when I was trying to use it.
  3. Woke up and annoyed my sleeping brother at home from office. This was super fun. I used Weaved to SSH into my Pi, downloaded and installed mps-youtube, and played some mean techinical death metal. This played over a speaker which I attached to the Pi and hid from sight.
  4. I also used espeak to creep the same brother out.

I’ve got a lot of other stuff planned. I’ll keep updating stuff as I do them.

Oneko, the cat that chases the cursor.

Today while browsing another desktop thread on /g/, I saw a user who had a cat roam around his cursor. After googling a bit I found out that this was the name of a package called Neko.

The wikipedia link describes it best.

…[Once run] the pointer could be modified to various cat toys such as a mouse, fish, or bird. When Neko caught up with the pointer, it would stare at the screen for a few seconds, scratch an itch on its body, yawn, and fall asleep until the pointer was disturbed. In windowed mode, Neko would stop at window boundaries and scratch at the edge of the window.

I downloaded the package and now Neko is happily sleeping at the corner of my screen. Note that oneko isnt in the official repositories, and I downloaded it from the Arch User Repository.

$ yaourt -S oneko

2015-06-13-100709_1366x768_scrot

Very very cute!

My experiences with Arch – Introduction

This is the first of a few blog posts which I’m going to use to document all that I tweak on my laptop and raspberry pi.

I have a Dell Inspiron 15 which has an intel core i5 processor with a 5GB RAM. It’s about 5 years old, and hence obsolete. About a year back, after consistent Windows use (and abuse), my laptop crashed and I took that oppurtunity to test linux. First I ran Ubuntu 13.10 Saucy Salamander, and I wasn’t that impressed with it either. After that I moved to Arch Linux, and haven’t looked back since.

On my Arch system I run a tiling window manager called Awesome Window Manager, and have been following various ricing guides online. Here is what my desktop looks like now. 2015-06-13-100548_1366x768_scrot2015-06-13-100709_1366x768_scrot

Here are a few resources online which I used to set this up.

  1. The /g/ wiki of 4chan.
  2. This YouTube user‘s videos.
  3. Quite obviously, the god-like Arch Wiki and also the wiki for awesome window manager.

I’ve mostly tried to stick to the ricing configuration which has been mentioned in the /g/-wiki under the section “What does /g/ use?”

I’ve tweaked with it so much that I have forgetten how I’ve gotten to where I am now. So I’ve decided to document whatever I do from now so that I can keep a track of it.