Prvni commit
This commit is contained in:
commit
337b3ae91b
|
@ -0,0 +1 @@
|
|||
konfigurace_jarda.h
|
|
@ -0,0 +1,6 @@
|
|||
#define SERVERADDR //127, 0, 0, 1
|
||||
#define ZABBIXPORT //10051
|
||||
#define ZABBIXAGHOST //"Mrazak-Test1"
|
||||
|
||||
const char* ssid = // "dochazka";
|
||||
const char* password = // "Heslo";
|
|
@ -0,0 +1,57 @@
|
|||
#include <DHT.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266ZabbixSender.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");
|
||||
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();
|
||||
}
|
Reference in New Issue