CARVIEW |
Select Language
HTTP/2 200
date: Mon, 13 Oct 2025 19:08:10 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1;mode=block
vary: accept-encoding
cf-cache-status: DYNAMIC
content-encoding: gzip
set-cookie: _csrf-frontend=c517b0844dbf627cda6a1bcd351f0bab2f7d58b15750d5c45edf5906248309a3a%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22DfR8y2usvvFq4HWvG31gvaAkfyof6b57%22%3B%7D; HttpOnly; Path=/
cf-ray: 98e11fc4eee58087-BLR
ESP32 + ST7796S WEATHER DASHBOARD - Pastebin.com
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //PROGRAM BY: RANDY N. CAÑADA
- /*SUBSCRIBE: FB PAGES:
- Playlist.ph:
- https://www.facebook.com/profile.php?id=61573177858722
- Arduino:
- https://www.facebook.com/rhacan2?__tn__=R
- YOUTUBE:
- PlaylistPH
- https://www.youtube.com/@PlaylistPh-h2v
- ElectroCrafters:
- https://www.youtube.com/channel/UCu1aqzUdTqSnTN5BHNlbVgA */
- #include <WiFi.h>
- #include <HTTPClient.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_ST7796S_kbv.h>
- #include <SPI.h>
- #include <ArduinoJson.h>
- #include <time.h>
- #include <math.h>
- // ------------------- TFT Pins -------------------
- #define TFT_CS 5
- #define TFT_DC 2
- #define TFT_RST 4
- #define TFT_BL 15
- #define REFRESH_BUTTON 13
- Adafruit_ST7796S_kbv tft = Adafruit_ST7796S_kbv(TFT_CS, TFT_DC, TFT_RST);
- // ------------------- Colors -------------------
- #define COLOR_BG 0x0000
- #define COLOR_CLOCK 0x7D7C
- #define COLOR_LOCATION 0xA89F
- #define COLOR_SUNDAY 0xF800
- #define COLOR_WEEKDAY 0x001F
- #define COLOR_TEMP 0xFD20
- #define COLOR_CONDITION 0xFFE0
- #define COLOR_SUNRISE 0xFFE0
- #define COLOR_DATE 0xFFFF
- #define COLOR_ERROR 0xF800
- // ------------------- WiFi & API -------------------
- const char* ssid = "YOUR WIFI";
- const char* password = "YOUR PASSWORD";
- const char* apiKey = "YOUR API KEY";
- const char* apiURL = "https://api.openweathermap.org/data/2.5/forecast?lat=-39.6386&lon=176.8497&units=metric&appid=";
- String locationName = "Pukahu, NZ";
- const char* dayNames[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
- // ------------------- Weather Icons -------------------
- void drawSunAnimated(int x, int y, int frame) {
- int radius = 10 + frame % 3;
- tft.fillCircle(x, y, radius, COLOR_SUNDAY);
- for (int i = 0; i < 360; i += 45) {
- float rad = i * M_PI / 180.0;
- int x1 = x + cos(rad) * (14 + frame % 2);
- int y1 = y + sin(rad) * (14 + frame % 2);
- int x2 = x + cos(rad) * (18 + frame % 2);
- int y2 = y + sin(rad) * (18 + frame % 2);
- tft.drawLine(x1, y1, x2, y2, COLOR_SUNDAY);
- }
- }
- void drawCloudAnimated(int x, int y, int frame) {
- int offset = frame % 3;
- tft.fillRoundRect(x + offset, y, 30, 20, 10, COLOR_WEEKDAY);
- tft.fillCircle(x + 10 + offset, y, 10, COLOR_WEEKDAY);
- tft.fillCircle(x + 20 + offset, y, 10, COLOR_WEEKDAY);
- }
- void drawRainAnimated(int x, int y, int frame) {
- drawCloudAnimated(x, y, frame);
- for (int i = 0; i < 3; i++) {
- int dropY = y + 20 + (frame % 4);
- tft.drawLine(x + 10 + i * 8, dropY, x + 10 + i * 8, dropY + 10, COLOR_WEEKDAY);
- }
- }
- // ------------------- Setup -------------------
- void setup() {
- Serial.begin(115200);
- SPI.begin(18, -1, 23, TFT_CS);
- pinMode(TFT_BL, OUTPUT);
- pinMode(REFRESH_BUTTON, INPUT_PULLUP);
- digitalWrite(TFT_BL, HIGH);
- tft.begin();
- tft.setRotation(1);
- tft.fillScreen(COLOR_BG);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("WiFi Connected!");
- configTime(0, 0, "pool.ntp.org");
- setenv("TZ", "NZST-12NZDT,M9.5.0,M4.1.0/3", 1);
- tzset();
- fetchForecast();
- }
- // ------------------- Forecast Fetch -------------------
- void fetchForecast() {
- HTTPClient http;
- String fullURL = String(apiURL) + apiKey;
- http.begin(fullURL);
- int httpCode = http.GET();
- if (httpCode == 200) {
- String payload = http.getString();
- DynamicJsonDocument doc(16384);
- DeserializationError error = deserializeJson(doc, payload);
- if (error) {
- tft.setCursor(20, 20);
- tft.setTextColor(COLOR_ERROR);
- tft.setTextSize(2);
- tft.println("JSON parse error.");
- return;
- }
- // ---- Current Date & Time ----
- time_t now;
- time(&now);
- struct tm timeinfo;
- localtime_r(&now, &timeinfo);
- char dateStr[32];
- strftime(dateStr, sizeof(dateStr), "%A %d %b %Y", &timeinfo);
- tft.fillScreen(COLOR_BG);
- tft.setTextColor(COLOR_DATE);
- tft.setTextSize(2);
- tft.setCursor(20, 20);
- tft.print(dateStr);
- tft.setTextColor(COLOR_LOCATION);
- tft.print(", ");
- tft.println(locationName);
- char timeStr[16];
- strftime(timeStr, sizeof(timeStr), "%I:%M:%S %p", &timeinfo);
- tft.setTextColor(COLOR_CLOCK);
- tft.setTextSize(4);
- tft.setCursor(20, 50);
- tft.println(timeStr);
- // ---- Current Temp & Condition ----
- float currentTemp = doc["list"][0]["main"]["temp"];
- String currentCond = doc["list"][0]["weather"][0]["description"].as<String>();
- tft.setTextSize(2);
- tft.setTextColor(COLOR_DATE);
- tft.setCursor(20, 100);
- tft.printf("Now: %.1fC", currentTemp);
- tft.setTextColor(COLOR_CONDITION);
- tft.setCursor(160, 100);
- tft.println(currentCond);
- // ---- Sunrise & Sunset ----
- time_t sunriseUTC = doc["city"]["sunrise"].as<long>();
- time_t sunsetUTC = doc["city"]["sunset"].as<long>();
- struct tm suninfo, setinfo;
- localtime_r(&sunriseUTC, &suninfo);
- localtime_r(&sunsetUTC, &setinfo);
- char sunStr[16], setStr[16];
- strftime(sunStr, sizeof(sunStr), "%I:%M %p", &suninfo);
- strftime(setStr, sizeof(setStr), "%I:%M %p", &setinfo);
- // ---- Debug ----
- Serial.printf("Sunrise Local: %s\n", sunStr);
- Serial.printf("Sunset Local: %s\n", setStr);
- // ---- Print Sunrise & Sunset ----
- tft.setTextColor(COLOR_DATE);
- tft.setCursor(20, 125);
- tft.print("Sunrise: ");
- tft.setTextColor(COLOR_SUNRISE);
- tft.println(sunStr);
- tft.setTextColor(COLOR_DATE);
- tft.setCursor(220, 125);
- tft.print(" Sunset: "); // two spaces
- tft.setTextColor(COLOR_SUNRISE);
- tft.println(setStr);
- // ---- Forecast Midday ----
- tft.drawLine(20, 145, 460, 145, COLOR_DATE);
- int found = 0;
- int frame = millis() / 500;
- for (JsonObject entry : doc["list"].as<JsonArray>()) {
- const char* dt_txt = entry["dt_txt"];
- if (strstr(dt_txt, "12:00:00")) {
- time_t dt = entry["dt"];
- struct tm dayinfo;
- localtime_r(&dt, &dayinfo);
- int x = 20 + found * 90;
- if (dayNames[dayinfo.tm_wday] == String("Sun")) {
- tft.setTextColor(COLOR_SUNDAY);
- } else {
- tft.setTextColor(COLOR_WEEKDAY);
- }
- tft.setTextSize(2);
- tft.setCursor(x, 160);
- tft.println(dayNames[dayinfo.tm_wday]);
- float temp = entry["main"]["temp"];
- tft.setTextColor(COLOR_TEMP);
- tft.setCursor(x, 185);
- tft.printf("%.0fC", temp);
- String condition = entry["weather"][0]["main"].as<String>();
- if (condition == "Clear") drawSunAnimated(x + 30, 220, frame);
- else if (condition == "Rain") drawRainAnimated(x + 20, 220, frame);
- else drawCloudAnimated(x + 20, 220, frame);
- found++;
- if (found >= 5) break;
- }
- }
- if (found == 0) {
- tft.setCursor(20, 160);
- tft.setTextColor(COLOR_ERROR);
- tft.setTextSize(2);
- tft.println("No midday forecasts found.");
- }
- } else {
- tft.setCursor(20, 20);
- tft.setTextColor(COLOR_ERROR);
- tft.setTextSize(2);
- tft.println("Failed to fetch forecast.");
- }
- http.end();
- }
- // ------------------- Loop -------------------
- // ------------------- Loop -------------------
- void loop() {
- static bool buttonPressed = false;
- static unsigned long lastDebounceTime = 0;
- const unsigned long debounceDelay = 50; // 50ms debounce
- int reading = digitalRead(REFRESH_BUTTON);
- // If button state changes
- if (reading == LOW && !buttonPressed && (millis() - lastDebounceTime > debounceDelay)) {
- buttonPressed = true;
- lastDebounceTime = millis();
- Serial.println("Manual refresh triggered!");
- fetchForecast();
- }
- // Reset latch when released
- if (reading == HIGH) {
- buttonPressed = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
-
⭐⭐⭐Crypto Accounts⭐⭐
Java | 4 sec ago | 0.15 KB
-
💡 Instant BTC Profit Method ✅ Working
JavaScript | 10 sec ago | 0.24 KB
-
📝 MAKE $2500 IN 15 MIN ✅ Working
JavaScript | 20 sec ago | 0.24 KB
-
⭐⭐⭐Make $1500 in 20 minutes⭐⭐
Java | 20 sec ago | 0.15 KB
-
⭐⭐⭐Crypto Accounts⭐⭐
Java | 26 sec ago | 0.15 KB
-
💵 Make 3000$ in 20 minutes 💵
JavaScript | 30 sec ago | 0.24 KB
-
⭐⭐⭐MAKE $500 IN 15 MIN⭐⭐
Java | 37 sec ago | 0.15 KB
-
💡 EASY MONEY GUIDE ✅ Working
JavaScript | 40 sec ago | 0.24 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand