Tuesday, January 26, 2016

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.