#define RELAY1 16  // D0
#define RELAY2 14  // D5
#define RELAY3 13  // D2
#define RELAY4 12  // D1

const char* version = "v2.3";

const char* ssid = "Vlcice";
const char* password = "1010201010";
const char* host = "terarium";


#include <Arduino.h>

#include <Preferences.h>  // preference
Preferences pref;

#include "time.h"

#include "relay.h"

#include "bme280.h"

#include "webserver.h"

#include "ota.h"


void setup() {

 

  Serial.begin(9600);
  Serial.println("");
  Serial.println("");
  Serial.println("Booting .... ");
  Serial.println("Version: " + String(version));

  pref.begin("my-app", false);

  wifi_setup();

  time_client_setup();

  // nastaveni vystupu
  relay_setup();

  sensor_setup();

  webserver_setup();

  ota_setup();

  Serial.println("Booting end");

}

void loop() {
  update_sensor_data();
  ota_handler();
  time_client_update();
  relay_scheduler();
}

void wifi_setup() {
  WiFi.mode(WIFI_STA);
  WiFi.hostname(host);
  WiFi.begin(ssid, password);
  if (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.printf("WiFi Failed!\n");
    return;
  }

  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());
}