64 lines
1.6 KiB
C++
64 lines
1.6 KiB
C++
#include <DHT.h>
|
|
#include <ESP8266WiFi.h>
|
|
#include <ESP8266ZabbixSender.h>
|
|
//#include "konfigurace_local.h"
|
|
#include "konfigurace.h"
|
|
|
|
#define pinKONTAKT 14
|
|
#define pinDHT 12
|
|
#define typDHT11 DHT11
|
|
|
|
DHT cidlo(pinDHT, typDHT11);
|
|
const int measurment_delay = 60;
|
|
unsigned long lastMsg = 0;
|
|
ESP8266ZabbixSender zSender;
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
delay(2000);
|
|
pinMode(pinKONTAKT, INPUT_PULLUP);
|
|
Serial.println("Start");
|
|
WiFi.mode(WIFI_STA);
|
|
WiFi.begin(ssid, password);
|
|
while (WiFi.status() != WL_CONNECTED) {
|
|
delay(500);
|
|
}
|
|
Serial.println("Pripojeno");
|
|
Serial.println();
|
|
Serial.print("MAC adresa: ");
|
|
Serial.println(WiFi.macAddress());
|
|
Serial.print("IP adresa: ");
|
|
Serial.println(WiFi.localIP());
|
|
WiFiClient client;
|
|
zSender.Init(IPAddress(SERVERADDR), ZABBIXPORT, ZABBIXAGHOST);
|
|
}
|
|
|
|
void loop() {
|
|
if (millis() - lastMsg > (1000 * measurment_delay) || millis() < (lastMsg - 1000)) {
|
|
sendMessage();
|
|
}
|
|
}
|
|
|
|
void sendMessage()
|
|
{
|
|
int kontakt = digitalRead(pinKONTAKT)? 0 : 1;
|
|
float teplota = cidlo.readTemperature();
|
|
float vlhkost = cidlo.readHumidity();
|
|
Serial.print("Kontakt: ");
|
|
Serial.println(kontakt);
|
|
Serial.print("Teplota: ");
|
|
Serial.println(teplota);
|
|
Serial.print("Vlhkost: ");
|
|
Serial.println(vlhkost);
|
|
zSender.ClearItem();
|
|
zSender.AddItem("kontakt", kontakt);
|
|
zSender.AddItem("teplota", teplota);
|
|
zSender.AddItem("vlhkost", vlhkost);
|
|
if (zSender.Send() == EXIT_SUCCESS) {
|
|
Serial.println("ZABBIX SEND: OK");
|
|
} else {
|
|
Serial.println("ZABBIX SEND: ERROR");
|
|
}
|
|
lastMsg = millis();
|
|
}
|