Build your own in house weather station

We all use a smartphone and most of the smart phones generally have a weather app. Which shows the weather for your city. But do you wonder what would be the weather like inside your house or inside your room? The “in house weather station” monitors the weather inside your house. With its help, you can get a report of what the weather is outside and compare it with the weather inside. Here we are monitoring only two parameters – temerature and humidity. After all the hard work, you would get an output similar to this

Tools :

  • Raspberry pi 2 with raspbian installed
  • DHT22 sensor
  • 10k resistor
  • Male to female jumper wires
  • Breadboard
  • Wires for making breadboard connections

I would not go in depth on how to setup the DHT22 sensor. Here are the instructions that I followed.

I was stuck with the resistor piece as I did not have a 10K resistor. So I added two 6k resistors in series, taking the total resistance to 12k (6k+6k).

Here is how my setup looks

W.r.t the software, I tried using the Adafruit code, but it felt more comfortable using the pigpio code after running the pigpiod daemon. I am still getting some errors when i call the s.cancel() and pi.stop() functions. But the rest of the code works.

To get the external temperature and humidity, I signed up with openweather and got their api. There is a python library pyowm which provides an implementation for openweather. So, I got the humidity and temperature of my city from openweather. And i pushed the data – external humidity & temperature and internal humidity & temperature into elasticsearch which I was running on my raspberry pi.

Looking at the limited resources available on the pi, both in terms of disk and memory, I did some tweaking in elasticsearch, so that It did not hog down my raspberry pi.

I restricted the heap size of elasticsearch to 256MB by adding the following options in the ./bin/elasticsearch script.


Since, I had to access my elasicsearch via the raspberry pi’s ip address, i changed the host to bind to the ip address instead of localhost. Also, looking at the disk constraints, I limited the number of shards & replicas to 1. Here are the configuration lines in ./config/elasticsearch.yml
index.number_of_shards: 1
index.number_of_replicas: 1

Here is the script which pulls data from openweather and gets data from my DHT22 sensor and pushes it into elasticsearch.

The interesting thing to note in the graph is that though there is change in the external temperature and humidity, the internal temperature and humidity does not change much.

Use your smartphone as a GUI display for your pi

With a very simple hack, we can use our smartphone as a GUI display for your raspberry pi. This can work over remotely and there is not HDMI or any other connector required to connect your smartphone to your pi.

There are a few apps that you would require on your smartphone. Download and install

Xserver XSDL

Xserver XSDL is a xserver which can be run on your smartphone. Whereas connectbot is a simple ssh client for connecting to your raspberry pi via ssh. The trick here is to run the Xserver on your smartphone. Ssh to your pi and tell your pi to forward the display to the Xserver running on your smartphone.

Let us see the configurations that need to be verified on the pi. Ssh to your raspberry pi over the network and check the following configuration options in these files.


AllowTcpForwarding yes
X11Forwarding yes
X11DisplayOffset 10


ForwardX11 yes
ForwardX11Trusted yes

If these configuration options are commented out, simply uncomment them. Else add them and restart your ssh server on your pi.

$ sudo service ssh restart

Now start the app Xserver XSDL on your smart phone. It may download a set of fonts and will then ask you to run some commands on your linux PC. The Xserver starts running on port 6000. Now, we need to forward the display of pi to our smartphone.

Go back to the ssh connection on your smartphone and run these commands.

$ export DISPLAY=           
$ export PULSE_SERVER=tcp:

My smartphone is running on the ip And i am forwarding the display directly to the Xserver running on port 6000.
This is insecure as the port forwarding is not happening over ssh but directly from the pi to the smartphone. But if you are on a local network, it should not matter.

Now simply start your lxde desktop environment on the ssh connection. Execute the following command on the ssh connection.

$ startlxde

And bingo…

It is not very comfortable for working as the mouse pointer is difficult to catch and click. But if you have an old smartphone or tablet lying around, you can use it as a display – running a smart photo frame or a hanging smart calendar.

Script to update godaddy dns A record

Recently, I have setup my raspberry pi as a download machine. The aim was to be able to access the machine from anywhere and be able to add files to download. Now, since the machine is connected via airtel broadband, it is bound to go down and come up as and when the electricity in my location does.

Everytime, when the machine came up, i would be having a different public ip address to access the machine as my ADSL modem+router would also go down.

At first, i setup a cron to be run at boot time which would give me the public ip address.

The corresponding cron entry is
@reboot /home/pi/progs/

I also created a dns entry to access the machine. And then wrote a script to update the dns record in godaddy whenever the machine reboots. Here is the script.

Now whenever my pi reboots, it checks and updates the corresponding DNS record at godaddy. And i can ssh my machine from anywhere.