Developing an app with Raspberry Pi: Behind the scenes of Horreum Weather

Raspberry Pi logo

Today, computers come in all kinds of shapes and sizes, so we decided to investigate the small ones since they’ve become a very important part of everyday life. To investigate their usefulness, we chose the Raspberry Pi 3 as a representative example and built a whole app with its help.

What exactly is a small computer?

This awesome machine changed our lives in so many ways. A small computer is a type of computer that possesses most of the features and capabilities of a large computer but is smaller in physical size. They were primarily designed for business applications and services that require the performance and efficiency of mainframe computers. Small computers are generally used as mid-range servers, where they can operate mid-sized software applications and support numerous users simultaneously.
Small computers may contain one or more processors, support multiprocessing and tasking, and are generally resilient to high workloads. Although they are smaller than mainframe or supercomputers, small computers are more powerful than personal computers and workstations.

Raspberry Pi

One of these small computers is the Raspberry Pi. The Raspberry Pi is a credit-card sized computer that plugs into a computer monitor or a TV and uses the standard keyboard and mouse. It is a capable little device that enables people of all ages to explore computing and to learn how to program in languages like JavaScript or Python.

Our goal is to present one small, powerful computer with many sensors that show useful data. All the parts of the hardware that we used were:

  • Raspberry Pi 3 b+
  • Camera Module v2
  • SDS 011 Sensor (Air Quality)
  • AM2302 DHT22 Sensor ( temperature and Humidity)
  • Breadboard

Before we started the development we connected all of these sensors on Raspberry Pi like on the picture below:

a photo of all elements of a Raspberry Pi computer

Technical details

Before we can start using our Raspberry Pi for anything, we need to get an OS installed. Raspbian is a free operating system based on Debian Linux, and it is optimized Raspberry Pi. We used Raspbian Strech Lite OS and install through the program named Etcher. Etcher ( is a program for flashing images to memory cards. In addition, a connection to the Internet has been made.

Camera Module v2

The Raspberry Pi Camera Module is an official product from the Raspberry Pi Foundation. After the connection of the camera on Raspberry Pi, we choose Node.js environment to stream video to a remote server. To send the data to the remote server, we used the FFMPEG framework. FFmpeg is the leading multimedia framework, able to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created. It supports the most obscure ancient formats up to the cutting edge. No matter if they were designed by some standards committee, the community or a corporation. It is also highly portable: FFmpeg compiles, runs, and passes our testing infrastructure across Linux, Mac OS X, Microsoft Windows, the BSDs, Solaris, etc. under a wide variety of build environments, machine architectures, and configurations. The standard for video compression we used is H.264. After all that configuration the live streaming is ready for following by the customers.

The following code was used to run FFmpeg framework for live streaming video and other data like temperature, humidity, PM2.5, and PM10 particulate matter. Also, the second part of the code shows us how to kill that process every time when we again call that function. We need that because we call that function many times and sensors are busy if we don’t kill before calling.

var exec = require('child_process').exec;
var cmd = `ffmpeg -i /dev/video0  -i logo.png -filter_complex "overlay=15:15, drawtext=text=${temp}:x=600:y=10: fontfile=/home/pi/font2.ttf:fontsize=35:fontcolor=white: shadowcolor=black:shadowx=5:shadowy=5, drawtext=text=${hum}:x=600:y=65: fontfile=/home/pi/font2.ttf:fontsize=35:fontcolor=white: shadowcolor=black:shadowx=5:shadowy=5, drawtext=text=${airPolution}:x=600:y=120: fontfile=/home/pi/font2.ttf:fontsize=35:fontcolor=white: shadowcolor=black:shadowx=5:shadowy=5" -f mpegts udp://${configData.videoServerFFsrvIp}`;
exec(cmd, function(error, stdout, stderr) {
   if (error) {
var fuser = `fuser /dev/video0`;
   exec(fuser, function(error, stdout, stderr) {
      var kill =  `kill -9 ${stdout}`;
         exec(kill, function(error, stdout, stderr) {
           exec(cmd, function(error, stdout, stderr) {



SDS 011 Sensor

Nova Fitness SDS011 is a professional laser dust sensor. Fan mounted on sensor automatically sucks air in. The sensor uses laser light scattering principle to measure the value of dust particles suspended in the air. The sensor provides high precision and reliable readings of PM2.5 and PM10 values. Any change in environment can be observed almost instantaneously – short respond time below 10 seconds. A sensor in standard mode reports reading with a 1-second interval. We are reading data (PM2.5 and PM10) with 1-sec interval.

Now we’ll show you the code which reads data from a serial port and calculates PM2.5 and PM10 values before printing in the console.

var SerialPort = require('serialport');
var port = new SerialPort('/dev/ttyUSB0');
port.on('data', (data) => {
 // console.log(data);
 let PM25 = ((data[3] * 256) + data[2]) /10
 let PM10 = ((data[5] * 256) + data[4]) /10
 console.log('PM25=', PM25, '\tPM10=', PM10 );
// open errors will be emitted as an error event
port.on('error', function(err) {
 console.log('Error: ', err.message);

What is PM2.5 and PM10?

PM10 is particulate matter 10 micrometers or less in diameter, PM2.5 is particulate matter 2.5 micrometers or less in diameter. That is particles of air pollution. PM2.5 is generally described as fine particles. Particles in this size range make up a large proportion of dust that can be drawn deep into the lungs.

AM2302 DHT22 Sensor

he AM2302 is a wired version of the DHT22, in a large plastic body. It is a basic digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and spits out a digital signal on the data pin. It’s fairly simple to use but requires careful timing to grab data. Before use this sensor you need to connect sensor overt the breadboard to Raspberry Pi like on the image below.

image showing how to connect AM2302 sensor to Raspberry Pi

Connecting AM2302 sensor to Raspberry Pi

We need a 4.7k Ohm resistor. Some articles state you can also use a 10k Ohm resistor, but I did not test this. After connection, you can follow the tutorial step by step on that link to configure AM2302 sensor.

Horreum Weather app

The following is a result of all configuration and connection to the remote server. We finally have a real-time view of live streaming with other data like on the image below.

Horreum Weather app preview
Horreum Weather app preview

This tool can also be used on multiple platforms very easily. With our API based project, we can make a mobile application, web application, Windows OS, and many other applications.

After all these things that have been processed, it can be concluded that by simple implementation we can create a very useful tool that we can use in everyday life. In addition, there is plenty of room for improving and extending our tools. An example of that is adding many similar sensors like before and make UI modern application based on the website or mobile platforms.

This article was written by our very own Aleksandar Jovanovic

You may also like

1 Comment

  1. Howdy! This is kind of off topic but I need some help from an established blog. Is it very difficult to set up your own blog? I’m not very techincal but I can figure things out pretty quick. I’m thinking about setting up my own but I’m not sure where to begin. Do you have any ideas or suggestions? Thank you

Leave a Reply

Your email address will not be published. Required fields are marked *