buienradar (dutch rain predictions)

This commit is contained in:
Nic Limper
2023-05-28 01:37:28 +02:00
parent da095a2382
commit aaf4f94df7
4 changed files with 117 additions and 3 deletions

View File

@@ -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",

View File

@@ -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);

View File

@@ -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);

View File

@@ -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<int>() < 5 ? 5 : cfgobj["timetolive"].as<int>())* 60;
updateTagImage(filename, mac, (cfgobj["timetolive"].as<int>() < 5 ? 5 : cfgobj["timetolive"].as<int>()), taginfo, imageParams);
break;
}
taginfo->modeConfigJson = doc.as<String>();
}
@@ -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;