One of our clients requested us a solution to monitor temperature in their datacenters with one condition, this should send data to a Zabbix server without cloud or any other integrations directly using a WIFI network.

Once we had received request we searched for some available solutions but none oh them was satisfying us. This was the moment when we decided to use a ESP32 board with a soldered temperature sensor, in short words building a dedicated solution.

For this project was needed:

  • ESP32 board
  • Zabbix library for ESP32
  • Temperature sensor (DHT22)
  • 3d printer to print a case

First of all we have built a custom library in order to comunicate ESP32 with Zabbix server like using zabbix_sender command. Of course ESP32 board with this sensor can communicate to other monitoring solutions like Nagios, Check_mk, Icinga, Grafana but not limited.

In the following firmware for our sensor we have implemented some mechanisms to ensure retry if something happen with sensor and disconnect from WIFI after data was sent since we need to use battery as efficient as possible.

And the final project looks as you can see in our office in testing some firmware functionalities.

The most important part of code is the following which send data to Zabbix server.

#include <ESP32ZabbixSender.h>
#include <DHT.h>
#include <WiFi.h>
#include <HTTPClient.h>

#define DHTTYPE DHT22
#define DHTPIN 4
#define SERVERADDR x, y, z., t
#define ZABBIXPORT 10051
#define ZABBIXAGHOST "DC1_TMP1"

DHT dht(DHTPIN, DHTTYPE);

ESP32ZabbixSender zSender;

String ssid = "wifi_name";
String pass = "wifi_password";

boolean checkConnection();

void setup() {
	Serial.begin(115200);
  dht.begin();
	WiFi.mode(WIFI_STA);
	WiFi.disconnect();
	delay(1000);
	WiFi.begin(ssid.c_str(), pass.c_str());
	while (!checkConnection()) {
	}
	zSender.Init(IPAddress(SERVERADDR), ZABBIXPORT, ZABBIXAGHOST);

}

void loop() {
  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();
	checkConnection();
	zSender.ClearItem();
	zSender.AddItem("temperature", (float)temperature);
	zSender.AddItem("humidity", (float)humidity);

	if (zSender.Send() == EXIT_SUCCESS) {
		Serial.println("ZABBIX SEND: OK");
	} else {
		Serial.println("ZABBIX SEND: NOT OK");
	}

	delay(60000);
}

boolean checkConnection() {
	int count = 0;
	Serial.print("Waiting for Wi-Fi connection");
	while (count < 30) {
		if (WiFi.status() == WL_CONNECTED) {
      Serial.println(WiFi.localIP());
			Serial.println();
			Serial.println("Connected!");
			return (true);
		}
		delay(500);
		Serial.print(".");
		count++;
	}
	Serial.println("Timed out.");
	return false;
}

Interested in infrastructure monitoring or custom IoT integrations?
→ Explore our Security Analytics (OTHSA)

Categories: Blog

0 Comments

Leave a Reply

Avatar placeholder

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