Weatherstation2 — ESP32 simulation

An interactive ESP32 circuit simulation you can run free in your browser on Velxio, by szaboj0924.

Components

Sketch code

#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <time.h>
#include <DHT.h>
#include <ArduinoOTA.h>

#include <varoskep.h>
#include <moon.h>
#include <space.h>
#include <nameday.h>
#include <birth.h>
#include <secrets.h>
#include <weatheranim.h>

// =====================================================
// HARDVERBEÁLLÍTÁSOK
// =====================================================

//képernyő
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
#define OLED_ADDRESS 0x3C

//dht
#define SDA_PIN 21
#define SCL_PIN 22
#define DHTPIN 19
#define DHTTYPE DHT11
#define MODE_SWITCH 23

// forgattyú
#define ENCODER_CLK 25
#define ENCODER_DT  26
#define ENCODER_SW  27


// =====================================================
// WIFI / OTA (átkerült külön .h-ba)
// =====================================================

#define WIFI_SSID "123"
#define WIFI_PASSWORD "234"
#define OTA_PASSWORD "4511932"

// Újracsatlakozáshoz
#define WIFI_RETRY_INTERVAL 30000UL

// Tárkány koordinátái
const float LATITUDE = 47.72;
const float LONGITUDE = 18.49;

// =====================================================
// IDŐZÍTÉSEK
// =====================================================

const unsigned long WEATHER_INTERVAL = 1200000UL; // 20 perc
const unsigned long DHT_INTERVAL = 5000UL;        // 5 másodperc
const unsigned long AUTO_MODE_DELAY = 600000UL;   // 10 perc
const unsigned long AUTO_SCREEN_INTERVAL = 10000UL; // 10 mp
const unsigned long MULTICLICK_TIME = 500; //0,5 másodperc
const unsigned long DEBOUNCE_MS = 40; //40 miliszekundum

unsigned long lastAnimation = 0;
unsigned long lastAnimUpdate = 0;
unsigned long lastDHTRead = 0;
unsigned long lastWeatherUpdate = 0;
unsigned long lastWiFiRetry = 0;
unsigned long lastUserAction = 0;
unsigned long lastAutoSwitch = 0;
unsigned long lastStarUpdate = 0;
unsigned long lastDebounceTime = 0;

uint8_t animFrame = 0;
uint8_t spaceFrame = 0;
uint8_t frame = 0;

// =====================================================
// OBJEKTUMOK
// =====================================================

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
DHT dht(DHTPIN, DHTTYPE);

// =====================================================
// GLOBÁLIS VÁLTOZÓK
// =====================================================
const int HISTORY_SIZE = 4;  // 4 db órás minta

char sunriseTime[20] = "2020-01-01T06:00";
char sunsetTime[20] = "2020-01-01T18:00";
bool otaStarted = false;
bool oledOk = false;
bool wifiTest = true;
bool forceMoonPhase = false;
bool extraMenu = false;
bool lastButtonState = HIGH;
bool stableButtonState = HIGH;
float insideTemp = 0.0;
int insideHumidity = 0;
float temperature = 0.0;
int humidity = 0;
int forecastCode1 = 0;
int forecastCode2 = 0;
int forecastCode3 = 0;
int forecastCode4 = 0;
int windDirection = 0;
int historyIndex = 0;
int historyCount = 0;
float forecastMax1 = 0.0;
float forecastMin1 = 0.0;
float forecast