Protected:

This content is password protected. To view it please enter your password below:

Advertisements

Setting up a DHT22 Temperature and Humidity sensor with the Raspberry Pi.

During the internship, bored out of mind, I was looking at a few cool Raspberry Pi related instructables on Instructables, and I found one particularly awesome one. The guy who made it hooked up a DHT11 sensor with a photoresistor and set that up in his basement, and then he made it upload the data read by the sensors to a website called ThingSpeak, which anyone can access and read. This seemed like it was pretty fun.

For one thing, Kolkata is a really humid place, so naturally I was excited about testing it out and see what kind of data I could take out of it.

And maybe after collecting enough data, I could use my sick data analysis skillz and maybe set up a regression model to predict the next day’s temperature and humidity?

With these thoughts in mind, I went ahead and

  1. Bought a DHT 22 sensor.
  2. (Almost) bought a BMP180 pressure sensor.
  3. Followed this instructable, and set everything up nice and sweet.

Here’s a pic.

IMG-20150811-WA0000

And here is the data I managed to collect.

It was pretty good fun doing it. Thingspeak allows you to download the data in CSV format and then from there you can do all sorts of magic with it using SAS or something else. Infact, you can directly work on  your data using MATLAB in ThingSpeak itself. So that’s pretty awesome.

The Raspberry Pi foundation recently came up with a new tiny little add-on board for the Raspberry Pi, which they call the Raspberry Pi SENSE hat.

This add-on board has a temperature humidity sensor, a pressure sensor, an orientation sensor, a tiny joystick and an 8×8 LED matrix grid, all put into one. Buying this one thing can get rid of the need for buying everything else at once. I can’t wait to get my hands on one.

Getting started with electronics with the Raspberry Pi : LED Hello World.

This one was long overdue, and I finally got around to doing it, and even though it’s just a damn LED light, making it glow was an extremely pleasant experience.

I just followed this video and also this video on YouTube. I highly recommend following that channel, because almost all of his videos have to do with the Raspberry Pi and electronics.

Following these two videos, I learnt the following.

Here’s a picture.

An LED light glowing. Note that here I used a 5v pin and not the GPIO pin. This 5v pin is connected to the main powerline of the Raspberry Pi.
An LED light glowing. Note that here I used a 5v pin and not the GPIO pin. This 5v pin is connected to the main powerline of the Raspberry Pi.

I also modified the code in the video above to make a birthday gift for a friend.  I hooked up an LED light to a GPIO pin, and wrote a while loop in python to make the light blink as long as the happy birthday song was playing. Here is the code.

import RPi.GPIO as GPIO
import time
import pygame
import sys

GPIO.setmode(GPIO.BOARD)
GPIO.setup(12,GPIO.OUT)

pygame.mixer.init()
pygame.mixer.music.load("song.mp3")
pygame.mixer.music.play()

while pygame.mixer.music.get_busy() == True:
 GPIO.output(12,GPIO.HIGH)
 time.sleep(1)
 GPIO.output(12,GPIO.LOW)
 time.sleep(1)
while pygame.mixer.music.get_busy() == False:
 GPIO.cleanup()
 sys.exit()

OSMC-Kodi on the Raspberry Pi

Once after launching a deauthentication attack on my unwary brother who was watching a movie on YouTube, I was overcome by a sudden feeling of guilt, because he came to me immediately afterwards and asked me if I could fix his laptop because his internet wasn’t working. Then I realized that I shouldn’t be such an asshole and so I decided to make it up to him in whatever way I can (without telling him I was responsible for his laptop not connecting, that is).

Now a while ago, I came across OSMC, which is a Debain-based Linux distro which brings Kodi (formerly called XBMC) to a variety of devices, one of them being the Raspberry pi. Now my brother is a nut, one who prefers watching Sunny Deol bash up people to breathing, and since I had to make it up to him somehow, and since I conveniently had a Raspberry pi lying around, and also since OSMC is just so damn beautiful, I decided to install it and show it to him and let him stream some more Sunny Deol.

It turned out that installing OSMC is a breeze. You just need to download the installer for your system, plug in a formatted and wiped SD card, and click on the install and sit back and relax and let it work it’s magic.

After your SD card has the OSMC bootable image on it, simply plug it back in to the Raspberry pi, attach a HDMI cable to it and the TV, and plug in the power cable. If everything’s right, you should get a beautiful splash screen with the OSMC logo on it, and that’s it! If you have a keyboard, then plug that in to the Raspberry pi and you’ll be able to control it with the keyboard. Otherwise, you can simply download the amazing Yatse app for Android, and you’ll be able to control it from your phone. iOS remotes are also available.

Here’s how the Yatse app looks like.

Now by default, OSMC doesn’t ship with the (highly illegal and definitely not recommended (*wink*) ) movie and TV show streaming add-ons, but with a little help, you should be on your way to piracy. I dabbled in piracy of the above kind and it was a thoroughly enjoyable experience.

If you don’t have a TV or a HDMI monitor lying around (i.e., if you’re a stank cheap ass) I think you can set up a http server on the Pi and access it from anywhere within your local network. (Or, using ngrok, from anywhere in the world!)

I haven’t tried this yet, and I will update this blog when I have.

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.