From aaf4f94df7002f32fe5850faba00ff7168731798 Mon Sep 17 00:00:00 2001 From: Nic Limper Date: Sun, 28 May 2023 01:37:28 +0200 Subject: [PATCH] buienradar (dutch rain predictions) --- ESP32_AP-Flasher/data/www/content_cards.json | 34 ++++++++ ESP32_AP-Flasher/data/www/ota.js | 2 +- ESP32_AP-Flasher/include/contentmanager.h | 1 + ESP32_AP-Flasher/src/contentmanager.cpp | 83 +++++++++++++++++++- 4 files changed, 117 insertions(+), 3 deletions(-) diff --git a/ESP32_AP-Flasher/data/www/content_cards.json b/ESP32_AP-Flasher/data/www/content_cards.json index 1f84f4e5..fd4ba76a 100644 --- a/ESP32_AP-Flasher/data/www/content_cards.json +++ b/ESP32_AP-Flasher/data/www/content_cards.json @@ -163,6 +163,40 @@ } ] }, + { + "id": 16, + "name": "Buienradar", + "desc": "Dutch rain predictions for the next two hours. Only works for Dutch locations.", + "hwtype": [ + 1 + ], + "param": [ + { + "key": "location", + "name": "Location", + "desc": "Name of the city. This is used to lookup the lat/long data, and to display as the title", + "type": "text" + }, + { + "key": "ttl", + "name": "Time To Live", + "desc": "How often (in minutes) should this be refreshed. Minimum is 5 minutes, but will shorten battery lifetime", + "type": "int" + }, + { + "key": "#lat", + "name": "Lat", + "desc": "Latitude (set automatic when generating image)", + "type": "ro" + }, + { + "key": "#lon", + "name": "Lon", + "desc": "Longitude (set automatic when generating image)", + "type": "ro" + } + ] + }, { "id": 9, "name": "RSS feed", diff --git a/ESP32_AP-Flasher/data/www/ota.js b/ESP32_AP-Flasher/data/www/ota.js index 06484658..d7d5425c 100644 --- a/ESP32_AP-Flasher/data/www/ota.js +++ b/ESP32_AP-Flasher/data/www/ota.js @@ -1,4 +1,4 @@ -const repoUrl = 'https://api.github.com/repos/jonasniesner/OpenEPaperLink/releases'; +const repoUrl = 'https://api.github.com/repos/nlimper/OpenEPaperLink/releases'; const $ = document.querySelector.bind(document); diff --git a/ESP32_AP-Flasher/include/contentmanager.h b/ESP32_AP-Flasher/include/contentmanager.h index 8de24db7..706b7c27 100644 --- a/ESP32_AP-Flasher/include/contentmanager.h +++ b/ESP32_AP-Flasher/include/contentmanager.h @@ -28,6 +28,7 @@ bool getImgURL(String &filename, String URL, time_t fetched, imgParam &imagePara bool getRssFeed(String &filename, String URL, String title, tagRecord *&taginfo, imgParam &imageParams); bool getCalFeed(String &filename, String URL, String title, tagRecord *&taginfo, imgParam &imageParams); void drawQR(String &filename, String qrcontent, String title, tagRecord *&taginfo, imgParam &imageParams); +void drawBuienradar(String &filename, JsonObject &cfgobj, tagRecord *&taginfo, imgParam &imageParams); char *formatHttpDate(time_t t); String urlEncode(const char *msg); int windSpeedToBeaufort(float windSpeed); diff --git a/ESP32_AP-Flasher/src/contentmanager.cpp b/ESP32_AP-Flasher/src/contentmanager.cpp index 37a3f6b0..48a7a689 100644 --- a/ESP32_AP-Flasher/src/contentmanager.cpp +++ b/ESP32_AP-Flasher/src/contentmanager.cpp @@ -261,7 +261,14 @@ void drawNew(uint8_t mac[8], bool buttonPressed, tagRecord *&taginfo) { prepareLUTreq(mac, cfgobj["bytes"]); taginfo->hasCustomLUT = true; break; - } + + case 16: // buienradar + + drawBuienradar(filename, cfgobj, taginfo, imageParams); + taginfo->nextupdate = now + (cfgobj["timetolive"].as() < 5 ? 5 : cfgobj["timetolive"].as())* 60; + updateTagImage(filename, mac, (cfgobj["timetolive"].as() < 5 ? 5 : cfgobj["timetolive"].as()), taginfo, imageParams); + break; + } taginfo->modeConfigJson = doc.as(); } @@ -920,7 +927,7 @@ bool getCalFeed(String &filename, String URL, String title, tagRecord *&taginfo, HTTPClient http; http.begin(URL); - http.setTimeout(10000); // timeout in ms + http.setTimeout(10000); http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS); int httpCode = http.GET(); if (httpCode != 200) { @@ -1069,6 +1076,78 @@ void drawQR(String &filename, String qrcontent, String title, tagRecord *&taginf #endif } +void drawBuienradar(String &filename, JsonObject &cfgobj, tagRecord *&taginfo, imgParam &imageParams) { + + wsLog("get weather"); + + getLocation(cfgobj); + HTTPClient http; + + String lat = cfgobj["#lat"]; + String lon = cfgobj["#lon"]; + http.begin("https://gps.buienradar.nl/getrr.php?lat=" + lat + "&lon=" + lon); + http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS); + http.setTimeout(5000); + int httpCode = http.GET(); + Serial.printf("Got code %d for Buienradar\n", httpCode); + + if (httpCode == 200) { + TFT_eSPI tft = TFT_eSPI(); + TFT_eSprite spr = TFT_eSprite(&tft); + U8g2_for_TFT_eSPI u8f; + u8f.begin(spr); + + tft.setTextWrap(false, false); + + String response = http.getString(); + + if (taginfo->hwType == SOLUM_29_SSD1619 || taginfo->hwType == SOLUM_29_UC8151) { + + initSprite(spr, 296, 128); + drawString(spr, cfgobj["location"], 5, 5, "fonts/bahnschrift30"); + + for (int i = 0; i < 295; i += 4) { + spr.drawPixel(i, 110, PAL_BLACK); + spr.drawPixel(i, 81, PAL_BLACK); + spr.drawPixel(i, 72, PAL_BLACK); + spr.drawPixel(i, 62, PAL_BLACK); + spr.drawPixel(i, 52, PAL_BLACK); + spr.drawPixel(i, 46, PAL_BLACK); + spr.drawPixel(i, 42, PAL_BLACK); + } + + u8f.setFont(u8g2_font_glasstown_nbp_tr); + u8f.setFontMode(0); + u8f.setFontDirection(0); + u8f.setForegroundColor(PAL_BLACK); + u8f.setBackgroundColor(PAL_WHITE); + u8f.setCursor(247, 11); + u8f.print("Buienradar"); + + for (int i = 0; i < 24; i++) { + int startPos = i * 11; + + uint8_t value = response.substring(startPos, startPos + 3).toInt(); + String timestring = response.substring(startPos + 4, startPos + 9); + int minutes = timestring.substring(3).toInt(); + if (value < 60) value = 60; + if (value > 170) value = 170; + + spr.fillRect(i * 12 + 5, 111 - (value - 60), 10, (value - 60), (value > 130 ? PAL_RED : PAL_BLACK)); + + spr.setTextFont(2); + spr.setTextColor(PAL_BLACK, PAL_WHITE); + u8f.setCursor(i * 12 + 1, 125); + if (minutes % 15 == 0) u8f.print(timestring); + } + } + spr2buffer(spr, filename, imageParams); + spr.deleteSprite(); + } + http.end(); + +} + char *formatHttpDate(time_t t) { static char buf[40]; struct tm *timeinfo;