From a0ebf0d255681a7304edee8d81c8145d7e56db4f Mon Sep 17 00:00:00 2001 From: Nic Limper Date: Mon, 21 Aug 2023 01:05:43 +0200 Subject: [PATCH] weather values in fahrenheit/mph --- ESP32_AP-Flasher/data/tagtypes/01.json | 2 +- ESP32_AP-Flasher/src/contentmanager.cpp | 42 +++++++++++++++------ ESP32_AP-Flasher/wwwroot/content_cards.json | 22 ++++++++++- 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/ESP32_AP-Flasher/data/tagtypes/01.json b/ESP32_AP-Flasher/data/tagtypes/01.json index 34546bf0..a6c64715 100644 --- a/ESP32_AP-Flasher/data/tagtypes/01.json +++ b/ESP32_AP-Flasher/data/tagtypes/01.json @@ -32,7 +32,7 @@ "wind": [280, 5, "fonts/bahnschrift30"], "temp": [5, 65, "fonts/bahnschrift70"], "icon": [285, 20, 70, 2], - "dir": [245, -12, 40], + "dir": [235, -12, 40], "umbrella": [190, -50, 25] }, "8": { diff --git a/ESP32_AP-Flasher/src/contentmanager.cpp b/ESP32_AP-Flasher/src/contentmanager.cpp index 34e2a188..b5686839 100644 --- a/ESP32_AP-Flasher/src/contentmanager.cpp +++ b/ESP32_AP-Flasher/src/contentmanager.cpp @@ -18,12 +18,11 @@ #include -#include "storage.h" - #include "U8g2_for_TFT_eSPI.h" #include "commstructs.h" #include "makeimage.h" #include "newproto.h" +#include "storage.h" #ifdef CONTENT_QR #include "qrcode.h" #endif @@ -638,21 +637,32 @@ void drawWeather(String &filename, JsonObject &cfgobj, const tagRecord *taginfo, const String lat = cfgobj["#lat"]; const String lon = cfgobj["#lon"]; const String tz = cfgobj["#tz"]; + String units = ""; + if (cfgobj["units"] == "1") { + units += "&temperature_unit=fahrenheit&windspeed_unit=mph"; + } StaticJsonDocument<1000> doc; - const bool success = util::httpGetJson("https://api.open-meteo.com/v1/forecast?latitude=" + lat + "&longitude=" + lon + "¤t_weather=true&windspeed_unit=ms&timezone=" + tz, doc, 5000); + const bool success = util::httpGetJson("https://api.open-meteo.com/v1/forecast?latitude=" + lat + "&longitude=" + lon + "¤t_weather=true&windspeed_unit=ms&timezone=" + tz + units, doc, 5000); if (!success) { return; } const auto ¤tWeather = doc["current_weather"]; const double temperature = currentWeather["temperature"].as(); - const int windspeed = currentWeather["windspeed"].as(); + float windspeed = currentWeather["windspeed"].as(); + int windval = 0; const int winddirection = currentWeather["winddirection"].as(); const bool isNight = currentWeather["is_day"].as() == 0; uint8_t weathercode = currentWeather["weathercode"].as(); if (weathercode > 40) weathercode -= 40; - const int beaufort = windSpeedToBeaufort(windspeed); + + const uint8_t beaufort = windSpeedToBeaufort(windspeed); + if (cfgobj["units"] != "1") { + windval = beaufort; + } else { + windval = int(windspeed); + } doc.clear(); @@ -664,10 +674,10 @@ void drawWeather(String &filename, JsonObject &cfgobj, const tagRecord *taginfo, "rain", "rain", "", "", "SNOW", "SNOW", "", "", "", "", "", "", "", "", "STRM", "HAIL", "", "", "HAIL"}; if (temperature < -9.9) { - sprintf(imageParams.segments, "%3d^%2d%-4.4s", static_cast(temperature), beaufort, weatherText[weathercode].c_str()); + sprintf(imageParams.segments, "%3d^%2d%-4.4s", static_cast(temperature), windval, weatherText[weathercode].c_str()); imageParams.symbols = 0x00; } else { - sprintf(imageParams.segments, "%3d^%2d%-4.4s", static_cast(temperature * 10), beaufort, weatherText[weathercode].c_str()); + sprintf(imageParams.segments, "%3d^%2d%-4.4s", static_cast(temperature * 10), windval, weatherText[weathercode].c_str()); imageParams.symbols = 0x04; } return; @@ -682,7 +692,7 @@ void drawWeather(String &filename, JsonObject &cfgobj, const tagRecord *taginfo, const auto &location = doc["location"]; drawString(spr, cfgobj["location"], location[0], location[1], location[2]); const auto &wind = doc["wind"]; - drawString(spr, String(beaufort), wind[0], wind[1], wind[2], TR_DATUM, (beaufort > 4 ? TFT_RED : TFT_BLACK)); + drawString(spr, String(windval), wind[0], wind[1], wind[2], TR_DATUM, (beaufort > 4 ? TFT_RED : TFT_BLACK)); char tmpOutput[5]; dtostrf(temperature, 2, 1, tmpOutput); @@ -712,9 +722,13 @@ void drawForecast(String &filename, JsonObject &cfgobj, const tagRecord *taginfo String lat = cfgobj["#lat"]; String lon = cfgobj["#lon"]; String tz = cfgobj["#tz"]; + String units = ""; + if (cfgobj["units"] == "1") { + units += "&temperature_unit=fahrenheit&windspeed_unit=mph"; + } DynamicJsonDocument doc(2000); - const bool success = util::httpGetJson("https://api.open-meteo.com/v1/forecast?latitude=" + lat + "&longitude=" + lon + "&daily=weathercode,temperature_2m_max,temperature_2m_min,precipitation_sum,windspeed_10m_max,winddirection_10m_dominant&windspeed_unit=ms&timeformat=unixtime&timezone=" + tz, doc, 5000); + const bool success = util::httpGetJson("https://api.open-meteo.com/v1/forecast?latitude=" + lat + "&longitude=" + lon + "&daily=weathercode,temperature_2m_max,temperature_2m_min,precipitation_sum,windspeed_10m_max,winddirection_10m_dominant&windspeed_unit=ms&timeformat=unixtime&timezone=" + tz + units, doc, 5000); if (!success) { return; } @@ -750,7 +764,13 @@ void drawForecast(String &filename, JsonObject &cfgobj, const tagRecord *taginfo const int8_t tmin = round(daily["temperature_2m_min"][dag].as()); const int8_t tmax = round(daily["temperature_2m_max"][dag].as()); - const uint8_t wind = windSpeedToBeaufort(daily["windspeed_10m_max"][dag].as()); + uint8_t wind; + const int8_t beaufort = windSpeedToBeaufort(daily["windspeed_10m_max"][dag].as()); + if (cfgobj["units"] == "1") { + wind = daily["windspeed_10m_max"][dag].as(); + } else { + wind = beaufort; + } spr.loadFont(day[2], *contentFS); @@ -763,7 +783,7 @@ void drawForecast(String &filename, JsonObject &cfgobj, const tagRecord *taginfo drawString(spr, String(tmin) + " ", dag * column1 + day[0].as(), day[4], "", TR_DATUM, (tmin < 0 ? TFT_RED : TFT_BLACK)); drawString(spr, String(" ") + String(tmax), dag * column1 + day[0].as(), day[4], "", TL_DATUM, (tmax < 0 ? TFT_RED : TFT_BLACK)); - drawString(spr, String(" ") + String(wind), dag * column1 + day[0].as(), day[3], "", TL_DATUM, (wind > 5 ? TFT_RED : TFT_BLACK)); + drawString(spr, String(wind), dag * column1 + column1 - 10, day[3], "", TR_DATUM, (beaufort > 5 ? TFT_RED : TFT_BLACK)); spr.unloadFont(); if (dag > 0) { for (int i = loc["line"][0]; i < loc["line"][1]; i += 3) { diff --git a/ESP32_AP-Flasher/wwwroot/content_cards.json b/ESP32_AP-Flasher/wwwroot/content_cards.json index fbe34409..c535572f 100644 --- a/ESP32_AP-Flasher/wwwroot/content_cards.json +++ b/ESP32_AP-Flasher/wwwroot/content_cards.json @@ -153,6 +153,16 @@ "name": "Lon", "desc": "Longitude (set automatic when generating image)", "type": "ro" + }, + { + "key": "units", + "name": "Units", + "desc": "Celcius or Fahrenheit?", + "type": "select", + "options": { + "0": "-Celcius / Beaufort / millimeters", + "1": "Fahrenheit / mph / millimeters" + } } ] }, @@ -185,6 +195,16 @@ "name": "Lon", "desc": "Longitude (set automatic when generating image)", "type": "ro" + }, + { + "key": "units", + "name": "Units", + "desc": "Celcius or Fahrenheit?", + "type": "select", + "options": { + "0": "-Celcius / Beaufort / millimeters", + "1": "Fahrenheit / mph / millimeters" + } } ] }, @@ -609,7 +629,7 @@ }, { "id": 21, - "name": "Display access point info", + "name": "Access point info", "desc": "Displays information about the currently connected access point", "hwtype": [0, 1] }