diff --git a/weather/Config.h b/weather/Config.h index 5963385..d0e458b 100644 --- a/weather/Config.h +++ b/weather/Config.h @@ -31,6 +31,9 @@ #define OPENWEATHER_SRV "api.openweathermap.org" #define OPENWEATHER_PORT 80 #define OPENWEATHER_API "your openweathermap api key" +#define OPENWEATHER_UNITS "metric" // "imperial" + +#define WEATHER_UNITS "C" // "F" #define WIFI_SSID "your wifi ssid" #define WIFI_PW "your wifi password" diff --git a/weather/Display.h b/weather/Display.h index f4d7232..20cbb25 100644 --- a/weather/Display.h +++ b/weather/Display.h @@ -298,7 +298,7 @@ void WeatherDisplay::DrawM5PaperInfo(int x, int y, int dx, int dy) canvas.setTextSize(3); DrawIcon(x + 35, y + 140, (uint16_t *) TEMPERATURE64x64); - canvas.drawString(String(myData.sht30Temperatur) + " C", x + 35, y + 210, 1); + canvas.drawString(String(myData.sht30Temperatur) + " " + (String)WEATHER_UNITS, x + 35, y + 210, 1); DrawIcon(x + 145, y + 140, (uint16_t *) HUMIDITY64x64); canvas.drawString(String(myData.sht30Humidity) + "%", x + 150, y + 210, 1); @@ -314,7 +314,7 @@ void WeatherDisplay::DrawHourly(int x, int y, int dx, int dy, Weather &weather, canvas.setTextSize(2); canvas.drawCentreString(getHourString(time) + ":00", x + dx / 2, y + 10, 1); - canvas.drawCentreString(String(temp) + " C", x + dx / 2, y + 30, 1); + canvas.drawCentreString(String(temp) + " " + WEATHER_UNITS, x + dx / 2, y + 30, 1); // canvas.drawCentreString(main, x + dx / 2, y + 70, 1); int iconX = x + dx / 2 - 32; @@ -431,9 +431,22 @@ void WeatherDisplay::Show() DrawHourly(x, 286, 116, 122, myData.weather, i); } + int min_tempC = -20; + int min_tempF = -10; + int max_tempC = 37; + int max_tempF = 100; + + int min_temp = min_tempC; + int max_temp = max_tempC; + + if (WEATHER_UNITS == "F") { + min_temp = min_tempF; + max_temp = max_tempF; + } + canvas.drawRect(15, 408, maxX - 30, 122, M5EPD_Canvas::G15); - DrawGraph( 15, 408, 232, 122, "Temperature (C)", 0, 7, -20, 30, myData.weather.forecastMaxTemp); - DrawGraph( 15, 408, 232, 122, "Temperature (C)", 0, 7, -20, 30, myData.weather.forecastMinTemp); + DrawGraph( 15, 408, 232, 122, "Temperature (" + (String)WEATHER_UNITS + ")", 0, 7, min_temp, max_temp, myData.weather.forecastMaxTemp); + DrawGraph( 15, 408, 232, 122, "Temperature (" + (String)WEATHER_UNITS + ")", 0, 7, min_temp, max_temp, myData.weather.forecastMinTemp); DrawGraph(247, 408, 232, 122, "Rain (mm)", 0, 7, 0, myData.weather.maxRain, myData.weather.forecastRain); DrawGraph(479, 408, 232, 122, "Humidity (%)", 0, 7, 0, 100, myData.weather.forecastHumidity); DrawGraph(711, 408, 232, 122, "Pressure (hPa)", 0, 7, 800, 1400, myData.weather.forecastPressure); diff --git a/weather/SHT30.h b/weather/SHT30.h index 7898759..937e7d1 100644 --- a/weather/SHT30.h +++ b/weather/SHT30.h @@ -27,7 +27,15 @@ bool GetSHT30Values(MyData &myData) { M5.SHT30.UpdateData(); if(M5.SHT30.GetError() == 0) { - myData.sht30Temperatur = (int) M5.SHT30.GetTemperature(); + String weatherUnits = (String)WEATHER_UNITS; + + if(weatherUnits == "C") { + myData.sht30Temperatur = (int) M5.SHT30.GetTemperature(); + } else if(weatherUnits == "F") { + float tempC = (float) M5.SHT30.GetTemperature(); + int tempF = (int)((tempC * 1.8) + 32); + myData.sht30Temperatur = tempF; + } myData.sht30Humidity = (int) M5.SHT30.GetRelHumidity(); return true; } diff --git a/weather/Utils.h b/weather/Utils.h index 65aa0bb..19716e9 100644 --- a/weather/Utils.h +++ b/weather/Utils.h @@ -33,9 +33,19 @@ String getRTCDateTimeString() M5.RTC.getDate(&date_struct); M5.RTC.getTime(&time_struct); - sprintf(buff,"%02d.%02d.%04d %02d:%02d:%02d", - date_struct.day, date_struct.mon, date_struct.year, - time_struct.hour, time_struct.min, time_struct.sec); + if (DATE_FORMAT == "MMDDYYYY") { + sprintf(buff,"%02d.%02d.%04d %02d:%02d:%02d", + date_struct.mon, date_struct.day, date_struct.year, + time_struct.hour, time_struct.min, time_struct.sec); + } else if (DATE_FORMAT == "YYYYMMDD") { + sprintf(buff,"%04d.%02d.%02d %02d:%02d:%02d", + date_struct.year, date_struct.mon, date_struct.day, + time_struct.hour, time_struct.min, time_struct.sec); + } else { + sprintf(buff,"%02d.%02d.%04d %02d:%02d:%02d", + date_struct.day, date_struct.mon, date_struct.year, + time_struct.hour, time_struct.min, time_struct.sec); + } return (String) buff; } @@ -68,8 +78,16 @@ String getRTCDateString() M5.RTC.getDate(&date_struct); - sprintf(buff,"%02d.%02d.%04d", - date_struct.day, date_struct.mon, date_struct.year); + if(DATE_FORMAT == "MMDDYYYY") { + sprintf(buff,"%02d.%02d.%04d", + date_struct.mon, date_struct.day, date_struct.year); + } else if (DATE_FORMAT == "YYYYMMDD") { + sprintf(buff,"%04d.%02d.%02d", + date_struct.year, date_struct.mon, date_struct.day); + } else { + sprintf(buff,"%02d.%02d.%04d", + date_struct.day, date_struct.mon, date_struct.year); + } return (String) buff; } @@ -92,10 +110,20 @@ String getRTCTimeString() String getDateTimeString(time_t rawtime) { char buff[32]; - + + if(DATE_FORMAT == "MMDDYYYY") { + sprintf(buff,"%02d.%02d.%04d %02d:%02d:%02d", + month(rawtime), day(rawtime), year(rawtime), + hour(rawtime), minute(rawtime), second(rawtime)); + } else if (DATE_FORMAT == "YYYYMMDD") { + sprintf(buff,"%04d.%02d.%02d %02d:%02d:%02d", + year(rawtime), month(rawtime), day(rawtime), + hour(rawtime), minute(rawtime), second(rawtime)); + } else { sprintf(buff,"%02d.%02d.%04d %02d:%02d:%02d", day(rawtime), month(rawtime), year(rawtime), hour(rawtime), minute(rawtime), second(rawtime)); + } return (String) buff; } @@ -104,9 +132,17 @@ String getDateTimeString(time_t rawtime) String getDateString(time_t rawtime) { char buff[32]; - - sprintf(buff,"%02d.%02d.%04d", + + if(DATE_FORMAT == "MMDDYYYY") { + sprintf(buff,"%02d.%02d.%04d", + month(rawtime), day(rawtime), year(rawtime)); + } else if(DATE_FORMAT == "YYYYMMDD") { + sprintf(buff,"%04d.%02d.%02d", + year(rawtime), month(rawtime), day(rawtime)); + } else { + sprintf(buff,"%02d.%02d.%04d", day(rawtime), month(rawtime), year(rawtime)); + } return (String) buff; } diff --git a/weather/Weather.h b/weather/Weather.h index c389edf..bde56b8 100644 --- a/weather/Weather.h +++ b/weather/Weather.h @@ -72,7 +72,8 @@ class Weather uri += "/data/2.5/onecall"; uri += "?lat=" + String((float) LATITUDE, 5); uri += "&lon=" + String((float) LONGITUDE, 5); - uri += "&units=metric&lang=en&exclude=minutely"; + uri += "&units=" + (String)OPENWEATHER_UNITS; + uri += "&lang=en&exclude=minutely"; uri += "&appid=" + (String) OPENWEATHER_API; client.stop(); @@ -114,14 +115,14 @@ class Weather JsonArray hourly_list = root["hourly"]; hourlyTime[0] = LocalTime(root["current"]["dt"].as()); hourlyMaxTemp[0] = root["current"]["temp"].as(); - hourlyMain[0] = root["current"]["weather"][0]["main"].as(); - hourlyIcon[0] = root["current"]["weather"][0]["icon"].as(); + hourlyMain[0] = root["current"]["weather"][0]["main"].as(); + hourlyIcon[0] = root["current"]["weather"][0]["icon"].as(); for (int i = 1; i < MAX_HOURLY; i++) { if (i < hourly_list.size()) { hourlyTime[i] = LocalTime(hourly_list[i - 1]["dt"].as()); hourlyMaxTemp[i] = hourly_list[i - 1]["temp"].as(); - hourlyMain[i] = hourly_list[i - 1]["weather"][0]["main"].as(); - hourlyIcon[i] = hourly_list[i - 1]["weather"][0]["icon"].as(); + hourlyMain[i] = hourly_list[i - 1]["weather"][0]["main"].as(); + hourlyIcon[i] = hourly_list[i - 1]["weather"][0]["icon"].as(); } }