Tech Tecnología

The best complement for an IoT solution using a Raspberry Pi

October 21, 2020

The best complement for an IoT solution using a Raspberry Pi

This post is also available in : Spanish

Monitor your IoT devices with a Raspberry Pi and Pandora FMS

Pandora FMS is a proactive, advanced, flexible and easy-to-configure monitoring tool according to each business. It gets integrated into all the needs of servers, network computers, terminals and whatever needs to be monitored.

In this article, we will focus on monitoring openHAB (Smart Home Solution), using the software agent installed on our Raspberry Pi (this article applies to both Pandora FMS Community and Enterprise versions).

My Smart Home

Before continuing with the article, I would like to share that everything that I am going to monitor is part of my home. Initially I started with the exterior lights, but little by little I kept on adding things, until I got to integrate CCTVs, an alarm and automation.

To start off, let’s see what a Raspberry Pi is. Basically, a Raspberry Pi is a low-cost single-board minicomputer (SBC) – less than $50 to give you an idea – where instead of hard drive an SD memory card is used.

raspberry pi iot
Raspberry PI 3b+

raspberry pi iot
Raspberry PI 3b, Raspberry PI Zero W

In a Raspberry Pi Zero W you can install a Pandora FMS agent to monitor any device connected to the same WiFi network.

More information about Raspberry Pi in its official page. https://www.raspberrypi.org/

Now, going into more detail, I currently use for my home the following components.

Raspberrys

Name            Raspberry Pi                  Software

openHAB    RPI 3b+, 16 GB            openHAB, Unifi Controller, Pandora FMS Agent

sits-mon      RPI 3B, 16 GB                MotionEYE, Pandora FMS Agent

 

Additional Components

Name  Descrition
Unifi APDevice that supports WIFI network
Firewall Internet and manages IPs of DVR devices
DVR Old DVR with analog cameras
Cámaras IPsNative IP Cameras

It is not the key part of the article, but you will surely wonder what kind of hardware I use to have a smart home solution. Here you can see some pictures so that you can see what it is all about:

raspberry pi iot

Relay Sonoff Basic R1, to which a DHT22 temperature and humidity sensor was added. If you know the device, you know it natively connects with eWelink, but in my case I modified the firmware so that it supports MQTT (we will see in detail what it is a little later)..

raspberry pi iot

Broadlink Alarm Kit: Sensors such as the magnetic one that
you see on the left send signals by RF and I get the data through a plugin in Python on Linux.

raspberry pi iot

Broadlink Environment Sensor: It allows to know the temperature, humidity, light, noise, etc. I get the data with Python on Linux.

Now that you know a little what I am using, we are going to better detail the software used to have my smart home working and its free software components.

openHAB is a home automation bus, a software solution developed in Java that connects components for automation and supports a wide range of vendors on a single platform, regardless of manufacturer and protocol.

The project was started by Kai Kreuzer in 2010 and today it has many co-developers. At the end of 2013 they decided to use the Eclipse SmartHome project as a base. Today both projects are developed at the same time.

More information:

https://www.itsanchez.com.ar/index.php/44-openhab/352-openhab que-es

https://www.openhab.org

Eclipse Mosquitto is an MQTT broker, a widely used protocol for IOT (Internet of Things) industrial solutions. At the heart of the integration with the components that are part of my smart home, before adding something new the first thing I check is that it supports MQTT.

More information: https://mosquitto.org

MotionEYE, is a frontend to integrate any type of camera. I use it to unify technologies (IP Cameras, DVR) and to be able to see them with no issues in openHAB.

More information: https://github.com/ccrisan/motioneye/

Some pictures of my smart home.
raspberry pi iot
raspberry pi iot

Native Application on iOS
raspberry pi iot
raspberry pi iot
raspberry pi iot
Interface screens that support touch screens

Now, after this introduction, we are going to fully delve into monitoring with Pandora FMS.

In my case, Pandora FMS is running in a virtual machine in the Cloud where Pandora FMS server runs and there is the WEB console to work with the solution. In the following diagram we see how it works:

raspberry pi iot
Configuration of the Firewall in the Cloud to be able to monitor the IoT solution

Port          TYPE       Use

443              TCP        Pandora FMS WEB Console

41121        TCP         Agent reception (Tentacle)

