#include <WiFi.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>

#define NTP_SERVER "pool.ntp.org"
#define UTC_OFFSET 0
#define UTC_OFFSET_DST 0
int utc7 = 25200;

DHT dht(19, DHT22);
Adafruit_SSD1306 display(128, 64, &Wire, -1);

void setup() {
  Serial.begin(115200);

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.setTextSize(1);
  display.setTextColor(WHITE);

  display.clearDisplay();
  display.setCursor(0,0);
  display.println("Nama: Devin Sanyoka");
  display.println("NIM: H1051211002");
  display.println("Kelas: IoT 1");
  display.display();

  delay(5000);

  WiFi.begin("Wokwi-GUEST", "", 6);
  while (WiFi.status() != WL_CONNECTED) {
    int i = 0;
    display.clearDisplay();
    display.setCursor(0,0);
    display.print("Connecting to WiFI");
    display.display();
    while (i<3) {
      delay(50);
      display.print(".");
      display.display();
      i++;
    }
  }
  display.clearDisplay();
  display.setCursor(0,0);
  display.print("Online, now updating time...");
  display.display();
  configTime(utc7, UTC_OFFSET_DST, NTP_SERVER);

  struct tm timeinfo;
  if (!getLocalTime(&timeinfo)) {
    display.clearDisplay();
    display.setCursor(0,0);
    display.print("Time Error");
    display.display();
    delay(5000);
    return;
  }
  display.clearDisplay();
  display.setCursor(0,0);
  display.println("The time is:");
  display.println(&timeinfo, "%H:%M:%S");
  display.print(&timeinfo, "%d/%m/%Y"); display.println(" WIB");
  display.display();
  delay(5000);
}

void loop() {
  float tempc = dht.readTemperature();
  float tempf = (tempc*9/5)+32;
  float tempk = tempc+273;
  float humi = dht.readHumidity();

  display.clearDisplay();
  display.setCursor(0,0);
  display.print("Suhu (C): "); display.println(tempc);
  display.print("Suhu (F): "); display.println(tempf);
  display.print("Suhu (K): "); display.println(tempk);
  display.print("Kelembapan: "); display.println(humi);
  display.display();
}
$abcdeabcde151015202530fghijfghij
esp:0
esp:2
esp:4
esp:5
esp:12
esp:13
esp:14
esp:15
esp:16
esp:17
esp:18
esp:19
esp:21
esp:22
esp:23
esp:25
esp:26
esp:27
esp:32
esp:33
esp:34
esp:35
esp:3V3
esp:EN
esp:VP
esp:VN
esp:GND.1
esp:D2
esp:D3
esp:CMD
esp:5V
esp:GND.2
esp:TX
esp:RX
esp:GND.3
esp:D1
esp:D0
esp:CLK
dht1:VCC
dht1:SDA
dht1:NC
dht1:GND
Loading
ssd1306