#include <WiFiManager.h>
#include <HTTPClient.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <ArduinoJson.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "DHT.h"
#include "symbols.h"
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define DHTPIN 14
#define DHTTYPE DHT11
// Network Time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org");
unsigned long previousMillisGetTimeDate = 0;
const long intervalGetTimeDate = 1000;
String weekDays[7] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
String weekDays3Dgt[7] = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
String months[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
unsigned long epochTime;
int currentHour, currentMinute, currentSecond;
String weekDay;
int monthDay, currentMonth;
String currentMonthName;
int currentYear, currentYearforSet;
String _DateTime;
int timezone_offset;
// Weather Data
String current_weather_Description;
String current_weather;
int current_temperature, current_pressure, current_humidity, current_wind_deg, current_visibility;
float current_wind_speed, current_feels_like, current_uv, current_dew_point;
String current_weather_sym;
String forecast_weather[4];
String forecast_weather_sym[4];
float forecast_temp_min[4];
float forecast_temp_max[4];
// Open Weather API
String Location = "General Santos City, PH";
String API_Key = "ef2e736841ed8ac931e043b7cd66961d";
String city = "General Santos";
String countryCode = "PH";
String units = "metric";
// ArduinoJSON
String strjsonBuffer;
String strjsonBufferCF;
JsonDocument root;
JsonDocument rootCF;
int update_trigger = 1;
// WiFi Manager
WiFiManager wifiManager;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
Serial.println("\n Starting youuuu");
// Wi-Fi
WiFi.mode(WIFI_STA);
Serial.print("Connecting to WiFi");
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println(" Connected!");
// bool resultant = wifiManager.autoConnect("Weathering With You");
// if (!resultant) {
// Serial.println("Failed to connect or hit timeout");
// delay(5000);
// ESP.restart();
// } else {
// Serial.println("Connected... Yeey :)");
// }
Serial.println(F("Weather Roll!"));
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
while (true)
;
}
dht.begin();
timeClient.begin();
timeClient.setTimeOffset(28800);
timeClient.begin();
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(3, 19);
display.println(" Get weather data");
display.setCursor(3, 28);
display.println(" from");
display.setCursor(3, 37);
display.println(" OpenWeatherMap");
display.drawRect(0, 0, 128, 64, WHITE); //--> Display frame
display.display();
delay(1000);
get_weather_data();
display.clearDisplay(); // clear display
display.setTextSize(1); // set text size
display.setTextColor(WHITE); // set text color
display.setCursor(0, 0); // set position to display
// set text
display.display(); // display on OLED
}
unsigned long lastSensorMillis = 0;
unsigned long lastGetTimeMillis = 0;
float h;
float t;
float hic;
void loop() {
// LED Indicator
// if (WiFi.status() == WL_CONNECTED) {
// digitalWrite(BUILTIN_LED, LOW);
// } else {
// digitalWrite(BUILTIN_LED, HIGH);
// }
// Serial Commands
if (Serial.available()) {
String payload = Serial.readStringUntil('\n');
if (payload.indexOf("resetWifi") >= 0) {
Serial.println("[CMD] Reset Wifi");
wifiManager.resetSettings();
}
}
// if (millis() - lastSensorMillis > 2000) {
// lastSensorMillis = millis();
// float h = dht.readHumidity();
// // delay(10);
// float t = dht.readTemperature();
// // Check if any reads failed and exit early (to try again).
// if (isnan(h) || isnan(t)) {
// Serial.println(F("Failed to read from DHT sensor!"));
// return;
// }
// // Compute heat index in Celsius (isFahreheit = false)
// float hic = dht.computeHeatIndex(t, h, false);
// }
// Time
if (millis() - lastGetTimeMillis >= 1000) {
lastGetTimeMillis = millis();
//----------------------------------------Processing time and date data
char timeProcess[8];
sprintf(timeProcess, "%02u:%02u:%02u", currentHour, currentMinute, currentSecond);
char _time[8];
strcpy(_time, timeProcess);
char dateDayProcess[2];
sprintf(dateDayProcess, "%02u", timeClient.getDay());
char _dateDay[2];
strcpy(_dateDay, dateDayProcess);
_DateTime = _dateDay;
_DateTime += "-" + currentMonthName + "-" + String(currentYear) + " " + _time;
//----------------------------------------
//----------------------------------------Conditions for updating weather data, time and date.
if (update_trigger == 1 && currentMinute % 15 == 0) {
display.clearDisplay(); //--> for Clearing the display
display.drawRect(0, 0, 128, 64, WHITE); //--> Display frame
display_current_weather_data();
display.drawRect(0, 0, 128, 64, WHITE);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(4, 52); //--> (x position, y position)
display.println(" Updating Data...");
display.drawLine(0, 47, 127, 47, WHITE);
display.display();
get_weather_data();
Serial.println("Set the Date and Time from the Internet...");
set_time_and_date();
update_trigger = 0;
}
if (currentMinute % 15 != 0) {
update_trigger = 1;
}
if (currentSecond > 20 && currentSecond < 26) {
display_weather_description();
} else if (currentSecond > 25 && currentSecond < 36) {
display_other_information_1();
} else if (currentSecond > 35 && currentSecond < 46) {
display_other_information_2();
} else if (currentSecond > 45 && currentSecond < 56) {
display_weather_forecast_data();
} else {
display.clearDisplay(); //--> for Clearing the display
display.drawRect(0, 0, 128, 64, WHITE); //--> Display frame
display_current_weather_data();
display_current_datetime();
display.drawLine(0, 47, 127, 47, WHITE);
display.display();
}
// display.setCursor(0, 10);
// display.print("Humidity : ");
// display.print(h);
// display.println(" %");
// display.setCursor(0, 20);
// display.print("Temperature: ");
// display.print(h);
// display.println(" C");
// display.display();
// Serial.print(F("Humidity: "));
// Serial.print(h);
// Serial.print(F("% Temperature: "));
// Serial.print(t);
// Serial.print(F("°C "));
// Serial.print(F("Heat index: "));
// Serial.print(hic);
// Serial.println(F("°C "));
if (WiFi.status() == WL_CONNECTED) {
unsigned long currentMillisGetTimeDate = millis();
if (currentMillisGetTimeDate - previousMillisGetTimeDate >= intervalGetTimeDate) {
previousMillisGetTimeDate = currentMillisGetTimeDate;
// Processing time and date data
char timeProcess[8];
sprintf(timeProcess, "%02u:%02u:%02u", currentHour, currentMinute, currentSecond);
char _time[8];
strcpy(_time, timeProcess);
char dateDayProcess[2];
sprintf(dateDayProcess, "%02u", timeClient.getDay());
char _dateDay[2];
strcpy(_dateDay, dateDayProcess);
_DateTime = _dateDay;
_DateTime += "-" + currentMonthName + "-" + String(currentYear) + " " + _time;
//----------------------------------------
// Conditions for updating weather data, time and date.
if (update_trigger == 1 && currentMinute % 15 == 0) {
display.clearDisplay(); //--> for Clearing the display
display.drawRect(0, 0, 128, 64, WHITE); //--> Display frame
display_current_weather_data();
display.drawRect(0, 0, 128, 64, WHITE);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(4, 52); //--> (x position, y position)
display.println(" Updating Data...");
display.drawLine(0, 47, 127, 47, WHITE);
display.display();
get_weather_data();
Serial.println("Set the Date and Time from the Internet...");
set_time_and_date();
update_trigger = 0;
}
if (currentMinute % 15 != 0) {
update_trigger = 1;
}
//----------------------------------------
// Conditions for displaying more detailed weather data
if (currentSecond > 20 && currentSecond < 26) {
display_weather_description();
} else if (currentSecond > 25 && currentSecond< 36) {
display_other_information_1();
} else if (currentSecond > 35 && currentSecond < 46) {
display_other_information_2();
} else if (currentSecond > 45 && currentSecond < 56) {
display_weather_forecast_data();
} else {
display.clearDisplay(); //--> for Clearing the display
display.drawRect(0, 0, 128, 64, WHITE); //--> Display frame
display_current_weather_data();
display_current_datetime();
display.drawLine(0, 47, 127, 47, WHITE);
display.display();
}
//----------------------------------------
}
//__________________________________________________________________________________________________
} else {
connection_lost();
}
}
}
void connection_lost() {
Serial.println("WiFi Disconnected");
display.clearDisplay(); //--> for Clearing the display
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 28);
display.println(" Connection lost !");
display.setCursor(0, 38);
display.println("Please configure wifi.");
display.drawRect(0, 0, 128, 64, WHITE); //--> Display frame
display.display();
delay(5000);
}
void get_weather_data() {
if (WiFi.status() == WL_CONNECTED) {
String current_serverPath = "http://api.openweathermap.org/data/2.5/weather?q=" + city + "," + countryCode + "&units=" + units + "&APPID=" + API_Key;
Serial.println("Get longitude, latitude & timezone offset from openweathermap...\n");
strjsonBuffer = httpGETRequest(current_serverPath.c_str());
DeserializationError errorRoot = deserializeJson(root, strjsonBuffer);
if (errorRoot) {
Serial.println("parseObject() failed");
delay(500);
return;
}
String lon = root["coord"]["lon"];
String lat = root["coord"]["lat"];
timezone_offset = root["timezone"];
Serial.println();
Serial.print("Lon : ");
Serial.println(lon);
Serial.print("Lat : ");
Serial.println(lat);
Serial.print("Timezone offset : ");
Serial.println(timezone_offset);
Serial.println();
Serial.println("Set the Date and Time from the Internet...");
set_time_and_date();
// Get current weather data
String current_forecast_serverPath = "http://api.openweathermap.org/data/3.0/onecall?lat=" + lat + "&lon=" + lon + "&units=" + units + "&exclude=hourly&APPID=" + API_Key;
Serial.println("Get weather data from openweathermap...");
strjsonBufferCF = httpGETRequest(current_forecast_serverPath.c_str());
//Serial.println(strjsonBuffer);
DeserializationError errorRootCF = deserializeJson(rootCF, strjsonBufferCF);
// Test if parsing succeeds.
if (errorRootCF) {
Serial.println("parseObject() failed");
delay(500);
return;
}
String str_current_weather = rootCF["current"]["weather"][0]["main"];
current_weather = str_current_weather;
String str_current_weather_Description = rootCF["current"]["weather"][0]["description"];
current_weather_Description = str_current_weather_Description;
String str_current_weather_sym = rootCF["current"]["weather"][0]["icon"];
current_weather_sym = str_current_weather_sym;
current_temperature = rootCF["current"]["temp"];
current_feels_like = rootCF["current"]["feels_like"];
current_uv = rootCF["current"]["uvi"];
current_dew_point = rootCF["current"]["dew_point"];
current_pressure = rootCF["current"]["pressure"];
current_humidity = rootCF["current"]["humidity"];
current_visibility = rootCF["current"]["visibility"];
current_wind_speed = rootCF["current"]["wind_speed"];
current_wind_deg = rootCF["current"]["wind_deg"];
//----------------------------------------
// Get weather forecast data for the following days
String str_forecast_weather1 = rootCF["daily"][0]["weather"][0]["main"];
forecast_weather[0] = str_forecast_weather1;
String str_forecast_weather_sym1 = rootCF["daily"][0]["weather"][0]["icon"];
forecast_weather_sym[0] = str_forecast_weather_sym1;
forecast_temp_max[0] = rootCF["daily"][0]["temp"]["max"];
forecast_temp_min[0] = rootCF["daily"][0]["temp"]["min"];
String str_forecast_weather2 = rootCF["daily"][1]["weather"][0]["main"];
forecast_weather[1] = str_forecast_weather2;
String str_forecast_weather_sym2 = rootCF["daily"][1]["weather"][0]["icon"];
forecast_weather_sym[1] = str_forecast_weather_sym2;
forecast_temp_max[1] = rootCF["daily"][1]["temp"]["max"];
forecast_temp_min[1] = rootCF["daily"][1]["temp"]["min"];
String str_forecast_weather3 = rootCF["daily"][2]["weather"][0]["main"];
forecast_weather[2] = str_forecast_weather3;
String str_forecast_weather_sym3 = rootCF["daily"][2]["weather"][0]["icon"];
forecast_weather_sym[2] = str_forecast_weather_sym3;
forecast_temp_max[2] = rootCF["daily"][2]["temp"]["max"];
forecast_temp_min[2] = rootCF["daily"][2]["temp"]["min"];
String str_forecast_weather4 = rootCF["daily"][3]["weather"][0]["main"];
forecast_weather[3] = str_forecast_weather4;
String str_forecast_weather_sym4 = rootCF["daily"][3]["weather"][0]["icon"];
forecast_weather_sym[3] = str_forecast_weather_sym4;
forecast_temp_max[3] = rootCF["daily"][3]["temp"]["max"];
forecast_temp_min[3] = rootCF["daily"][3]["temp"]["min"];
//----------------------------------------
//----------------------------------------
Serial.println();
Serial.println("Current weather data");
Serial.print("weather : ");
Serial.println(current_weather);
Serial.print("weather description : ");
Serial.println(current_weather_Description);
Serial.print("weather symbol : ");
Serial.println(current_weather_sym);
Serial.print("temperature : ");
Serial.print(current_temperature);
Serial.println(" °C");
Serial.print("feels_like : ");
Serial.print(current_feels_like);
Serial.print(" °C");
Serial.print(" (");
Serial.print(round(current_feels_like));
Serial.print(" °C");
Serial.println(")");
Serial.print("UV : ");
Serial.print(current_uv);
Serial.print(" (");
Serial.print(round(current_uv));
Serial.println(")");
Serial.print("Dew point : ");
Serial.print(current_dew_point);
Serial.print(" °C");
Serial.print(" (");
Serial.print(round(current_dew_point));
Serial.print(" °C");
Serial.println(")");
Serial.print("pressure : ");
Serial.print(current_pressure);
Serial.println(" hPa");
Serial.print("humidity : ");
Serial.print(current_humidity);
Serial.println(" %");
Serial.print("visibility : ");
Serial.print(current_visibility);
Serial.print(" m");
Serial.print(" (");
float current_visibility_to_km = current_visibility / 1000;
Serial.print(current_visibility_to_km);
Serial.print(" km");
Serial.println(")");
Serial.print("wind_speed : ");
Serial.print(current_wind_speed);
Serial.println(" m/s");
Serial.print("wind_deg : ");
Serial.print(current_wind_deg);
Serial.println("°");
//----------------------------------------
//----------------------------------------
int wds[4] = { timeClient.getDay(), timeClient.getDay() + 1, timeClient.getDay() + 2, timeClient.getDay() + 3 };
for (int i = 0; i < 4; i++) {
if (wds[i] == 7) {
wds[i] = 0;
}
if (wds[i] == 8) {
wds[i] = 1;
}
if (wds[i] == 9) {
wds[i] = 2;
}
}
String wd;
//----------------------------------------
//----------------------------------------
wd = weekDays[wds[0]];
Serial.println();
Serial.print("Weather forecast data : ");
Serial.println(wd);
Serial.print("weather : ");
Serial.println(forecast_weather[0]);
Serial.print("weather_sym : ");
Serial.println(forecast_weather_sym[0]);
Serial.print("temp_max : ");
Serial.print(forecast_temp_max[0]);
Serial.print(" °C");
Serial.print(" (");
Serial.print(round(forecast_temp_max[0]));
Serial.print(" °C");
Serial.println(")");
Serial.print("temp_min : ");
Serial.print(forecast_temp_min[0]);
Serial.print(" °C");
Serial.print(" (");
Serial.print(round(forecast_temp_min[0]));
Serial.print(" °C");
Serial.println(")");
Serial.println();
wd = weekDays[wds[1]];
Serial.println();
Serial.print("Weather forecast data : ");
Serial.println(wd);
Serial.print("weather : ");
Serial.println(forecast_weather[1]);
Serial.print("weather_sym : ");
Serial.println(forecast_weather_sym[1]);
Serial.print("temp_max : ");
Serial.print(forecast_temp_max[1]);
Serial.print(" °C");
Serial.print(" (");
Serial.print(round(forecast_temp_max[1]));
Serial.print(" °C");
Serial.println(")");
Serial.print("temp_min : ");
Serial.print(forecast_temp_min[1]);
Serial.print(" °C");
Serial.print(" (");
Serial.print(round(forecast_temp_min[1]));
Serial.print(" °C");
Serial.println(")");
Serial.println();
wd = weekDays[wds[2]];
Serial.println();
Serial.print("Weather forecast data : ");
Serial.println(wd);
Serial.print("weather : ");
Serial.println(forecast_weather[2]);
Serial.print("weather_sym : ");
Serial.println(forecast_weather_sym[2]);
Serial.print("temp_max : ");
Serial.print(forecast_temp_max[2]);
Serial.print(" °C");
Serial.print(" (");
Serial.print(round(forecast_temp_max[2]));
Serial.print(" °C");
Serial.println(")");
Serial.print("temp_min : ");
Serial.print(forecast_temp_min[2]);
Serial.print(" °C");
Serial.print(" (");
Serial.print(round(forecast_temp_min[2]));
Serial.print(" °C");
Serial.println(")");
wd = weekDays[wds[3]];
Serial.println();
Serial.print("Weather forecast data : ");
Serial.println(wd);
Serial.print("weather : ");
Serial.println(forecast_weather[3]);
Serial.print("weather_sym : ");
Serial.println(forecast_weather_sym[3]);
Serial.print("temp_max : ");
Serial.print(forecast_temp_max[3]);
Serial.print(" °C");
Serial.print(" (");
Serial.print(round(forecast_temp_max[3]));
Serial.print(" °C");
Serial.println(")");
Serial.print("temp_min : ");
Serial.print(forecast_temp_min[3]);
Serial.print(" °C");
Serial.print(" (");
Serial.print(round(forecast_temp_min[3]));
Serial.print(" °C");
Serial.println(")");
Serial.println("--------------------");
Serial.println();
//----------------------------------------
Serial.println("Set the Date and Time again from the Internet...");
set_time_and_date();
} else {
Serial.println("WiFi Disconnected");
}
}
String httpGETRequest(const char* serverName) {
WiFiClient client;
HTTPClient http;
// Your IP address with path or Domain name with URL path
http.begin(client, serverName);
// Send HTTP POST request
int httpResponseCode = http.GET();
String payload = "{}";
if (httpResponseCode == 200) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
payload = http.getString();
} else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
display.clearDisplay(); //--> for Clearing the display
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 19);
display.println(" Failed to get");
display.setCursor(0, 28);
display.println(" weather data !");
display.setCursor(0, 37);
display.print(" HTTP Response: ");
display.println(httpResponseCode);
display.drawRect(0, 0, 128, 64, WHITE); //--> Display frame
display.display();
delay(5000);
}
// Free resources
http.end();
return payload;
}
void set_time_and_date() {
timeClient.setTimeOffset(timezone_offset);
// Send an HTTP GET request
timeClient.update();
epochTime = timeClient.getEpochTime();
currentHour = timeClient.getHours();
currentMinute = timeClient.getMinutes();
currentSecond = timeClient.getSeconds();
weekDay = weekDays[timeClient.getDay()];
//Get a time structure
struct tm* ptm = gmtime((time_t*)&epochTime);
monthDay = ptm->tm_mday;
currentMonth = ptm->tm_mon + 1;
currentMonthName = months[currentMonth - 1];
currentYear = ptm->tm_year + 1900;
currentYearforSet = currentYear - 2000;
// Set time manually to 13:55:30 Jan 1st 2014
// YOU CAN SET THE TIME FOR THIS EXAMPLE HERE
// tinfo.Year = currentYearforSet;
// tinfo.Month = currentMonth;
// tinfo.Day = monthDay;
// tinfo.Hour = currentHour;
// tinfo.Minute = currentMinute;
// tinfo.Second = currentSecond;
// // Convert time structure to timestamp
// initialt = makeTime(tinfo);
// // Set system time counter
// setTime(initialt);
Serial.println("Setting Date and Time from Internet is successful.");
}
// DISPLAYS
void display_current_datetime() {
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(4, 52); //--> (x position, y position)
display.println(_DateTime);
}
void display_current_weather_data() {
//----------------------------------------Weather icon selection conditions
if (current_weather == "Thunderstorm") {
display.drawBitmap(10, 5, Thunderstorm_Sym, 24, 24, WHITE); //--> display.drawBitmap(x position, y position, bitmap data, bitmap width, bitmap height, color);
} else if (current_weather == "Drizzle") {
display.drawBitmap(10, 5, Drizzle_Sym, 24, 24, WHITE); //--> display.drawBitmap(x position, y position, bitmap data, bitmap width, bitmap height, color);
} else if (current_weather == "Rain") {
display.drawBitmap(10, 5, Rain_Sym, 24, 24, WHITE); //--> display.drawBitmap(x position, y position, bitmap data, bitmap width, bitmap height, color);
} else if (current_weather == "Snow") {
display.drawBitmap(10, 5, Snow_Sym, 24, 24, WHITE); //--> display.drawBitmap(x position, y position, bitmap data, bitmap width, bitmap height, color);
} else if (current_weather == "Clear") {
if (current_weather_sym == "01d") {
display.drawBitmap(10, 5, Clear_Daylight_Sym, 24, 24, WHITE); //--> display.drawBitmap(x position, y position, bitmap data, bitmap width, bitmap height, color);
} else if (current_weather_sym == "01n") {
display.drawBitmap(10, 5, Clear_Night_Sym, 24, 24, WHITE); //--> display.drawBitmap(x position, y position, bitmap data, bitmap width, bitmap height, color);
}
} else if (current_weather == "Clouds") {
if (current_weather_sym == "02d") {
display.drawBitmap(10, 5, Clouds_Daylight_Sym, 24, 24, WHITE); //--> display.drawBitmap(x position, y position, bitmap data, bitmap width, bitmap height, color);
} else if (current_weather_sym == "02d") {
display.drawBitmap(10, 5, Clouds_Night_Sym, 24, 24, WHITE); //--> display.drawBitmap(x position, y position, bitmap data, bitmap width, bitmap height, color);
} else {
display.drawBitmap(10, 5, Cloudy_Sym, 24, 24, WHITE); //--> display.drawBitmap(x position, y position, bitmap data, bitmap width, bitmap height, color);
}
}
// for (int i = 0; i < 10; i++) {
// if (current_weather == mist[i]) {
// display.drawBitmap(10, 5, Mist_Sym, 24, 24, WHITE); //--> display.drawBitmap(x position, y position, bitmap data, bitmap width, bitmap height, color);
// }
// }
}
void display_weather_forecast_data() {
int forecast_X1[] = { 20, 90 };
int forecast_X2[] = { 17, 87 };
int forecast_X3[] = { 8, 79 };
int wds[4] = { timeClient.getDay(), timeClient.getDay() + 1, timeClient.getDay() + 2, timeClient.getDay() + 3 };
int round_forecast_temp_max[2];
int round_forecast_temp_min[2];
for (int i = 0; i < 4; i++) {
if (wds[i] == 7) {
wds[i] = 0;
}
if (wds[i] == 8) {
wds[i] = 1;
}
if (wds[i] == 9) {
wds[i] = 2;
}
}
String forecast_weather_Prcs[2];
String forecast_weather_sym_Prcs[2];
int wds_Prcs[2];
if (currentSecond > 45 && currentSecond < 51) {
forecast_weather_Prcs[0] = forecast_weather[0];
forecast_weather_Prcs[1] = forecast_weather[1];
forecast_weather_sym_Prcs[0] = forecast_weather_sym[0];
forecast_weather_sym_Prcs[1] = forecast_weather_sym[1];
wds_Prcs[0] = wds[0];
wds_Prcs[1] = wds[1];
round_forecast_temp_max[0] = round(forecast_temp_max[0]);
round_forecast_temp_min[0] = round(forecast_temp_min[0]);
round_forecast_temp_max[1] = round(forecast_temp_max[1]);
round_forecast_temp_min[1] = round(forecast_temp_min[1]);
} else {
forecast_weather_Prcs[0] = forecast_weather[2];
forecast_weather_Prcs[1] = forecast_weather[3];
forecast_weather_sym_Prcs[0] = forecast_weather_sym[2];
forecast_weather_sym_Prcs[1] = forecast_weather_sym[3];
wds_Prcs[0] = wds[2];
wds_Prcs[1] = wds[3];
round_forecast_temp_max[0] = round(forecast_temp_max[2]);
round_forecast_temp_min[0] = round(forecast_temp_min[2]);
round_forecast_temp_max[1] = round(forecast_temp_max[3]);
round_forecast_temp_min[1] = round(forecast_temp_min[3]);
}
String wd;
String WF, WSF;
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
//----------------------------------------Process data for display
for (int i = 0; i < 2; i++) {
wd = weekDays3Dgt[wds_Prcs[i]];
display.setCursor(forecast_X1[i], 0);
display.print(wd);
WF = forecast_weather_Prcs[i];
WSF = forecast_weather_sym_Prcs[i];
if (WF == "Thunderstorm") {
display.drawBitmap(forecast_X2[i], 9, Thunderstorm_Sym, 24, 24, WHITE); //--> display.drawBitmap(x position, y position, bitmap data, bitmap width, bitmap height, color);
} else if (WF == "Drizzle") {
display.drawBitmap(forecast_X2[i], 9, Drizzle_Sym, 24, 24, WHITE); //--> display.drawBitmap(x position, y position, bitmap data, bitmap width, bitmap height, color);
} else if (WF == "Rain") {
display.drawBitmap(forecast_X2[i], 9, Rain_Sym, 24, 24, WHITE); //--> display.drawBitmap(x position, y position, bitmap data, bitmap width, bitmap height, color);
} else if (WF == "Snow") {
display.drawBitmap(forecast_X2[i], 9, Snow_Sym, 24, 24, WHITE); //--> display.drawBitmap(x position, y position, bitmap data, bitmap width, bitmap height, color);
} else if (WF == "Clear") {
if (WSF == "01d") {
display.drawBitmap(forecast_X2[i], 9, Clear_Daylight_Sym, 24, 24, WHITE); //--> display.drawBitmap(x position, y position, bitmap data, bitmap width, bitmap height, color);
} else if (WSF == "01n") {
display.drawBitmap(forecast_X2[i], 9, Clear_Night_Sym, 24, 24, WHITE); //--> display.drawBitmap(x position, y position, bitmap data, bitmap width, bitmap height, color);
}
} else if (WF == "Clouds") {
if (WSF == "02d") {
display.drawBitmap(forecast_X2[i], 9, Clouds_Daylight_Sym, 24, 24, WHITE); //--> display.drawBitmap(x position, y position, bitmap data, bitmap width, bitmap height, color);
} else if (WSF == "02d") {
display.drawBitmap(forecast_X2[i], 9, Clouds_Night_Sym, 24, 24, WHITE); //--> display.drawBitmap(x position, y position, bitmap data, bitmap width, bitmap height, color);
} else {
display.drawBitmap(forecast_X2[i], 9, Cloudy_Sym, 24, 24, WHITE); //--> display.drawBitmap(x position, y position, bitmap data, bitmap width, bitmap height, color);
}
}
// for (int i = 0; i < 10; i++) {
// if (WF == mist[i]) {
// display.drawBitmap(forecast_X2[i], 9, Mist_Sym, 24, 24, WHITE); //--> display.drawBitmap(x position, y position, bitmap data, bitmap width, bitmap height, color);
// }
// }
String forecast_temp_max_min = String(round_forecast_temp_max[i]) + "/" + round_forecast_temp_min[i];
if (forecast_temp_max_min.length() == 6) {
forecast_X3[i] += 3;
} else if (forecast_temp_max_min.length() == 5) {
forecast_X3[i] += 6;
} else if (forecast_temp_max_min.length() == 4) {
forecast_X3[i] += 9;
} else if (forecast_temp_max_min.length() == 3) {
forecast_X3[i] += 12;
}
display.setCursor(forecast_X3[i], 36);
display.print(forecast_temp_max_min);
}
//----------------------------------------
display.drawRect(0, 47, 128, 17, WHITE); //--> Display frame
display_current_datetime();
display.display();
}
void display_weather_description() {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0); //--> (x position, y position)
display.println("Weather description :");
display.setCursor(0, 10); //--> (x position, y position)
display.println(current_weather_Description);
display.drawRect(0, 47, 128, 17, WHITE); //--> Display frame
display_current_datetime();
display.display();
}
void display_other_information_1() {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
int round_current_feels_like = round(current_feels_like);
String Show_current_feels_like = "Feels Like :" + String(round_current_feels_like);
display.setCursor(0, 0); //--> (x position, y position)
display.print(Show_current_feels_like);
display.print((char)247); //--> ASCII degree symbol
display.print("C");
int round_current_uv = round(current_uv);
String Show_current_uv = "UV :" + String(round_current_uv);
display.setCursor(0, 10); //--> (x position, y position)
display.println(Show_current_uv);
int round_current_dew_point = round(current_dew_point);
String Show_current_dew_point = "Dew Point :" + String(round_current_dew_point);
display.setCursor(0, 20); //--> (x position, y position)
display.print(Show_current_dew_point);
display.print((char)247); //--> ASCII degree symbol
display.print("C");
display.drawRect(0, 47, 128, 17, WHITE); //--> Display frame
display_current_datetime();
display.display();
}
void display_other_information_2() {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
String Show_current_pressure = "Pressure :" + String(current_pressure) + "hPa";
display.setCursor(0, 0); //--> (x position, y position)
display.println(Show_current_pressure);
float current_visibility_to_km = current_visibility / 1000;
String Show_current_visibility = "visibility :" + String(current_visibility_to_km) + "km";
display.setCursor(0, 10); //--> (x position, y position)
display.println(Show_current_visibility);
String Cardinal_Direction;
if (current_wind_deg > 347 || current_wind_deg < 12) {
Cardinal_Direction = "N";
} else if (current_wind_deg > 11 && current_wind_deg < 34) {
Cardinal_Direction = "NNE";
} else if (current_wind_deg > 33 && current_wind_deg < 57) {
Cardinal_Direction = "NE";
} else if (current_wind_deg > 56 && current_wind_deg < 79) {
Cardinal_Direction = "ENE";
} else if (current_wind_deg > 78 && current_wind_deg < 102) {
Cardinal_Direction = "E";
} else if (current_wind_deg > 101 && current_wind_deg < 124) {
Cardinal_Direction = "ESE";
} else if (current_wind_deg > 123 && current_wind_deg < 147) {
Cardinal_Direction = "SE";
} else if (current_wind_deg > 146 && current_wind_deg < 169) {
Cardinal_Direction = "SSE";
} else if (current_wind_deg > 168 && current_wind_deg < 192) {
Cardinal_Direction = "S";
} else if (current_wind_deg > 191 && current_wind_deg < 214) {
Cardinal_Direction = "SSW";
} else if (current_wind_deg > 213 && current_wind_deg < 237) {
Cardinal_Direction = "SW";
} else if (current_wind_deg > 236 && current_wind_deg < 259) {
Cardinal_Direction = "WSW";
} else if (current_wind_deg > 258 && current_wind_deg < 282) {
Cardinal_Direction = "W";
} else if (current_wind_deg > 281 && current_wind_deg < 304) {
Cardinal_Direction = "WNW";
} else if (current_wind_deg > 303 && current_wind_deg < 327) {
Cardinal_Direction = "NW";
} else if (current_wind_deg > 326 && current_wind_deg < 347) {
Cardinal_Direction = "NNW";
}
display.setCursor(0, 20); //--> (x position, y position)
display.print("Wind Degree :");
display.print(current_wind_deg);
display.print((char)247); //--> ASCII degree symbol
display.println(Cardinal_Direction);
display.drawRect(0, 47, 128, 17, WHITE); //--> Display frame
display_current_datetime();
display.display();
delay(10);
}