On both Raspberry Pi I use the official Raspberry OS (formerly Raspbian), based on Debian 10. To install Pandora FMS agents, just execute the command apt -y install pandorafms-agent from the console through SSH. Before continuing, I will share some screens with the final result and then I will explain some specific settings for Raspberry Pi.

Pandora FMS screenshots
raspberry pi iot
Raspberry Pi Agents

In my case, Pandora FMS is running on a virtual machine in the Cloud.

raspberry pi iot
Graphic Console openHAB

Now, looking at the result a little, we are going to see in more detail why monitoring is important and what are the strengths of Pandora FMS to know the state of a smart home solution. Something very important to keep in mind is the temperature on the Raspberry Pi. At this point we add the following configuration in the file /etc/pandorafms/pandora_agent.conf

## Temperatura Raspberry PI
module_begin
module_name RPI_Temperatura
module_type generic_data
module_exec vcgencmd measure_temp | sed 's/temp=//' | sed 's/C//' | sed 's/.$//g'
module_max 100
module_min 0
module_description Temperatura Procesador RaspberryPI module_min_warning 70
module_max_warning 90
module_min_critical 91
module_max_critical 100
module_end

The line module_exec vcgencmd measure_temp | sed ‘s/temp=//’ | sed ‘s/C//’ | sed ‘s/.$//g’ executes the command vcgencmd measure_temp | sed ‘s/temp=//’ | sed ‘s/C//’ | sed ‘s/.$//g’

Then it returns the current temperature of your Raspberry Pi, as seen in the following image:

raspberry pi iot

We see that adding an important value is something really simple in Pandora FMS and allows you to see the picture (current state) and the movie (historical state) of the temperature of your Raspberry Pi.

raspberry pi iot
Raspberry Pi temperature with cooler (fan)

raspberry pi iot
Raspberry Pi temperature with no cooler (fan)

With these two graphs you can already see that it is highly recommended to use a cooler (fan) so that the usage temperature of the mini computer stays like that. Any value saved in Pandora FMS allows you to carry out this type of analysis, such as the internet speed of your link, network devices, etc. In an IoT solution, knowing that the devices work and being able to generate alerts in the event of a failure is very important and easy to do using Pandora FMS.

Integration of openHAB values in Pandora FMS

Something very important and useful in times of digital transformation is the integration between different software solutions. In this case, I am going to take the temperature and humidity of the sensors that report through MQTT to openHAB and turn them into Pandora FMS monitors using the Agent Plugin logic.

For that create the plugin in the directory /etc/pandorafms/plugins/get_oh_item.sh with the following content

#!/bin/bash
if [ $# -eq 0 ]
then
echo "Item and description must be added "
echo "get_oh_item.sh [ItemPandora] [ItemOH] \"Module Description\""
exit 1
fi
itemp=$1
itemo=$2
desc=$3
i1=$(curl http://localhost:8080/rest/items/$itemo/state ) echo ''
echo " echo " echo " echo "$desc"
echo ''

It is a bash script that, according to 3 parameters, takes a value and generates the monitors in XML format so that they are reported in a simple way in Pandora FMS

How does it work? It’s very easy, run the example:

/etc/pandorafms/plugins/get_oh_item.sh ITS-openHAB-Humedad Garage GarageHum “Garage Humidity”

And you get the following result:

raspberry pi iot

For the data to be in our Pandora FMS console, edit the file /etc/pandorafms/pandora_agent.with and add the following line:

module_plugin /etc/pandorafms/plugins/get_oh_item.sh ITS openHAB-Garage-Humidity GarageHum “Garage Humidity”

Save the file and restart the agent with the command systemctl restart pandorafms-agent

raspberry pi iot

Validate the monitors created with your Agent Plugin. Having the values you can generate native visual consoles like the following:

raspberry pi iot

With a little more effort, by integrating Pandora FMS with Grafana you can make dashboards like the following:

raspberry pi iot

raspberry pi iot

To finish off, remember Pandora FMS is a flexible monitoring system, capable of monitoring devices, infrastructures, applications, services and business processes.

Would you like to find out more about what Pandora FMS can offer you? Find out clicking here .

If you have to monitor more than 100 devices, you can also enjoy a FREE 30-day Pandora FMS Enterprise DEMO . Get it here .

Last but not least, remember that if you have a reduced number of devices to monitor, you can use the Pandora FMS OpenSource version. Find more information here .


Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.