Blinking ESP32S3-8048S070 display + errorGuru Meditation Error

I have built a weather station and it can work for days without any problems, but from one moment to the next the display starts to shine (i have a video).Whatever I do, this will continue to be the case. After turning it off for a while (sometimes an hour, sometimes several hours) everything works again for a while.
error code:
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.

Core 1 register dump:
PC : 0x400556c0 PS : 0x00060d30 A0 : 0x8200c445 A1 : 0x3fcebd40
A2 : 0x00000016 A3 : 0x00000014 A4 : 0x000000ff A5 : 0x0000ff00
A6 : 0x00ff0000 A7 : 0xff000000 A8 : 0x82006c41 A9 : 0x3fcebd00
A10 : 0x00000000 A11 : 0x0000e100 A12 : 0x00000000 A13 : 0x3fc9ae58
A14 : 0x3d87d780 A15 : 0x0000001f SAR : 0x0000001d EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000014 LBEG : 0x40054bf0 LEND : 0x40054c0f LCOUNT : 0x00000000

Backtrace: 0x400556bd:0x3fcebd40 0x4200c442:0x3fcebd50 0x4200c461:0x3fcebd70 0x420043c5:0x3fcebd90 0x42005065:0x3fcebdb0 0x42005490:0x3fcebe60 0x4200efae:0x3fcebeb0

// Sketch for ESP32, ESP8266, RP2040 Pico W, RP2040 Nano Connect
// it will run on a "bare" board ans reports via Serial messages.

// It fetches the Weather Forecast from OpenWeather and is
// an example from the library here:
// https://github.com/Bodmer/OpenWeather

// Sign up for a key and read API configuration info here:
// https://openweathermap.org/

// You can change the "User_Setup.h" file inside the OpenWeather
// to shows the data stream from the server
//ESP32_Wroom_32  (30 pins)
//Setup_User (ILI9488)


// Choose library to load
#ifdef ESP8266
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#else // ESP32, Pico W, RP2040 Nano Connect
#include <WiFi.h>
#endif

#include <JSON_Decoder.h>
#include <OpenWeather.h>
// Just using this library for unix time conversion
#include <Time.h>

/******************************************************************************/
#include "gfx_conf.h"   //Please modify the setting of display driver according to the board you are using in gfx_conf.h.
/******************************************************************************/
#include "FS.h"
#include "SPIFFS.h"

LGFX lcd; //tbv display

//---------------------
// =====================================================
// ========= User configured stuff starts here =========
// Further configuration settings can be found in the
// OpenWeather library "User_Setup.h" file

#define TIME_OFFSET 1UL * 3600UL // UTC + 0 hour

// Change to suit your WiFi router
#define WIFI_SSID     "xxxx"
#define WIFI_PASSWORD "xxxxx"

// OpenWeather API Details, replace x's with your API key
String api_key = "xxxxxxxxx"; // Obtain this from your OpenWeather account

// Set both your longitude and latitude to at least 4 decimal places
String latitude =  "51.4416"; // 90.0000 to -90.0000 negative for Southern hemisphere
String longitude = "5.4697"; // 180.000 to -180.000 negative for West

String units = "metric";  // or "imperial"
String language = "nl";   // See notes tab

// =========  User configured stuff ends here  =========
// =====================================================

OW_Weather ow; // Weather forecast library instance
//------------------------------------------------------------

//FONTS
//https://oleddisplay.squix.ch/
#include "fonts/Luckiest_Guy_Regular_24.h"
#include "fonts/Dialog_plain_7.h"
#include "fonts/Dialog_plain_9.h"
#include "fonts/Dialog_plain_12.h"
#include "fonts/Dialog_plain_14.h"
#include "fonts/Dialog_plain_18.h"
#include "fonts/Dialog_plain_24.h"
#include "fonts/Dialog_bold_12.h"
#include "fonts/Dialog_bold_14.h"
#include "fonts/Dialog_bold_24.h"
#include "fonts/DialogInput_plain_32.h"
#include "fonts/Dialog_bold_32.h"
#include "fonts/Dialog_bold_40.h"
#include "fonts/Orbitron_Bold_32.h"

//-------------------------
  #define TFT_ORANGE      0xFDA0

 
void setup() {
  Serial.begin(115200);

//tbv display 7 inch
 //IO Pin
  pinMode(38, OUTPUT);
  digitalWrite(38, LOW);
  pinMode(17, OUTPUT);
  digitalWrite(17, LOW);
  pinMode(18, OUTPUT);
  digitalWrite(18, LOW);
  pinMode(42, OUTPUT);
  digitalWrite(42, LOW);

  // Init Display
  lcd.begin();
  lcd.fillScreen(TFT_BLACK);
 // lcd.setTextSize(2);
  delay(5000);
#ifdef TFT_BL
  pinMode(TFT_BL, OUTPUT);
  digitalWrite(TFT_BL, HIGH);
#endif

draw_all_panel_frames (); 

//---------------------------------------------------------------
 Serial.printf("\n\nConnecting to %s\n", WIFI_SSID);

  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println();
  Serial.print("Connected\n");

//---------------------------------------------------------------
SPIFFS.begin();
listFiles();

#ifdef FORMAT_SPIFFS
  tft.drawString("Formatting SPIFFS, so wait!", 120, 195); SPIFFS.format();
#endif

} //einde setup

void loop() {
lcd.fillScreen(TFT_BLACK);  
draw_all_panel_frames (); 


//Koptekst  
lcd.setFont(&Luckiest_Guy_Regular_24);
lcd.setCursor(70, 12);
lcd.setTextColor(TFT_CYAN);
lcd.printf("MEERDAAGSE ONLINE WEERSVERWACHTING EINDHOVEN");

lcd.setTextColor(TFT_YELLOW);
//lcd.printf(subT0);
lcd.setFont(0);
//---------------------------------------------------------

//drawBmp("/cloud_sky.bmp",25, 170);
//drawBmp("/cloudy.bmp",235, 60);
//drawBmp("/cloud.bmp",435, 60);


//-------------------------------------------------------------
  printForecast();
  // We can make 1000 requests a day
  delay(5 * 60 * 1000); // Every 5 minutes = 288 requests per day


}//einde loop


void draw_all_panel_frames ()
{//kaders
lcd.drawRect(5,5,790,40,TFT_GREEN); //rechthoek  / x,y begin, x,y eind , kleur
lcd.drawLine(265,105,265,475,TFT_GREEN);
lcd.drawLine(530,105,530,475,TFT_GREEN);
//lcd.drawLine(600,105,600,475,TFT_GREEN);
lcd.drawLine(5,105,795,105,TFT_GREEN);
}


//--------------------------------------
/***************************************************************************************
**                          Send weather info to serial port
***************************************************************************************/
void printForecast()
{

  // Create the structures that hold the retrieved weather
  OW_forecast  *forecast = new OW_forecast;

  Serial.print("\nRequesting weather information from OpenWeather... ");

  ow.getForecast(forecast, api_key, latitude, longitude, units, language);

  Serial.println("Weather from OpenWeather\n");

  Serial.print("city_name           : "); Serial.println(forecast->city_name);
  Serial.print("sunrise             : "); Serial.println(strTime(forecast->sunrise));
  Serial.print("sunset              : "); Serial.println(strTime(forecast->sunset));
  Serial.print("Latitude            : "); Serial.println(ow.lat);
  Serial.print("Longitude           : "); Serial.println(ow.lon);
  Serial.print("Timezone            : "); Serial.println(forecast->timezone);
  Serial.println();

  if (forecast)
  {
    Serial.println("###############  Forecast weather  ###############\n");
    for (int i = 0; i < (MAX_DAYS * 8); i++)
    {
      Serial.print("3 hourly forecast   "); if (i < 10) Serial.print(" "); Serial.print(i);
      Serial.println();
      Serial.print("dt (time)        : "); Serial.print(strTime(forecast->dt[i]));

      Serial.print("temp             : "); Serial.println(forecast->temp[i]);
      Serial.print("temp.min         : "); Serial.println(forecast->temp_min[i]);
      Serial.print("temp.max         : "); Serial.println(forecast->temp_max[i]);

      Serial.print("pressure         : "); Serial.println(forecast->pressure[i]);
      Serial.print("sea_level        : "); Serial.println(forecast->sea_level[i]);
      Serial.print("grnd_level       : "); Serial.println(forecast->grnd_level[i]);
      Serial.print("humidity         : "); Serial.println(forecast->humidity[i]);

      Serial.print("clouds           : "); Serial.println(forecast->clouds_all[i]);
      Serial.print("wind_speed       : "); Serial.println(forecast->wind_speed[i]);
      Serial.print("wind_deg         : "); Serial.println(forecast->wind_deg[i]);
      Serial.print("wind_gust        : "); Serial.println(forecast->wind_gust[i]);

      Serial.print("visibility       : "); Serial.println(forecast->visibility[i]);
      Serial.print("pop              : "); Serial.println(forecast->pop[i]);
      Serial.println();

      Serial.print("dt_txt           : "); Serial.println(forecast->dt_txt[i]);
      Serial.print("id               : "); Serial.println(forecast->id[i]);
      Serial.print("main             : "); Serial.println(forecast->main[i]);
      Serial.print("description      : "); Serial.println(forecast->description[i]);
      Serial.print("icon             : "); Serial.println(forecast->icon[i]);

      Serial.println();


//i=0
if (forecast->id[0])
{//begin i=0
 

  lcd.setTextColor(TFT_YELLOW);
  lcd.setCursor(25,50); //1e zijkant naar rechts, 2e bovenkant naar beneden
  String myString1 = strTime(forecast->dt[1]);
  String sub1 = myString1.substring(0, 3);

  if (sub1== "Sun"){sub1="Zondag";}
  if (sub1== "Mon"){sub1="Maandag";}
  if (sub1== "Tue"){sub1="Dinsdag";}
  if (sub1== "Wed"){sub1="Woensdag";}
  if (sub1== "Thu"){sub1="Donderdag";}
  if (sub1== "Fri"){sub1="Vrijdag";}
  if (sub1== "Sat"){sub1="Zaterdag";} 

  lcd.setCursor(30,115); 
  lcd.setFreeFont(&Dialog_bold_32);
  lcd.print(sub1);
//---------------------------------------------------------------

//tbv forecast tijd
  String myStringT1 = strTime(forecast->dt[1]);
  String subT1 = myStringT1.substring(11, 16); //tbv tijd forcast

  lcd.setFreeFont(&Dialog_bold_12);
  lcd.setCursor(75,155); 
  lcd.print(subT1);


  lcd.setFreeFont(&Orbitron_Bold_32);
  lcd.setTextColor(TFT_WHITE);
  lcd.setCursor(50,55); 
  lcd.print("Het is vandaag : ");

  String myString0 = strTime(forecast->dt[0]);
  String sub0 = myString0.substring(0, 3);

  if (sub0== "Sun"){sub0="Zondag";}
  if (sub0== "Mon"){sub0="Maandag";}
  if (sub0== "Tue"){sub0="Dinsdag";}
  if (sub0== "Wed"){sub0="Woensdag";}
  if (sub0== "Thu"){sub0="Donderdag";}
  if (sub0== "Fri"){sub0="Vrijdag";}
  if (sub0== "Sat"){sub0="Zaterdag";} 

//tbv 
  String myStringM0 = strTime(forecast->dt[0]);
  String subM0 = myStringM0.substring(4, 7); //tbv tijd forcast 

  String myStringD0 = strTime(forecast->dt[0]);
  String subD0 = myStringD0.substring(9, 11); //tbv tijd forcast 

  if (subM0== "Jan"){subM0="Januari";}
  if (subM0== "Feb"){subM0="Februari";}
  if (subM0== "Mar"){subM0="Maart";}
  if (subM0== "Apr"){subM0="April";}
  if (subM0== "May"){subM0="Mei";}
  if (subM0== "Jun"){subM0="Juni";}
  if (subM0== "Jul"){subM0="Juli";} 
  if (subM0== "Aug"){subM0="Augustus";}
  if (subM0== "Sep"){subM0="September";}
  if (subM0== "Oct"){subM0="Oktober";}
  if (subM0== "Nov"){subM0="November";}
  if (subM0== "Dec"){subM0="December";}

  lcd.print(sub0);
  lcd.printf(" ");
  lcd.print(subD0);
  lcd.printf(" ");
  lcd.print(subM0); 

 //--------------------------------------------
  lcd.setFreeFont(0);

//temp
  lcd.setFreeFont(&Dialog_bold_24);
  lcd.setCursor(30,340);
  lcd.setTextColor(TFT_WHITE);
  lcd.print("Temp");
  lcd.setTextColor(TFT_MAGENTA);
  lcd.setCursor(130,340);
  lcd.print(forecast->temp[1]);
   lcd.setCursor(30,370);
  lcd.setTextColor(TFT_WHITE);  
  lcd.print("Tmin");
  lcd.setTextColor(TFT_MAGENTA);
  lcd.setCursor(130,370);  
  lcd.println(forecast->temp_min[1]);
  lcd.setCursor(30,400);
  lcd.setTextColor(TFT_WHITE);  
  lcd.print("Tmax");
  lcd.setTextColor(TFT_MAGENTA);
  lcd.setCursor(130,400);  
  lcd.println(forecast->temp_max[1]);

//-------------------------------------------------
//Vocht
  lcd.setCursor(30,430);
  lcd.setTextColor(TFT_WHITE);  
  lcd.print("Vocht");
  lcd.setTextColor(TFT_MAGENTA);
  lcd.setCursor(140,430);
  lcd.print(forecast->humidity[1]);  
  lcd.print(" %");

//case tbv weer iconen

lcd.setTextColor(TFT_CYAN);
lcd.setFont(&Dialog_bold_14);
 switch(forecast->id[1]) {//begin case  i=0
   case 800: drawBmp("/summer.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Zonnig");  
  break;
  case 801: drawBmp("/cloud.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Licht bewolkt 11-25%"); 
  break;
  case 802: drawBmp("/cloud.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Licht bewolkt 25-50%"); 
  break;
  case 803: drawBmp("/cloudy.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Bewolkt 51-84% ");
  break;
  case 804: drawBmp("/cloudy.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Zwaar bewolkt 85-100%");
  break;
  
  case 200: drawBmp("/storm.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Onweer met lichte regen");
  break;
  case 201: drawBmp("/storm.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Onweer met regen");
  break;
  case 202: drawBmp("/storm.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Onweer met zware regen");
  break;
  case 210: drawBmp("/storm.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Lichte onweer");
  break;
  case 211: drawBmp("/storm.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Onweer");
  break;
  case 212: drawBmp("/storm.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Zware onweer");
  break;
  case 221: drawBmp("/storm.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Ruwe onweer");
  break;
  case 230: drawBmp("/storm.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Onweer met lichte motregen");
  break;
  case 231: drawBmp("/storm.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Onweer met motregen");
  break;
  case 232: drawBmp("/storm.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Onweer met zware motregen");
  break;

  case 300: drawBmp("/rain2.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Lichte motregen");
  break;
  case 301: drawBmp("/rain2.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Motregen");
  break;
  case 302: drawBmp("/rain2.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Hevige motregen");
  break;
  case 310: drawBmp("/rain2.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Lichte motregen/regen");
  break;
  case 311: drawBmp("/rain2.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Motregen/regen");
  break;
  case 312: drawBmp("/rain2.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Hevige motregen/regen");
  break;
  case 313: drawBmp("/rain2.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Regenbui en motregen");
  break;
  case 314: drawBmp("/rain2.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Zware regenbui en motregen");
  break;
  case 321: drawBmp("/rain2.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Zware regenbui");
  break;

  case 500: drawBmp("/rain.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Lichte regen"); 
  break;
  case 501: drawBmp("/rain.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Lichte regen");
  break;
  case 502: drawBmp("/rain.bmp",25, 170); 
  lcd.setCursor(35,310);
  lcd.print("Hevige regen");
  break;
  case 503: drawBmp("/storm.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Zeer hevige regen");
  break;
  case 504: drawBmp("/storm.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Extreme regen");
  break;
  case 511: drawBmp("/rain.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Ijskoude regen");
  break;
  case 520: drawBmp("/rain.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Lichte douche regen");
  break;
  case 521: drawBmp("/rain.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Douche regen");
  break;
  case 522: drawBmp("/rain.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Hevige douche regen");
  break;
  case 531: drawBmp("/rain.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Zware douche regen");
  break;
  case 600: drawBmp("/snow.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Lichte sneeuw");
  break;
  case 601: drawBmp("/snow.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Sneeuw");
  break;
  case 602: drawBmp("/snow.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Hevige sneeuw");
  break;
  case 611: drawBmp("/sleet.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Natte sneeuw");
  break;
  case 612: drawBmp("/sleet.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Lichte natte sneeuw");
  break;
  case 615: drawBmp("/sleet.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Lichte regen en sneeuw");
  break;
  case 616: drawBmp("/snow.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Regen en sneeuw");
  break;
  case 620: drawBmp("/snow.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Lichte sneeuw");
  break;
  case 621: drawBmp("/snow.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Lichte sneeuw");
  break;
  case 622: drawBmp("/snow.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Hevige sneeuw");
  break;

  case 701: drawBmp("/fog.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Mist");
  break;
  case 711: drawBmp("/fog.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Mist/nevel");
  break;
  case 721: drawBmp("/fog.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Nevel");
  break;
  case 731: drawBmp("/fog.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Zand/stofwervelingen");
  break;
  case 741: drawBmp("/fog.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Sluier mist");
  break;
  case 751: drawBmp("/fog.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Zand");
  break;
  case 761: drawBmp("/fog.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Stofwervelingen");
  break;
  case 762: drawBmp("/fog.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Vulkanisch as");
  break;
  case 771: drawBmp("/fog.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Rukwinden");
  break;
  case 781: drawBmp("/fog.bmp",25, 170);
  lcd.setCursor(35,310);
  lcd.print("Tornado");
  break;
  default:break; 
  lcd.setFont(0);
 } //eind case i=1

}//einde if i=1

//++++++++++++++++++++++++++++++++++++++++++++++++++
if (forecast->id[9])
{//begin i=9
//----------------

  lcd.setTextColor(TFT_YELLOW);
  String myString9 = strTime(forecast->dt[9]);
  String sub9 = myString9.substring(0, 3);

  if (sub9== "Sun"){sub9="Zondag";}
  if (sub9== "Mon"){sub9="Maandag";}
  if (sub9== "Tue"){sub9="Dinsdag";}
  if (sub9== "Wed"){sub9="Woensdag";}
  if (sub9== "Thu"){sub9="Donderdag";}
  if (sub9== "Fri"){sub9="Vrijdag";}
  if (sub9== "Sat"){sub9="Zaterdag";} 

  lcd.setCursor(295,115); 
  lcd.setFreeFont(&Dialog_bold_32);
  lcd.print(sub9);


//tbv forecast tijd
  String myStringT9 = strTime(forecast->dt[9]);
  String subT9 = myStringT9.substring(11, 16); //tbv tijd forcast

  lcd.setFreeFont(&Dialog_bold_12);
  lcd.setCursor(375,155); 
  lcd.print(subT9);
//------------

//temp
  lcd.setFreeFont(&Dialog_bold_24);
  lcd.setCursor(300,340);
  lcd.setTextColor(TFT_WHITE);
  lcd.print("Temp");
  lcd.setTextColor(TFT_MAGENTA);
  lcd.setCursor(400,340);
  lcd.print(forecast->temp[9]);
  lcd.setCursor(300,370);
  lcd.setTextColor(TFT_WHITE);  
  lcd.print("Tmin");
  lcd.setTextColor(TFT_MAGENTA);
  lcd.setCursor(400,370);  
  lcd.println(forecast->temp_min[9]);
  lcd.setCursor(300,400);
  lcd.setTextColor(TFT_WHITE);  
  lcd.print("Tmax");
  lcd.setTextColor(TFT_MAGENTA);
  lcd.setCursor(400,400);  
  lcd.println(forecast->temp_max[9]);

//-------------------------------------------------
//Vocht
  lcd.setCursor(300,430);
  lcd.setTextColor(TFT_WHITE);  
  lcd.print("Vocht");
  lcd.setTextColor(TFT_MAGENTA);
  lcd.setCursor(410,430);
  lcd.print(forecast->humidity[9]);  
  lcd.print(" %");


  lcd.setTextColor(TFT_CYAN);
  lcd.setFont(&Dialog_bold_12);

switch(forecast->id[9]) {//begin case  i=9
  case 800: drawBmp("/summer.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Zonnig");  
  break;
  case 801: drawBmp("/cloud.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Licht bewolkt 11-25%"); 
  break;
  case 802: drawBmp("/cloud.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Licht bewolkt 25-50%"); 
  break;
  case 803: drawBmp("/cloudy.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Bewolkt 51-84% ");
  break;
  case 804: drawBmp("/cloudy.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Zwaar bewolkt 85-100%");
  break;
  case 200: drawBmp("/storm.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Onweer met lichte regen");
  break;
  case 201: drawBmp("/storm.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Onweer met regen");
  break;
  case 202: drawBmp("/storm.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Onweer met zware regen");
  break;
  case 210: drawBmp("/storm.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Lichte onweer");
  break;
  case 211: drawBmp("/storm.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Onweer");
  break;
  case 212: drawBmp("/storm.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Zware onweer");
  break;
  case 221: drawBmp("/storm.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Ruwe onweer");
  break;
  case 230: drawBmp("/storm.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Onweer met lichte motregen");
  break;
  case 231: drawBmp("/storm.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Onweer met motregen");
  break;
  case 232: drawBmp("/storm.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Onweer met zware motregen");
  break;
  case 300: drawBmp("/rain2.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Lichte motregen");
  break;
  case 301: drawBmp("/rain2.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Motregen");
  break;
  case 302: drawBmp("/rain2.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Hevige motregen");
  break;
  case 310: drawBmp("/rain2.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Lichte motregen/regen");
  break;
  case 311: drawBmp("/rain2.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Motregen/regen");
  break;
  case 312: drawBmp("/rain2.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Hevige motregen/regen");
  break;
  case 313: drawBmp("/rain2.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Regenbui en motregen");
  break;
  case 314: drawBmp("/rain2.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Zware regenbui en motregen");
  break;
  case 321: drawBmp("/rain2.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Zware regenbui");
  break;
  case 500: drawBmp("/rain.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Lichte regen"); 
  break;
  case 501: drawBmp("/rain.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Lichte regen");
  break;
  case 502: drawBmp("/rain.bmp",320, 170); 
  lcd.setCursor(305,310);
  lcd.print("Hevige regen");
  break;
  case 503: drawBmp("/storm.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Zeer hevige regen");
  break;
  case 504: drawBmp("/storm.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Extreme regen");
  break;
  case 511: drawBmp("/rain.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Ijskoude regen");
  break;
  case 520: drawBmp("/rain.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Lichte douche regen");
  break;
  case 521: drawBmp("/rain.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Douche regen");
  break;
  case 522: drawBmp("/rain.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Hevige douche regen");
  break;
  case 531: drawBmp("/rain.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Zware douche regen");
  break;
  case 600: drawBmp("/snow.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Lichte sneeuw");
  break;
  case 601: drawBmp("/snow.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Sneeuw");
  break;
  case 602: drawBmp("/snow.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Hevige sneeuw");
  break;
  case 611: drawBmp("/sleet.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Natte sneeuw");
  break;
  case 612: drawBmp("/sleet.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Lichte natte sneeuw");
  break;
  case 615: drawBmp("/sleet.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Lichte regen en sneeuw");
  break;
  case 616: drawBmp("/snow.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Regen en sneeuw");
  break;
  case 620: drawBmp("/snow.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Lichte sneeuw");
  break;
  case 621: drawBmp("/snow.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Lichte sneeuw");
  break;
  case 622: drawBmp("/snow.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Hevige sneeuw");
  break;
  case 701: drawBmp("/fog.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Mist");
  break;
  case 711: drawBmp("/fog.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Mist/nevel");
  break;
  case 721: drawBmp("/fog.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Nevel");
  break;
  case 731: drawBmp("/fog.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Zand/stofwervelingen");
  break;
  case 741: drawBmp("/fog.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Sluier mist");
  break;
  case 751: drawBmp("/fog.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Zand");
  break;
  case 761: drawBmp("/fog.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Stofwervelingen");
  break;
  case 762: drawBmp("/fog.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Vulkanisch as");
  break;
  case 771: drawBmp("/fog.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Rukwinden");
  break;
  case 781: drawBmp("/fog.bmp",320, 170);
  lcd.setCursor(305,310);
  lcd.print("Tornado");
  break;
  default:break; 
  lcd.setFont(0);
 } //eind case i=9
}//einde if i=9


//+++++++++++++++++++++++++++++++++++

if (forecast->id[17])
{//begin i=17
//----------------

  lcd.setTextColor(TFT_YELLOW);
  String myString17 = strTime(forecast->dt[17]);
  String sub17 = myString17.substring(0, 3);

  if (sub17== "Sun"){sub17="Zondag";}
  if (sub17== "Mon"){sub17="Maandag";}
  if (sub17== "Tue"){sub17="Dinsdag";}
  if (sub17== "Wed"){sub17="Woensdag";}
  if (sub17== "Thu"){sub17="Donderdag";}
  if (sub17== "Fri"){sub17="Vrijdag";}
  if (sub17== "Sat"){sub17="Zaterdag";} 

  lcd.setCursor(560,115); 
  lcd.setFreeFont(&Dialog_bold_32);
  lcd.print(sub17);


//tbv forecast tijd
  String myStringT17 = strTime(forecast->dt[17]);
  String subT17 = myStringT17.substring(11, 16); //tbv tijd forcast

  lcd.setFreeFont(&Dialog_bold_12);
  lcd.setCursor(650,155); 
  lcd.print(subT17);
//------------

//temp
  lcd.setFreeFont(&Dialog_bold_24);
  lcd.setCursor(575,340);
  lcd.setTextColor(TFT_WHITE);
  lcd.print("Temp");
  lcd.setTextColor(TFT_MAGENTA);
  lcd.setCursor(675,340);
  lcd.print(forecast->temp[17]);
  lcd.setCursor(575,370);
  lcd.setTextColor(TFT_WHITE);  
  lcd.print("Tmin");
  lcd.setTextColor(TFT_MAGENTA);
  lcd.setCursor(675,370);  
  lcd.println(forecast->temp_min[17]);
  lcd.setCursor(575,400);
  lcd.setTextColor(TFT_WHITE);  
  lcd.print("Tmax");
  lcd.setTextColor(TFT_MAGENTA);
  lcd.setCursor(675,400);  
  lcd.println(forecast->temp_max[17]);

//-------------------------------------------------
//Vocht
  lcd.setCursor(575,430);
  lcd.setTextColor(TFT_WHITE);  
  lcd.print("Vocht");
  lcd.setTextColor(TFT_MAGENTA);
  lcd.setCursor(685,430);
  lcd.print(forecast->humidity[17]);  
  lcd.print(" %");

  lcd.setTextColor(TFT_CYAN);
  lcd.setFont(&Dialog_bold_12);

switch(forecast->id[17]) {//begin case  i=17
  case 800: drawBmp("/summer.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Zonnig");  
  break;
  case 801: drawBmp("/cloud.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Licht bewolkt 11-25%"); 
  break;
  case 802: drawBmp("/cloud.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Licht bewolkt 25-50%"); 
  break;
  case 803: drawBmp("/cloudy.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Bewolkt 51-84% ");
  break;
  case 804: drawBmp("/cloudy.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Zwaar bewolkt 85-100%");
  break;
  case 200: drawBmp("/storm.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Onweer met lichte regen");
  break;
  case 201: drawBmp("/storm.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Onweer met regen");
  break;
  case 202: drawBmp("/storm.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Onweer met zware regen");
  break;
  case 210: drawBmp("/storm.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Lichte onweer");
  break;
  case 211: drawBmp("/storm.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Onweer");
  break;
  case 212: drawBmp("/storm.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Zware onweer");
  break;
  case 221: drawBmp("/storm.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Ruwe onweer");
  break;
  case 230: drawBmp("/storm.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Onweer met lichte motregen");
  break;
  case 231: drawBmp("/storm.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Onweer met motregen");
  break;
  case 232: drawBmp("/storm.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Onweer met zware motregen");
  break;
  case 300: drawBmp("/rain2.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Lichte motregen");
  break;
  case 301: drawBmp("/rain2.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Motregen");
  break;
  case 302: drawBmp("/rain2.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Hevige motregen");
  break;
  case 310: drawBmp("/rain2.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Lichte motregen/regen");
  break;
  case 311: drawBmp("/rain2.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Motregen/regen");
  break;
  case 312: drawBmp("/rain2.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Hevige motregen/regen");
  break;
  case 313: drawBmp("/rain2.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Regenbui en motregen");
  break;
  case 314: drawBmp("/rain2.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Zware regenbui en motregen");
  break;
  case 321: drawBmp("/rain2.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Zware regenbui");
  break;
  case 500: drawBmp("/rain.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Lichte regen"); 
  break;
  case 501: drawBmp("/rain.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Lichte regen");
  break;
  case 502: drawBmp("/rain.bmp",595, 170); 
  lcd.setCursor(575,310);
  lcd.print("Hevige regen");
  break;
  case 503: drawBmp("/storm.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Zeer hevige regen");
  break;
  case 504: drawBmp("/storm.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Extreme regen");
  break;
  case 511: drawBmp("/rain.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Ijskoude regen");
  break;
  case 520: drawBmp("/rain.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Lichte douche regen");
  break;
  case 521: drawBmp("/rain.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Douche regen");
  break;
  case 522: drawBmp("/rain.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Hevige douche regen");
  break;
  case 531: drawBmp("/rain.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Zware douche regen");
  break;
  case 600: drawBmp("/snow.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Lichte sneeuw");
  break;
  case 601: drawBmp("/snow.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Sneeuw");
  break;
  case 602: drawBmp("/snow.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Hevige sneeuw");
  break;
  case 611: drawBmp("/sleet.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Natte sneeuw");
  break;
  case 612: drawBmp("/sleet.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Lichte natte sneeuw");
  break;
  case 615: drawBmp("/sleet.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Lichte regen en sneeuw");
  break;
  case 616: drawBmp("/snow.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Regen en sneeuw");
  break;
  case 620: drawBmp("/snow.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Lichte sneeuw");
  break;
  case 621: drawBmp("/snow.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Lichte sneeuw");
  break;
  case 622: drawBmp("/snow.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Hevige sneeuw");
  break;
  case 701: drawBmp("/fog.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Mist");
  break;
  case 711: drawBmp("/fog.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Mist/nevel");
  break;
  case 721: drawBmp("/fog.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Nevel");
  break;
  case 731: drawBmp("/fog.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Zand/stofwervelingen");
  break;
  case 741: drawBmp("/fog.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Sluier mist");
  break;
  case 751: drawBmp("/fog.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Zand");
  break;
  case 761: drawBmp("/fog.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Stofwervelingen");
  break;
  case 762: drawBmp("/fog.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Vulkanisch as");
  break;
  case 771: drawBmp("/fog.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Rukwinden");
  break;
  case 781: drawBmp("/fog.bmp",595, 170);
  lcd.setCursor(575,310);
  lcd.print("Tornado");
  break;
  default:break; 
  lcd.setFont(0);
 } //eind case i=17
}//einde if i=17







//-----------------------------------------------------------------      
    }
  }
  // Delete to free up space and prevent fragmentation as strings change in length
  delete forecast;
}//einde forecast



/***************************************************************************************
**                          Convert unix time to a time string
***************************************************************************************/
String strTime(time_t unixTime)
{
  unixTime += TIME_OFFSET;
  return ctime(&unixTime);
}
//--------------------------------------------------------------------------





//##################################################################################
//-----------------------------------------------
//declare draBmp
//------------------------------------------------------------------------
    void drawBmp(const char *filename, int16_t x, int16_t y) {


  if ((x >= lcd.width()) || (y >= lcd.height())) return;

  fs::File bmpFS;

  // Open requested file on SD card
  bmpFS = SPIFFS.open(filename, "r");

  if (!bmpFS)
  {
    Serial.print("File not found");
    return;
  }

  uint32_t seekOffset;
  uint16_t w, h, row, col;
  uint8_t  r, g, b;

  uint32_t startTime = millis();

  if (read16(bmpFS) == 0x4D42)
  {
    read32(bmpFS);
    read32(bmpFS);
    seekOffset = read32(bmpFS);
    read32(bmpFS);
    w = read32(bmpFS);
    h = read32(bmpFS);

    if ((read16(bmpFS) == 1) && (read16(bmpFS) == 24) && (read32(bmpFS) == 0))
    {
      y += h - 1;

      bool oldSwapBytes = lcd.getSwapBytes();
      lcd.setSwapBytes(true);
      bmpFS.seek(seekOffset);

      uint16_t padding = (4 - ((w * 3) & 3)) & 3;
      uint8_t lineBuffer[w * 3 + padding];

      for (row = 0; row < h; row++) {
        
        bmpFS.read(lineBuffer, sizeof(lineBuffer));
        uint8_t*  bptr = lineBuffer;
        uint16_t* tptr = (uint16_t*)lineBuffer;
        // Convert 24 to 16 bit colours
        for (uint16_t col = 0; col < w; col++)
        {
          b = *bptr++;
          g = *bptr++;
          r = *bptr++;
          *tptr++ = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
        }

        // Push the pixel row to screen, pushImage will crop the line if needed
        // y is decremented as the BMP image is drawn bottom up
        lcd.pushImage(x, y--, w, 1, (uint16_t*)lineBuffer);
      }
      lcd.setSwapBytes(oldSwapBytes);
     // Serial.print("Loaded in "); Serial.print(millis() - startTime);
     // Serial.println(" ms");
    }
    else Serial.println("BMP format not recognized.");
  }
  bmpFS.close();
}

// These read 16- and 32-bit types from the SD card file.
// BMP data is stored little-endian, Arduino is little-endian too.
// May need to reverse subscript order if porting elsewhere.

uint16_t read16(fs::File &f) {
  uint16_t result;
  ((uint8_t *)&result)[0] = f.read(); // LSB
  ((uint8_t *)&result)[1] = f.read(); // MSB
  return result;
}

uint32_t read32(fs::File &f) {
  uint32_t result;
  ((uint8_t *)&result)[0] = f.read(); // LSB
  ((uint8_t *)&result)[1] = f.read();
  ((uint8_t *)&result)[2] = f.read();
  ((uint8_t *)&result)[3] = f.read(); // MSB
  return result;
}
//-------------------------------------------------------





//==============tbv iconen
// -------------------------------------------------------------------------
// List SPIFFS files in a neat format for ESP8266 or ESP32
// -------------------------------------------------------------------------
void listFiles(void) {
  Serial.println();
  Serial.println("SPIFFS files found:");

#ifdef ESP32
  listDir(SPIFFS, "/", true);
#else
  fs::Dir dir = SPIFFS.openDir("/"); // Root directory
  String  line = "=====================================";

  Serial.println(line);
  Serial.println("  File name               Size");
  Serial.println(line);

  while (dir.next()) {
    String fileName = dir.fileName();
    Serial.print(fileName);
    // File path can be 31 characters maximum in SPIFFS
    int spaces = 33 - fileName.length(); // Tabulate nicely
    if (spaces < 1) spaces = 1;
    while (spaces--) Serial.print(" ");
    fs::File f = dir.openFile("r");
    Serial.print(f.size()); Serial.println(" bytes");
    yield();
  }

  Serial.println(line);
#endif
  Serial.println();
  delay(10000);
}

#ifdef ESP32
void listDir(fs::FS &fs, const char * dirname, uint8_t levels) {
  Serial.printf("Listing directory: %s\n", dirname);

  fs::File root = fs.open(dirname);
  if (!root) {
    Serial.println("Failed to open directory");
    return;
  }
  if (!root.isDirectory()) {
    Serial.println("Not a directory");
    return;
  }

  fs::File file = root.openNextFile();
  while (file) {

    if (file.isDirectory()) {
      Serial.print("DIR : ");
      String fileName = file.name();
      Serial.print(fileName);
      if (levels) {
        listDir(fs, file.name(), levels - 1);
      }
    } else {
      String fileName = file.name();
      Serial.print("  " + fileName);
      // File path can be 31 characters maximum in SPIFFS
      int spaces = 33 - fileName.length(); // Tabulate nicely
      if (spaces < 1) spaces = 1;
      while (spaces--) Serial.print(" ");
      String fileSize = (String) file.size();
      spaces = 8 - fileSize.length(); // Tabulate nicely
      if (spaces < 1) spaces = 1;
      while (spaces--) Serial.print(" ");
      Serial.println(fileSize + " bytes");
    }

    file = root.openNextFile();
  }
}
#endif
// Einde List SPIFFS

What is the problem and how can I counteract it?

Only the global objects expanding can cause fragmentation. So best practice if you use global String variables is, to start them out with a reserved space that you do not plan to exceed., using the .reserve() String member function.
All locally used Strings are destroyed when exiting the function.

Actually looking at your code i don't see why the forecast pointer needs to be declared dynamically, since it is only used locally anyway it will also be destroyed when exiting the function.

Regardless i guess you just do need to make sure that

  if (forecast)

is true before you

if (forecast->id[0])

so it makes more sense to do something like

  if (!forecast) {
    Serial.println("Forecast not found");
    return;
  }

to prevent the request for a member varible on an object that does not exist.

I am sorry, but i have 2 weather station build and have placed the wrong code.
This is the correct code.

//BIBLIOTHEN NIET UPDATEN

/*******************************************************************************
 ******************************************************************************/
#include <Arduino_GFX_Library.h>

#define GFX_BL DF_GFX_BL // default backlight pin, you may replace DF_GFX_BL to actual backlight pin
#define TFT_BL 2
/* More dev device declaration: https://github.com/moononournation/Arduino_GFX/wiki/Dev-Device-Declaration */
#if defined(DISPLAY_DEV_KIT)
Arduino_GFX *gfx = create_default_Arduino_GFX();
#else /* !defined(DISPLAY_DEV_KIT) */

/* More data bus class: https://github.com/moononournation/Arduino_GFX/wiki/Data-Bus-Class */
//Arduino_DataBus *bus = create_default_Arduino_DataBus();

/* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */
//Arduino_GFX *gfx = new Arduino_ILI9341(bus, DF_GFX_RST, 0 /* rotation */, false /* IPS */);

Arduino_ESP32RGBPanel *bus = new Arduino_ESP32RGBPanel(
    GFX_NOT_DEFINED /* CS */, GFX_NOT_DEFINED /* SCK */, GFX_NOT_DEFINED /* SDA */,
    41 /* DE */, 40 /* VSYNC */, 39 /* HSYNC */, 42 /* PCLK */,
    14 /* R0 */, 21 /* R1 */, 47 /* R2 */, 48 /* R3 */, 45 /* R4 */,
    9 /* G0 */, 46 /* G1 */, 3 /* G2 */, 8 /* G3 */, 16 /* G4 */, 1 /* G5 */,
    15 /* B0 */, 7 /* B1 */, 6 /* B2 */, 5 /* B3 */, 4 /* B4 */
);
// option 1:
// 7寸 50PIN 800*480
Arduino_RPi_DPI_RGBPanel *gfx = new Arduino_RPi_DPI_RGBPanel(
  bus,
//  800 /* width */, 0 /* hsync_polarity */, 8/* hsync_front_porch */, 2 /* hsync_pulse_width */, 43/* hsync_back_porch */,
//  480 /* height */, 0 /* vsync_polarity */, 8 /* vsync_front_porch */, 2/* vsync_pulse_width */, 12 /* vsync_back_porch */,
//  1 /* pclk_active_neg */, 16000000 /* prefer_speed */, true /* auto_flush */);

    800 /* width */, 0 /* hsync_polarity */, 210 /* hsync_front_porch */, 30 /* hsync_pulse_width */, 16 /* hsync_back_porch */,
    480 /* height */, 0 /* vsync_polarity */, 22 /* vsync_front_porch */, 13 /* vsync_pulse_width */, 10 /* vsync_back_porch */,
    1 /* pclk_active_neg */, 16000000 /* prefer_speed */, true /* auto_flush */);

#endif /* !defined(DISPLAY_DEV_KIT) */
/*******************************************************************************
 * End of Arduino_GFX setting
 ******************************************************************************/

//----------------
  #include <WiFi.h>
  #include <HTTPClient.h>   
  #include <WiFiClient.h>
  #include <Arduino_JSON.h>
//fonts declare  
//#include "FreeMono8pt7b.h"
/* more fonts at: https://github.com/moononournation/ArduinoFreeFontFile.git */
//https://oleddisplay.squix.ch/
//Kies lib version
//#include "Orbitron_Medium_12.h"
#include "fonts/Luckiest_Guy_Regular_18.h"
#include "fonts/Luckiest_Guy_Regular_24.h"
#include "fonts/Luckiest_Guy_Regular_26.h"
#include "fonts/Luckiest_Guy_Regular_28.h"
//#include "Montez_Regular_32.h"

#include "fonts/Dialog_plain_7.h"
#include "fonts/Dialog_plain_9.h"
#include "fonts/Dialog_plain_18.h"
#include "fonts/Dialog_plain_24.h"
#include "fonts/Dialog_bold_24.h"
#include "fonts/DialogInput_plain_32.h"
#include "fonts/Dialog_bold_32.h"
#include "fonts/Dialog_bold_40.h"

  #define SCALE0      0xC655                                                                   // accent color for unused rainbow scale segments                                   
  #define SCALE1      0x5DEE                                                                   // accent color for unused rainbow scale segments         
  #define SCALE2      0x10CE                                                                   // blue used as fill in baro panel
    
  #define GREEN2RED   4
  #define DEG2RAD 0.0174532925 

  const char* ssid = "xxxxx";                                                                  // your wifi SSID here
  const char* password = "xxxxx"; 
   String openWeatherMapApiKey = "xxx";                                    // your OpenWeatherMap APIkey here  
   String city = "Eindhoven";                                                                      // replace with your city's name
   String countryCode = "NL";                                                                   // replace with your country identification
   String jsonBuffer;
   String jsonDocument (1024); 

// THE DEFAULT TIMER IS SET TO 10 SECONDS FOR TESTING PURPOSES
// for a final application, check the API call limits per hour/minute to avoid getting blocked/banned
   unsigned long lastTime = 0;
// timer set to 10 minutes (600000)
   unsigned long timerDelay = 600000;                                                           // currently one initial call and then every ten minutes 
// set timer to 30 seconds (30000)                                                              // handy during the testing phase of your project
// unsigned long timerDelay = 30000;

//https://javl.github.io/image2cpp/
// 'OIP', 144x150px
const unsigned char epd_bitmap_OIP [] PROGMEM = {
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x3d, 0x80, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0xc0, 0x00, 0x00, 0xff, 0xe0, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x60, 0x00, 0x07, 0xe0, 0xf8, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x30, 0x00, 0x1f, 0x00, 
	0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x18, 0x00, 
	0x3c, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 
	0x8c, 0x00, 0x70, 0x1c, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x3f, 0xc7, 0x00, 0xc0, 0x06, 0x08, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x3f, 0xe1, 0x83, 0x80, 0x03, 0x04, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xf0, 0xe3, 0x00, 0x01, 0x06, 0x18, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x37, 0xf8, 0x7e, 0x00, 0x01, 0x82, 0x0c, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0xfe, 0x1e, 0x00, 0x00, 0x62, 0x06, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1b, 0xff, 0x0f, 0xe0, 0x00, 
	0x33, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1b, 0xff, 0x83, 
	0x9c, 0x00, 0x10, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 
	0xff, 0xc1, 0xc7, 0x00, 0x10, 0x61, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x0d, 0xff, 0xe0, 0xe1, 0x80, 0x00, 0x30, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x0c, 0xff, 0xf0, 0x60, 0x40, 0x00, 0x10, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0xff, 0xf8, 0x30, 0xe0, 0x00, 0x08, 0xe0, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x7f, 0xfc, 0x13, 0x00, 0x18, 0x08, 0xa0, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x3f, 0xfe, 0x1e, 0x00, 0x07, 0x08, 
	0xa0, 0x03, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4f, 0x9f, 0xff, 0x0c, 0x00, 
	0x01, 0xcc, 0x1f, 0xff, 0xc0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x8f, 0xff, 
	0x08, 0x1f, 0x00, 0x66, 0x00, 0x00, 0x1f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x30, 
	0xcf, 0xff, 0x00, 0x27, 0xe0, 0x22, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x03, 0x98, 0xc3, 0xff, 0x80, 0x0f, 0xf8, 0x32, 0x0e, 0x03, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x02, 0xfe, 0x61, 0xff, 0x80, 0x0d, 0xfe, 0x12, 0x01, 0x1f, 0xfe, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x30, 0xff, 0x80, 0x0f, 0xff, 0x92, 0xc0, 0xff, 0xfc, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x18, 0x3f, 0x80, 0xff, 0x8f, 0xc2, 0x80, 0x7f, 
	0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x1c, 0x0f, 0x81, 0xde, 0x0f, 0xbb, 
	0x00, 0x7f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xbf, 0xe7, 0x03, 0x80, 0x1f, 
	0x87, 0xf7, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0x05, 0x80, 
	0x00, 0x0f, 0xff, 0xf1, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 
	0x18, 0xc0, 0x00, 0x0f, 0xff, 0xf1, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x30, 0x5f, 0xe1, 0xb0, 0x00, 0x07, 0xff, 0xff, 0xc1, 0xdf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x3f, 0xe0, 0x01, 0x00, 0x00, 0x03, 0xef, 0xc0, 0xf1, 0xfc, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x20, 0xf8, 0x02, 0x00, 0x00, 0x01, 0xff, 0xa8, 0x1f, 0xf0, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x1f, 0x04, 0x00, 0x00, 0x00, 0x7d, 0x1c, 0x5f, 0xe0, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x03, 0xd8, 0x00, 0x00, 0x00, 0x02, 0x03, 
	0xbf, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x70, 0x00, 0x00, 0x00, 
	0x06, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x1c, 0x00, 
	0x00, 0x00, 0x0c, 0x48, 0x0f, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x3f, 0xfc, 
	0x06, 0x00, 0x00, 0x00, 0x18, 0x48, 0x08, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 
	0xe0, 0x07, 0x81, 0x80, 0x00, 0x00, 0x7b, 0xf8, 0x08, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x0f, 0x00, 0x00, 0xc0, 0xc0, 0x00, 0x00, 0xe0, 0x3d, 0x08, 0x18, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x7f, 0xf0, 0x00, 0x00, 0x30, 0x60, 0x00, 0x03, 0x80, 0x07, 0x18, 0x18, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x01, 0xfe, 0x0c, 0x30, 0x00, 0x0f, 0x00, 0x0b, 0xf8, 0x30, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0f, 0x03, 0x86, 0x10, 0x00, 0x3c, 0x00, 0x10, 
	0x30, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x38, 0x00, 0x63, 0x08, 0x00, 0xf0, 
	0x00, 0x00, 0x61, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x60, 0x00, 0x18, 0x8c, 
	0x07, 0x80, 0x00, 0x01, 0xc7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0xc0, 0x00, 
	0x0c, 0xc4, 0x10, 0x00, 0x00, 0x03, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x01, 
	0x80, 0x00, 0x02, 0x46, 0x00, 0x00, 0x00, 0x0c, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x04, 0x03, 0x00, 0x00, 0x01, 0x23, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x04, 0x06, 0x00, 0x00, 0x00, 0x93, 0xc1, 0x80, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x06, 0x04, 0x00, 0x00, 0x00, 0xd3, 0xec, 0x06, 0x18, 0x18, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x69, 0xf8, 0x38, 0x0f, 0xf8, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x18, 0x00, 0x00, 0x00, 0x29, 0xf9, 0xe0, 
	0x1d, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x18, 0x00, 0x00, 0x00, 0x15, 
	0xfe, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x30, 0x00, 0x00, 
	0x00, 0x0d, 0xfe, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x30, 
	0x00, 0x00, 0x00, 0x04, 0xff, 0x1f, 0x08, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x03, 0x60, 0x00, 0x00, 0x00, 0x06, 0xff, 0xfe, 0x0c, 0x00, 0x06, 0x40, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x03, 0x60, 0x00, 0x00, 0x00, 0x02, 0xff, 0xfe, 0x04, 0x00, 0xcc, 0x20, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x03, 0x60, 0x00, 0x00, 0x00, 0x01, 0xff, 0xfe, 0x04, 0x01, 0xf0, 0x10, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xff, 0xfe, 0x08, 0x06, 
	0x60, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xfe, 
	0x18, 0x0c, 0x40, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 
	0x3f, 0xfe, 0x1c, 0x70, 0x40, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 
	0x00, 0x00, 0x1f, 0xfe, 0x26, 0x40, 0x40, 0x60, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 
	0x00, 0x80, 0x00, 0x00, 0x0f, 0xfe, 0x21, 0xc0, 0xe5, 0xc0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x03, 0x80, 0x00, 0x80, 0x00, 0x00, 0x07, 0xfe, 0x40, 0x4f, 0x6f, 0x80, 0x40, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x03, 0x00, 0x00, 0x80, 0x00, 0x00, 0x03, 0x07, 0xff, 0xe8, 0x39, 0x80, 0x40, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x7f, 0xf8, 0x39, 0x80, 
	0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x80, 0x00, 0x00, 0x06, 0x00, 0x00, 0x98, 
	0x11, 0x80, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x80, 0x00, 0x00, 0x06, 0x00, 
	0x01, 0x80, 0x01, 0xb1, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x80, 0x00, 0x00, 
	0x0c, 0x00, 0x01, 0x00, 0x03, 0xbf, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x80, 
	0x00, 0x00, 0x18, 0x00, 0x02, 0x00, 0x07, 0xf7, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 
	0x00, 0xc0, 0x20, 0x00, 0x30, 0x00, 0x06, 0x00, 0x07, 0xf9, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x0e, 0x00, 0x00, 0xc0, 0x20, 0x00, 0x60, 0x00, 0x04, 0x00, 0x0f, 0xff, 0x20, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x0c, 0x00, 0x00, 0xc0, 0x40, 0x00, 0xc0, 0x00, 0x0e, 0x00, 0x1f, 0xfe, 0x20, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x40, 0x20, 0x03, 0x00, 0x00, 0x0f, 0x80, 0x3f, 0xff, 
	0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x40, 0x30, 0x1c, 0x00, 0x00, 0x19, 0xf1, 
	0xff, 0xff, 0xb0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x40, 0x07, 0xe0, 0x00, 0x00, 
	0x10, 0x3f, 0xff, 0xff, 0xb0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x60, 0x00, 0x00, 
	0x00, 0x00, 0x30, 0x3f, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x60, 
	0x00, 0x00, 0x00, 0x00, 0x30, 0x3f, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 
	0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x20, 0x7f, 0xff, 0xff, 0xb0, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x38, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x60, 0xff, 0xff, 0xff, 0xa0, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x30, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x60, 0xff, 0xf0, 0xff, 0x20, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x41, 0xff, 0x90, 0xfe, 
	0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0xc3, 0xff, 
	0x90, 0xfe, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 
	0xc7, 0xf9, 0x31, 0xfc, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x18, 0x00, 0x00, 
	0x00, 0x00, 0x8f, 0xf1, 0x33, 0xfc, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x1c, 
	0x00, 0x00, 0x00, 0x01, 0x8f, 0xf3, 0x37, 0xf8, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 
	0x00, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x9f, 0xf2, 0x37, 0xf8, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x60, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x01, 0x8f, 0xf2, 0x33, 0xf8, 0x40, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0xe0, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01, 0x8f, 0xf2, 0x31, 0xf8, 0xc0, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x01, 0x0f, 0xfa, 0x30, 0xf0, 
	0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x01, 0x07, 0xfe, 
	0x30, 0x70, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x03, 
	0x07, 0xfe, 0x30, 0x31, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x01, 0xc0, 0x00, 
	0x00, 0x03, 0x07, 0xfc, 0x10, 0x11, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 
	0xe0, 0x00, 0x00, 0x03, 0x07, 0xfc, 0x10, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 
	0x00, 0x00, 0xf0, 0x00, 0x00, 0x03, 0x07, 0xfe, 0x10, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 
	0x80, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x03, 0x07, 0xfe, 0x10, 0x03, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x03, 0x0d, 0xfe, 0x18, 0x06, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x02, 0x0d, 0xfe, 0x18, 0x06, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x02, 0x0c, 0xfe, 
	0x18, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x02, 
	0x1c, 0xfe, 0x08, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 
	0x00, 0x02, 0x1c, 0x7f, 0x08, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 
	0x01, 0xf0, 0x00, 0x02, 0x14, 0x7f, 0x8c, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x32, 0x7f, 0xc4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x02, 0x22, 0x3f, 0xe4, 0x60, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x02, 0x22, 0x3f, 0xbe, 0xc0, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x07, 0xc0, 0x02, 0x62, 0x3f, 0xcf, 0x80, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x30, 0x00, 0x03, 0xf0, 0x02, 0x62, 0x3f, 
	0xc7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0xfe, 0x02, 
	0xe2, 0x3f, 0xc2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 
	0x7f, 0x83, 0xe3, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x78, 0x00, 
	0x00, 0x00, 0x6f, 0xe3, 0xe1, 0x7f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xc6, 0x00, 0x1f, 
	0xc0, 0x00, 0x00, 0x00, 0xc1, 0xff, 0x61, 0x7f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 
	0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x3e, 0x61, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x06, 0x07, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x04, 0x61, 0xff, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x61, 0xfe, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x61, 0xfe, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 
	0x41, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 
	0x00, 0x00, 0x41, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 
	0x00, 0x0c, 0x00, 0x00, 0x43, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 
	0xe0, 0x00, 0x00, 0x18, 0x00, 0x00, 0x43, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 
	0x00, 0x07, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x47, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x08, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x30, 0x02, 0x00, 0x47, 0xf0, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x07, 0xc8, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x60, 0x02, 0x00, 0x4f, 0xf0, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x05, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x60, 0x02, 0x00, 0x4f, 0xf0, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x02, 0x00, 
	0x4f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 
	0x02, 0x00, 0x4f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x03, 0x00, 0x02, 0x00, 0x4f, 0xe8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x06, 0x00, 0x02, 0x00, 0x5f, 0xe8, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x02, 0x00, 0x5f, 0xe4, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x02, 0x00, 0x5f, 0xc6, 0x00, 0x00, 0x00, 0x00, 
	0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x02, 0x00, 0x5f, 0xc2, 0x00, 0x00, 
	0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x02, 0x00, 0x5f, 0xc3, 
	0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x02, 0x00, 
	0x1f, 0xc1, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 
	0x03, 0xff, 0xff, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x3f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 
	0x00, 0x00, 0x02, 0x00, 0x1f, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0x00, 
	0x00, 0x3f, 0xff, 0x00, 0x1e, 0x00, 0x1f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xfe, 
	0x00, 0x00, 0x03, 0xe0, 0x1f, 0xff, 0x80, 0x00, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x7f, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00
};

  int delayTime = 500;
                                                       
// joint variables
   float temp_01=10;
   float hum_01;
   int   hum_02; 
   int   press_02 = 960;                                                                        // necessary for initial dynamic baro panel
   float w_speed_01;
   float w_speed_02;
   float press_01;
   float weather_01;

// rainbow scale ring meter variables
   uint32_t runTime = -99999;                                                                   // time for next update
   int reading = 10;                                                                            // value to be displayed in circular scale
   int tesmod = 0;
   int r_gauge_pos_x = 420 ;              // these two variables govern the position  ====> Nieuwe pos tbv 7"
   int r_gauge_pos_y = 10;              // of the square + gauge on the display 
//org   int r_gauge_pos_x;                                                                           // these two variables govern the position
//org   int r_gauge_pos_y;                                                                           // of the square + gauge on the display
   int ringmeter_radius = 150;                                                                   // governs diameter of rainbow gauge
//org   int ringmeter_radius = 65;    
  char* ringlabel[] = {"","*C","%","mBar"};          
   

   
   
                                             // some custom labels
   float temp_rainbowgauge;  
   int t;    
                                                                                 // x-position of numeric in rainbow scale center                                                                 // governs position of numerical output rainbow scale

// small needle humidity meter 
   int   j;   
   float center_x1;                                                                             // center x of edge markers humidity gauge 
   float center_y1;                                                                             // center y of edge markers humidity gauge         
   int   radius_s = 135;                                                                         // for scale markers
   int   needle_length = 120;                                                                    // gauge needle length
   int   edgemarkerLength = 5;                                                                  // edge marker length               
   float edge_x1, edge_y1, edge_x1_out, edge_y1_out;   
   float angle_needle = 0;
   float needle_x, needle_y;                                                                        
   float needle_x_old, needle_y_old;
   float angle_circle = 0;
   int   pivot_x;                                                                               // pivot coordinates needle of small gauge hum panel
   int   pivot_y;

   int   static_num_panel_x;
   int   static_num_panel_y;
   int   baro_panel_x;
   int   baro_panel_y;
   float barval;   

   int   p1_x, p1_y, p1_x_old, p1_y_old;                                                        // barometer panel polygon points
   int   p2_x, p2_y, p2_x_old, p2_y_old;
   int   p3_x, p3_y, p3_x_old, p3_y_old;
   int   p4_x, p4_y, p4_x_old, p4_y_old;

   float compassPivot_x;                                                                        // wind compass direction pointer
   float compassPivot_y;  
   float c_x1, c_x2,c_x3, c_x4;
   float c_y1, c_y2,c_y3, c_y4;
   float c_x1_old,c_x2_old,c_x3_old, c_x4_old;
   float c_y1_old,c_y2_old,c_y3_old, c_y4_old;    
   float wind_dir_01;
   int   wind_dir_02;
   float compass_angle;
   int   compass_r = 22;
   char* sector [] = {"Noord", "Noord-Oost", "Oost", "Zuid-Oost", "Zuid", "Zuid-West", "West", "Noord-West"};                              // wind sector labels
   int   h; 


   float max_temp_today;                                                                        // mini max temp panel 
   float min_temp_today;
   int   minmax_panel_x; 
   int   minmax_panel_y; 
   int   t_meter_increase;
   int   t_meter_increase_old;


// TBV BEGIN POS KADERS
   int   kader_x;
   int   kader_y;
   //------------------------------------------------------------------------

void setup(void)
{
  //-------------------------------------------  
   Serial.begin(115200);

   WiFi.begin (ssid, password);

   Serial.println ("Connecting");
   while (WiFi.status() != WL_CONNECTED) {
     delay(5000);
     Serial.print(".");
   }
   Serial.println("");
   Serial.print("Connected to WiFi network with IP Address: ");
   Serial.println(WiFi.localIP());
 
   Serial.println("Timer set to 10 seconds (timerDelay variable), it will take 10 seconds before publishing the first reading.");

//---------------------------------------------
 
 
    gfx->begin();
    gfx->fillScreen(BLACK);

#ifdef TFT_BL
    pinMode(TFT_BL, OUTPUT);
    digitalWrite(TFT_BL, HIGH);
#endif

draw_all_panel_frames (); 
title_panel_text();
static_data_in_numeric_window ();
rainbowScaleMeter ();   
static_data_in_rainbow_panel ();
humidity_static ();
build_dynamic_baropanel ();                                                                  // to start dynamic baropanel
static_minmax_panel ();
compassGauge ();

   Serial.println ("First run to get data. Next update according to timerDelay");
   Serial.println ();  
   Serial.println ();
   run_the_weatherstation (); // we do this here once to get the station up and running. next update: see timerDelay


}

void loop()
{
   if ((millis() - lastTime) > timerDelay)                                                      // check WiFi connection status
      {
       if(WiFi.status()== WL_CONNECTED)
         {     
          run_the_weatherstation ();        
         }   
       else
         {
          Serial.println("WiFi Disconnected");
         }
         
         lastTime = millis();
      }
   delay(10000);
 
 
 gfx->drawBitmap(635, 325, epd_bitmap_OIP, 144, 150, CYAN); //x,y, naam, grote

}

// ######################################################################################
// #  functions section                                                                 # 
// ######################################################################################

// ######################################################################################
// #  static - draw all panel frames                                                    #
// ######################################################################################

void draw_all_panel_frames (){ 

 //  baro_panel_x = 162;
//   baro_panel_y = 156;
   baro_panel_x = 476;  //extra tbv positie
   baro_panel_y = 322; 
   minmax_panel_x = 242; 
   minmax_panel_y  = 478;
   kader_x = 3;
   kader_y = 3 ;

gfx->drawRoundRect(kader_x,   kader_y, 412,  38, 4, GREEN);                                      // title panel frame m TEXT KOP
gfx->drawRoundRect (  kader_x,  kader_y+40 , 412, 277, 4, GREEN);                                   // left upper big panel frame / VERZAMEL KADER

gfx->drawRoundRect (  kader_x+444,  kader_y, 335, 317, 4, GREEN);                                   // right upper big panel frame  // TEMP KADER VERZAMELRAINBOW => y= + 330


gfx->drawRoundRect (  3, 322,  154,  156, 4, GREEN);                           // extreme left lowerpanel frame    => kader WIND  y+????
gfx->drawRoundRect ( 161, 322,  154,  156, 4, GREEN);                         // left-of-middle lower panel frame       => HUM
gfx->drawRoundRect (minmax_panel_x+77, 322, 154,  156, 4, GREEN);                      // extreme right lower window e         
gfx->drawRoundRect (476, 322, 154,  156, 4, GREEN);                      // barpmeter         
              


}

// ######################################################################################
// # static data in the title panel                                                     #
// ######################################################################################
//https://github.com/moononournation/Arduino_GFX/blob/master/examples/HelloWorldGfxfont/HelloWorldGfxfont.ino
void title_panel_text(){
   gfx->setTextColor (CYAN,BLACK);
   gfx->setFont(&Luckiest_Guy_Regular_26);
   gfx->setCursor (kader_x+40,kader_y+28);
   gfx->print ("WEERONLINE EINDHOVEN");
}

// ######################################################################################
// # static data in the numeric panel                                                   #
// ######################################################################################

void static_data_in_numeric_window (){
    
   static_num_panel_x = 20;  //x org = 3  y org =3  (KADERS)    // all coordinates in this panel relative to these two
   static_num_panel_y = 35;  // org=+5

   gfx->setTextColor (YELLOW,BLACK);
   gfx->setFont(&Dialog_bold_32); 
   gfx->setCursor (static_num_panel_x,static_num_panel_y+45);   // basis postie laten staan
   gfx->print ("temp");
   gfx->setCursor (static_num_panel_x,static_num_panel_y+100);   //alles Y+10 ivm grote
   gfx->print ("druk");
   gfx->setCursor (static_num_panel_x,static_num_panel_y+155);
   gfx->print ("vocht");
   gfx->setCursor (static_num_panel_x,static_num_panel_y+210);
   gfx->print ("wind");
   gfx->setCursor (static_num_panel_x,static_num_panel_y+265);
   gfx->print ("richting");
   //gfx->setTextColor (YELLOW,BLACK);
   //gfx->setFreeFont(&FreeSans9pt7b); 
   gfx->setCursor (static_num_panel_x+310,static_num_panel_y+45); //Y+5  alles X+50 tbv opschuiven naar rechts
   gfx->print ("C"); 
   gfx->drawCircle(static_num_panel_x+300,static_num_panel_y+25,4,YELLOW);   // degree character
   gfx->drawCircle(static_num_panel_x+300,static_num_panel_y+25,5,YELLOW);   // char degree character -> werkt alleen bij GFX   // degree character
   gfx->setCursor (static_num_panel_x+300,static_num_panel_y+100); 
   gfx->print ("mB");
   gfx->setCursor (static_num_panel_x+300,static_num_panel_y+155);
   gfx->print ("%");
   gfx->setCursor (static_num_panel_x+300,static_num_panel_y+210);
   gfx->print ("m/s"); 
  gfx->setFont(0);
}

// ######################################################################################
// # static data in the rainbow scale panel                                             #
// ######################################################################################

 void static_data_in_rainbow_panel (){
   gfx->setFont(&Dialog_plain_18); 
   gfx->setCursor (r_gauge_pos_x+45,r_gauge_pos_y+15);  
   gfx->setTextColor (YELLOW);   
   gfx->print ("temp");                                                                      
   gfx->drawCircle(r_gauge_pos_x+310,r_gauge_pos_y+5,3,YELLOW);                    // degree character
   gfx->drawCircle(r_gauge_pos_x+310,r_gauge_pos_y+5,4,YELLOW);  
   gfx->setCursor (r_gauge_pos_x+320,r_gauge_pos_y+20);     
   gfx->print ("C");   
   gfx->setCursor (r_gauge_pos_x+145,r_gauge_pos_y+290);  
   gfx->setFont(&Dialog_plain_24);
   gfx->print ("0");
   gfx->setCursor (r_gauge_pos_x+230,r_gauge_pos_y+290);          // 50 is top rainbow scale temperature 
   gfx->print ("50");
   gfx->setFont(0);
}

// ######################################################################################
// #  wind compass - static part                                                        #
// ######################################################################################

void compassGauge (){

   compassPivot_x = 1;       // these coordinates determine the position of wind compass and everything in it  /positie aanpassin bij 7"
   compassPivot_y = 301;

   gfx->drawCircle ((compassPivot_x+80), (compassPivot_y+98), (compass_r+25), BLUE);             // outer circle compass   ===> centrum posistie van ringen   
   gfx->drawCircle ((compassPivot_x+80), (compassPivot_y+98), (compass_r+15), CYAN);              // inner circle compass - pointer fits in here
   gfx->setFont(&Dialog_plain_18); 
   gfx->setTextColor (WHITE, BLACK);
   gfx->setCursor ((compassPivot_x+73), (compassPivot_y+42));
   gfx->print ("N");
   gfx->setCursor ((compassPivot_x+75), (compassPivot_y+165));
   gfx->print ("Z");
   gfx->setCursor ((compassPivot_x+133), (compassPivot_y+105));
   gfx->print ("O");
   gfx->setCursor ((compassPivot_x+10), (compassPivot_y+105));
   gfx->print ("W"); 


   gfx->setFont(&Dialog_plain_9); 
   gfx->setCursor ((compassPivot_x+40), (compassPivot_y+60));
   gfx->print ("NW");
   gfx->setCursor ((compassPivot_x+110), (compassPivot_y+60));
   gfx->print ("NO");
   gfx->setCursor ((compassPivot_x+40), (compassPivot_y+140));
   gfx->print ("ZW");
   gfx->setCursor ((compassPivot_x+110), (compassPivot_y+140));
   gfx->print ("ZO");

   gfx->setCursor ((compassPivot_x+10), (compassPivot_y+40));
   gfx->setTextColor (YELLOW, BLACK);
   gfx->setFont(&Dialog_plain_18); 
   gfx->print ("wind");

   gfx->setFont(0); 
}



//------------------------------------------

// ######################################################################################
// #  wind compass - dynamic wind compass pointer                                       #
// ######################################################################################


void compassPointer (){       


  compassPivot_x = 40;       // these coordinates determine the position of wind compass and everything in it  /positie aanpassin bij 7"
  compassPivot_y = 360;


                                                   
   gfx->fillTriangle (c_x1_old,c_y1_old,c_x2_old,c_y2_old,c_x4_old,c_y4_old,BLACK);          // remove old compass pointer by overwritig in white
   gfx->fillTriangle (c_x1_old,c_y1_old,c_x3_old,c_y3_old,c_x4_old,c_y4_old,BLACK);          // remove old compass pointer by overwritig in white
  
   compass_angle = ((wind_dir_02-90)*DEG2RAD);                                        

   c_x1 = ((compassPivot_x+40) + (compass_r * cos (compass_angle)));                         // calculate coordinates compass pointer tip 
   c_y1 = ((compassPivot_y+40) + (compass_r * sin (compass_angle)));                       

   c_x2 = ((compassPivot_x+40) + (compass_r * cos (compass_angle + 163*DEG2RAD)));           // calculate coordinates compass pointer base point
   c_y2 = ((compassPivot_y+40) + (compass_r * sin (compass_angle + 163*DEG2RAD)));                       

   c_x3 = ((compassPivot_x+40) + (compass_r * cos (compass_angle - 163*DEG2RAD)));           // calculate coordinates compass pointer base point
   c_y3 = ((compassPivot_y+40) + (compass_r * sin (compass_angle - 163*DEG2RAD)));                       

   c_x4 = ((compassPivot_x+40) + ((compass_r-4) * cos (compass_angle - 180*DEG2RAD)));       // calculate coordinates compass pointer base point
   c_y4 = ((compassPivot_y+40) + ((compass_r-4) * sin (compass_angle - 180*DEG2RAD)));                 

   c_x1_old = c_x1; c_x2_old = c_x2; c_x3_old = c_x3;   c_x4_old = c_x4;
   c_y1_old = c_y1; c_y2_old = c_y2; c_y3_old = c_y3;   c_y4_old = c_y4;
   
   gfx->fillTriangle (c_x1, c_y1,c_x3, c_y3, c_x4, c_y4, 0x3A72);                            // print the new pointer to display                              
   gfx->fillTriangle (c_x1, c_y1,c_x2, c_y2, c_x4, c_y4, CYAN);                              // print the new pointer to display

   
/*
tft.fillTriangle (c_x2, c_y2 ,c_x3, c_y3-20, c_x4, c_y4, CYAN);
2=rechterhoek, 3=top  4 = linkerhoek
Parameters:
x0:x coordinate of the apex
y0:y coordinate of the apex
x1:x coordinate of the bottom left point
y1:y coordinate of the bottom left point
x2:x coordinate of the bottom right point
y2:y coordinate of the bottom right point
color:the color of the triangle

        1
      *  *
     **  **
    * *  * * 
   *  *  *  *
  * *   4  * *
 * *        * * 
* *          * *
3               2


*/
}


// ######################################################################################
// #  wind sector calculator                                                            #
// ######################################################################################

void windSectorReporter (){

   h = 0;
   if (wind_dir_02 <22.5) h = 0;
   if (wind_dir_02> 22.5) h = 1; 
   if (wind_dir_02> 67.5) h = 2;
   if (wind_dir_02>112.5) h = 3;
   if (wind_dir_02>157.5) h = 4;  
   if (wind_dir_02>202.5) h = 5;
   if (wind_dir_02>247.5) h = 6;
   if (wind_dir_02>292.5) h = 7; 
   if (wind_dir_02>337.5) h = 8; 

}


// ######################################################################################
// #  humidity needle meter panel - static part                                         #       // in right-of-middle lower window
// ######################################################################################

void humidity_static (){

// these four coordinates determine everything in the humidity meter panel 
   pivot_x   = 167;             // pivot coordinates needle of humidity meter -// pivot coordinates needle of small gauge  -> punt begin lijn
   pivot_y   = 468;       //165
   center_x1 = 164;                                                                              // center x of edge markers humidity gauge - different from pivot needle!
   center_y1 = 470;   
   needle_x_old = pivot_x;                                                                      // remember
   needle_y_old = pivot_y;                                                                      // remember

  gfx->setFont(&Dialog_plain_18);  
  gfx->setTextColor (YELLOW, BLACK); 
  gfx->setCursor ((pivot_x+65), (pivot_y-128));                                                  // display percent sign in  small gauge scale
  gfx->print ("% vocht");
  gfx->fillCircle (pivot_x+2, pivot_y, 4, MAGENTA);           // pivot needle middle small gauge                                                                         // arbitrary seeding temp - avoids drawing black line from position 0.0
 // gfx->setFont(&Dialog_plain_9); 
  gfx->setTextColor (WHITE, BLACK);  
  gfx->setCursor ((pivot_x),(pivot_y-110));   
  gfx->print ("100");    
  gfx->setCursor ((pivot_x+100),(pivot_y-10));                        
  gfx->print ("40");                                                                            // scale starts with 40% and ends with 100%


  j = 270;                                                                                     // start point of cirle segment
    do {
       angle_circle = (j* DEG2RAD);                                                             // angle expressed in radians - 1 degree = 0,01745331 radians      

       edge_x1 = (center_x1+4 + (radius_s*cos (angle_circle)));                                 // scale - note the 4 pixels offset in x      
       edge_y1 = (center_y1 + (radius_s*sin (angle_circle)));                                   // scale
         
       edge_x1_out = (center_x1+4 + ((radius_s+edgemarkerLength)*cos (angle_circle)));          // scale - note the 4 pixels offset in x   
       edge_y1_out = (center_y1 + ((radius_s+edgemarkerLength)*sin (angle_circle)));            // scale
        
       gfx->drawLine (edge_x1, edge_y1, edge_x1_out, edge_y1_out,MAGENTA); 
       j = j+6; 
   } 
   while (j<356);   
//extra ivm extra weergave
  j = 270;                                                                                     // start point of cirle segment
    do {
       angle_circle = (j* DEG2RAD);                                                             // angle expressed in radians - 1 degree = 0,01745331 radians      

       edge_x1 = (center_x1+4 + (radius_s*cos (angle_circle)));                                 // scale - note the 4 pixels offset in x      
       edge_y1 = (center_y1 + (radius_s*sin (angle_circle)));                                   // scale
         
       edge_x1_out = (center_x1+5 + ((radius_s+edgemarkerLength)*cos (angle_circle)));          // scale - note the 4 pixels offset in x   
       edge_y1_out = (center_y1+1 + ((radius_s+edgemarkerLength)*sin (angle_circle)));            // scale
       
        
       gfx->drawLine (edge_x1+1, edge_y1, edge_x1_out, edge_y1_out,CYAN); //MAGENTA


       j = j+6; 
   } 
   while (j<356); 
     
  gfx->setFont(0); 
//-----------------------------      
   
                                                                               // end of circle segment
}
// ######################################################################################
// #   humidity needle meter - dynamic part = needle movement control                   #
// ######################################################################################

void needle_meter (){                                                                         
          
   gfx->drawLine (pivot_x, pivot_y, needle_x_old, needle_y_old, 0);                              // remove old needle by overwritig in BLACK

   angle_needle = (420*DEG2RAD - 1.5*hum_02*DEG2RAD);                                           // contains a 1.5 stretch factor to expand 60 percentage points over 90 degrees of scale

   if (angle_needle > 6.28) angle_needle = 6.28;                                                // prevents the needle from ducking below horizontal    
   needle_x = (pivot_x + ((needle_length)*cos (angle_needle)));                                 // calculate x coordinate needle point
   needle_y = (pivot_y + ((needle_length)*sin (angle_needle)));                                 // calculate y coordinate needle point
   needle_x_old = needle_x;                                                                     // remember previous needle position
   needle_y_old = needle_y;

 //  gfx->drawLine (pivot_x, pivot_y, needle_x, needle_y,MAGENTA); 

   gfx->drawLine (pivot_x, pivot_y, needle_x, needle_y,CYAN); //RED
  // gfx->drawLine (pivot_x+3, pivot_y+1, needle_x+1, needle_y+1,CYAN); //RED


   gfx->fillCircle (pivot_x, pivot_y, 2, MAGENTA);                                               // restore needle pivot
}

// ######################################################################################
// # static data in the min-max temp panel                                              #
// ######################################################################################

   void static_minmax_panel (){
//kader afmeting gfx->drawRoundRect  (minmax_panel_x+75, minmax_panel_y-154, 154,  156, 4, GREEN); 

   gfx->drawRoundRect (minmax_panel_x+90, minmax_panel_y-148, 14, 120, 4, WHITE);                     // 'thermometer'
   gfx->fillCircle (minmax_panel_x+96, minmax_panel_y-20, 13, RED);  
   gfx->drawCircle (minmax_panel_x+96, minmax_panel_y-20, 14, WHITE);

   gfx->setTextColor (YELLOW,BLACK);
   gfx->setFont(&Dialog_plain_18); 
   gfx->setCursor (minmax_panel_x+120,minmax_panel_y-138); //110
   gfx->print ("Max temp");
  
   gfx->setFont(&Dialog_plain_24); 
   gfx->drawCircle (minmax_panel_x+195, minmax_panel_y-120, 3, WHITE);
   gfx->drawCircle (minmax_panel_x+195, minmax_panel_y-120, 4, WHITE); // meer min => omhoog
   gfx->setCursor (minmax_panel_x+197,minmax_panel_y-95); 
   gfx->setTextColor (WHITE,BLACK);
   gfx->print ("C");
 
   gfx->setFont(&Dialog_plain_18); 
   gfx->setCursor (minmax_panel_x+120,minmax_panel_y-60); 
   gfx->setTextColor (YELLOW,BLACK);
   gfx->print ("Min temp");

   gfx->setTextColor (WHITE,BLACK);  
   gfx->setFont(&Dialog_plain_24); 
   gfx->drawCircle (minmax_panel_x+195, minmax_panel_y-40, 3, WHITE);
   gfx->drawCircle (minmax_panel_x+195, minmax_panel_y-40, 4, WHITE);  
   gfx->setCursor (minmax_panel_x+197,minmax_panel_y-15); 
   gfx->print ("C");

   t_meter_increase = 92;         //was 46                  // absolute vertical pixel range of 'mercury' in thermometer simulation

    gfx->setFont(0);  
}


//https://stackoverflow.com/questions/75858382/openweathermap-weather-returns-null

// ######################################################################################
// # run the weather station - get json string and parse                                #
// ######################################################################################


void run_the_weatherstation (){
// for(;;){         
          
          String serverPath = "http://api.openweathermap.org/data/2.5/weather?q=" + city + "," + countryCode + "&APPID=" + openWeatherMapApiKey;
      
          jsonBuffer = httpGETRequest(serverPath.c_str());
          Serial.println(jsonBuffer);
          Serial.println("na jsonbuffer");
          JSONVar myObject = JSON.parse(jsonBuffer);

               double weather_01  = (myObject ["weather"]["id"]);

               double temp_01     = (myObject ["main"]["temp"]); 
               double hum_01      = (myObject ["main"]["humidity"]); 
               double press_01    = (myObject ["main"]["pressure"]); 
               double w_speed_01  = (myObject ["wind"]["speed"]);   
               double wind_dir_01 = (myObject ["wind"]["deg"]);  


         JSONVar minmax_temp = JSON.parse(jsonBuffer);
               double min_temp = (minmax_temp ["main"]["temp_min"]);
               double max_temp = (minmax_temp ["main"]["temp_max"]);
 
  
          if (JSON.typeof(myObject) == "undefined")                                             // JSON.typeof(jsonVar) can be used to get the type of the var
            {
             Serial.println("Parsing input failed!");
             return;
             }
    
          Serial.println ("*******************************************");  
          Serial.print ("JSON object = ");
          Serial.println (myObject);
          Serial.println ("*******************************************");    
          Serial.println ("extracted from JSON object:");        


          Serial.print (myObject["weather"]["id"]);
          Serial.println (" =ID2");

          Serial.print ("temperature:    ");    
          Serial.print (myObject["main"]["temp"]);
          Serial.println (" *K");       
          Serial.print ("pressure:       ");
          Serial.print (myObject["main"]["pressure"]);
          Serial.println (" mB"); 
          Serial.print ("humidity:       ");
          Serial.print(myObject["main"]["humidity"]);
          Serial.println (" %");  
          Serial.print ("wind speed:     ");
          Serial.print (myObject["wind"]["speed"]);
          Serial.println (" m/s");  
          Serial.print("wind direction: ");
          Serial.print (myObject["wind"]["deg"]);
          Serial.println (" degrees");      

  


                                                                                                                            
          temp_rainbowgauge = temp_01-273;                                                      // convert temp from Kelvin to Celsius
          hum_02 = hum_01;                                                                      // place humidity value in a transferable variable
          press_02 = press_01;                                                                  // place air pressure value in a transferable variable
          w_speed_02 = w_speed_01;                                                              // place wind speed value in a transferable variable

          max_temp_today = max_temp-273;
          min_temp_today = min_temp-273;
      
          Serial.print("min temp today: ");
          Serial.print (min_temp_today,1);
          Serial.println (" *C");         
          Serial.print("max temp today: ");
          Serial.print (max_temp_today,1);                  
          Serial.println (" *C");   
          
          wind_dir_02 = wind_dir_01;
          windSectorReporter ();

   gfx->setFont(&Dialog_plain_9); 
   gfx->setCursor ((compassPivot_x+10), (compassPivot_y+170));
   gfx->print (myObject["wind"]["deg"]);
   gfx->setFont(0);

    rainbowScaleMeter ();
    print_dynamic_data_to_display ();
    compassPointer ();  
    refresh_dynamic_baropanel();
    build_dynamic_baropanel (); 
    needle_meter ();  
    dynamic_minmax_panel (); 

//}//einde for

}//einde run


// ######################################################################################
// # dynamic data in the min-max temp panel                                             #
// ######################################################################################
//nog aanpassen
   void dynamic_minmax_panel (){

   gfx->fillRect (minmax_panel_x+115,minmax_panel_y-115, 72,30,BLACK); //BLACK   tbv wegvegen oude waarde  /meer min => omhoog
   
   gfx->setFont(&Dialog_bold_24);
   
   if (max_temp_today >=  0.0) gfx->setCursor (minmax_panel_x+140,minmax_panel_y-95); 
   if (max_temp_today >= 10.0) gfx->setCursor (minmax_panel_x+124,minmax_panel_y-95); 
   if (max_temp_today <  -0.0) gfx->setCursor (minmax_panel_x+124,minmax_panel_y-95); 
   if (max_temp_today <  -9.9) gfx->setCursor (minmax_panel_x+128,minmax_panel_y-95); 

   gfx->print (max_temp_today,1);  
 
   gfx->fillRect (minmax_panel_x+115,minmax_panel_y-35, 72,30,BLACK);   //BLACK

   if (min_temp_today >=  0.0) gfx->setCursor (minmax_panel_x+140,minmax_panel_y-15); 
   if (min_temp_today >= 10.0) gfx->setCursor (minmax_panel_x+124,minmax_panel_y-15); //minder min => omlaag
   if (min_temp_today <  -0.0) gfx->setCursor (minmax_panel_x+124,minmax_panel_y-15); 
   if (min_temp_today <  -9.9) gfx->setCursor (minmax_panel_x+128,minmax_panel_y-15);   
   gfx->print (min_temp_today,1);   
  
   t_meter_increase_old = t_meter_increase;  
   t_meter_increase = ((max_temp_today/33)*92);                                                 // empirically determined dynamic range of 'mercury' in the graphical thermometer
   t_meter_increase = ((max_temp_today/33)*92);      
   //t_meter_increase = ((max_temp_today/33)*46);                                                 // empirically determined dynamic range of 'mercury' in the graphical thermometer
   //t_meter_increase = ((max_temp_today/33)*46);     



   if (t_meter_increase <1)  t_meter_increase = 1;
   if (t_meter_increase >45) t_meter_increase = 45;                                             // barrier against overflowing of graphical thermometer 
   //if (t_meter_increase <1)  t_meter_increase = 1;
   //if (t_meter_increase >45) t_meter_increase = 45;    

  //org gfx->fillRect (minmax_panel_x+9,minmax_panel_y+57, 5, -t_meter_increase_old, YELLOW); //black
//org gfx->fillRect (minmax_panel_x+9,minmax_panel_y+57, 5, -t_meter_increase, RED); 
 
 
 gfx->fillRect (minmax_panel_x+91,minmax_panel_y-26 -t_meter_increase_old, 12, t_meter_increase_old,BLACK);  
 gfx->fillRect (minmax_panel_x+91,minmax_panel_y-26 -t_meter_increase, 12, t_meter_increase,RED); 

gfx->setFont(0);

}

// ######################################################################################
// # http GET request module                                                            #
// ######################################################################################

String httpGETRequest(const char* serverName) {

   WiFiClient client;
   HTTPClient http;
      
   http.begin(client, serverName);                                                              // your IP address with path or Domain name with URL path 
    
   int httpResponseCode = http.GET();                                                           // send HTTP POST request  
   String payload = "{}"; 
  
   if (httpResponseCode>0) {
    Serial.print("HTTP Response code: ");
    Serial.println(httpResponseCode);
    payload = http.getString();
   }
   else {
     Serial.print("Error code: ");
     Serial.println(httpResponseCode);
   }

   http.end();                                                                                  // free resources
   return payload;  
}



///=================================================================================================

// ######################################################################################
// #  dynamic temperature rainbow scale meter                                           #
// ######################################################################################

void  rainbowScaleMeter (){
   
   if (millis () - runTime >= 100)                                                              // originally 500 = delay                                       
     {                                    
      runTime = millis ();
      if( tesmod==0)
        {
         reading =  99;
        }
      if( tesmod==1)
        {
         reading = temp_rainbowgauge*2;                                                         // important: here ring is seeded with value      
        } 
 
//       r_gauge_pos_x = 161;                                                                     // these two variables govern the position
//       r_gauge_pos_y = 5;                                                                       // of the square + gauge on the display = upper left corner

     ringMeter (reading,0,100, (r_gauge_pos_x+45),(r_gauge_pos_y+17),ringmeter_radius,ringlabel[0],GREEN2RED);    
     tesmod = 1;
     }
}

// ######################################################################################
// #  rainbow scale: draw the rainbox ring meter, returns x coord of righthand side     #
// ######################################################################################

int ringMeter(int value,int vmin,int vmax,int x,int y,int r, char *units, byte scheme){
  // Minimum value of r is about 52 before value text intrudes on ring
  // drawing the text first is an option
 
   x += r; y += r;                                                                              // calculate coordinates of center of ring
   int w = r / 3;                                                                               // width of outer ring is 1/4 of radius
   int angle = 150;                                                                             // half the sweep angle of the meter (300 degrees)
   int v = map (value, vmin, vmax, -angle, angle);                                              // map the value to an angle v
   byte seg = 3;                                                                                // segments are 3 degrees wide = 100 segments for 300 degrees
   byte inc = 6;                                                                                // draw segments every 3 degrees, increase to 6 for segmented ring
   int colour = BLUE;                                                                           // variable to save "value" text color from scheme and set default
 
 
   for (int i = -angle+inc/2; i < angle-inc/2; i += inc)                                        // draw color blocks every increment degrees
     {           
      float sx = cos((i - 90) * DEG2RAD);                                                       // calculate pair of coordinates for segment start
      float sy = sin((i - 90) * DEG2RAD);
      uint16_t x0 = sx * (r - w) + x;
      uint16_t y0 = sy * (r - w) + y;
      uint16_t x1 = sx * r + x;
      uint16_t y1 = sy * r + y;
    
      float sx2 = cos((i + seg - 90) * DEG2RAD);                                                // calculate pair of coordinates for segment end
      float sy2 = sin((i + seg - 90) * DEG2RAD);
      int x2 = sx2 * (r - w) + x;
      int y2 = sy2 * (r - w) + y;
      int x3 = sx2 * r + x;
      int y3 = sy2 * r + y;

      if (i < v) 
         {                                                                                      // fill in coloured segments with 2 triangles
          switch (scheme)
             {
              case 0: colour = RED; break;                                                      // fixed color
              case 1: colour = GREEN; break;                                                    // fixed color
              case 2: colour = BLUE; break;                                                     // fixed colour
              case 3: colour = RED; break;                   // full spectrum blue to red
              case 4: colour = GREEN; break;                   // green to red (high temperature etc)
              case 5: colour = BLUE; break;                  // red to green (low battery etc)

            // case 3: colour = rainbow(map(i, -angle, angle, 0, 127)); break;                   // full spectrum blue to red
            //  case 4: colour = rainbow(map(i, -angle, angle, 70, 127)); break;                  // green to red (high temperature etc)
            //  case 5: colour = rainbow(map(i, -angle, angle, 127, 63)); break;                  // red to green (low battery etc)
              default: colour = BLUE; break;                                                    // fixed color
             }
              gfx->fillTriangle(x0, y0, x1, y1, x2, y2, colour);
              gfx->fillTriangle(x1, y1, x2, y2, x3, y3, colour);
             }
      else                                                                                      // fill in blank segments
             {
              gfx->fillTriangle(x0, y0, x1, y1, x2, y2, SCALE1);                                 // color of the unoccupied ring scale 
              gfx->fillTriangle(x1, y1, x2, y2, x3, y3, SCALE0);                                 // color of the unoccupied ring scale
             }
         }
            
t=530;                                  //t=197 aanpassen tbv 7  

   if (temp_rainbowgauge<-9.9) t = 525;   //positie na actuele temp
   if (temp_rainbowgauge>-9.9) t = 530;  
   if (temp_rainbowgauge > 0 ) t = 532;
   if (temp_rainbowgauge >9.9) t = 524;

   gfx->fillRect (t+14,y-22,140,40,BLACK);   //BLACK   tbv wegvallen nadat temp is gelezen  BLACK
   gfx->setFont(&Dialog_bold_40); 
   //gfx->setTextSize(4); 

   gfx->setCursor (t+45,y+10);     //positie temp => temp 0.0 heeft basis t,y positie
   gfx->setTextColor (WHITE); //yellow
  
   gfx->print (temp_rainbowgauge,1);    // tft.print (temp_rainbowgauge,1);  = basic temp 0.0. 
   return (temp_rainbowgauge);
  gfx->setFont(0);
   
}


/*
// ######################################################################################
// #  rainbow scale: 16-bit rainbow color mixer                                         #
// ######################################################################################

unsigned int rainbow (byte value) {                                                             // value is expected to be in range 0-127
                                                                                                // value is converted to a spectrum color from 0 = BLUE through to 127 = RED
   byte RED = 0;                                                                                // RED is the top 5 bits of a 16 bit colour value
   byte GREEN = 0;                                                                              // GREEN is the middle 6 bits
   byte BLUE = 0;                                                                               // BLUE is the bottom 5 bits
   byte quadrant = value / 32;

   if (quadrant == 0)
     {
      BLUE = 31;
      GREEN = 2 * (value % 32);
      RED = 0;
     }
   if (quadrant == 1)
     {
      BLUE = 31 - (value % 32);
      GREEN = 63;
      RED = 0;
     }
   if (quadrant == 2)
     {
      BLUE = 0;
      GREEN = 63;
      RED = value % 32;
     }
   if (quadrant == 3)
     {
      BLUE = 0;
      GREEN = 63 - 2 * (value % 32);
      RED = 31;
     }
   return (RED << 11) + (GREEN << 5) + BLUE;
}

*/


// ######################################################################################
// # dynamic data in the numeric panel                                                  #
// ######################################################################################

void print_dynamic_data_to_display (){
//waarden presenteren
   static_num_panel_x = 120;                 // all coordinates in this panel relative to these two
   static_num_panel_y = 35;               // all coordinates in this panel relative to these two   
   
   gfx->setTextColor (WHITE,BLACK);
   gfx->setFont(&Dialog_bold_32); 
   gfx->fillRect (static_num_panel_x+10,static_num_panel_y+20,150,40,BLACK);  //tbv wegvallen temp bij verandering ->org =BLACK   
   gfx->setCursor (static_num_panel_x+65,static_num_panel_y+46);  
   gfx->print (temp_rainbowgauge,1);  //tbv temp in rainbow en totaal overzicht


//////////////////
   gfx->fillRect (static_num_panel_x+45,static_num_panel_y+72,132,40,BLACK); 
   gfx->setCursor (static_num_panel_x+55,static_num_panel_y+98); 
   if (press_02 <1000) gfx->setCursor (static_num_panel_x+60,static_num_panel_y+98); 
   gfx->print (press_02,0); 


   gfx->fillRect (static_num_panel_x+45,static_num_panel_y+129,120,40,BLACK);   
   gfx->setCursor (static_num_panel_x+75,static_num_panel_y+155);  
   gfx->print (hum_02,0);        

   gfx->fillRect (static_num_panel_x+40,static_num_panel_y+184,130,40,BLACK);  
   gfx->setCursor (static_num_panel_x+70,static_num_panel_y+210);   
   gfx->print (w_speed_02,1);

   gfx->fillRect (static_num_panel_x+45,static_num_panel_y+238,245,36,BLACK);  
   gfx->setCursor (static_num_panel_x+65,static_num_panel_y+265); 
   gfx->print (sector[h]); 
   gfx->setFont(0);

}

// ######################################################################################
// #  dynamic barometer panel                                                           #
// ######################################################################################

void build_dynamic_baropanel (){                                                                // fills two triangles to create 4-point polygon
   
   barval = 1050-press_02;  

//   baro_panel_x = 162;  //extra tbv positie
//   baro_panel_y = 156;                                                                   // based on baro pressure 

//   baro_panel_x = 476;  //extra tbv positie
//   baro_panel_y = 322;     
//vierkant linker bovenhoek = 476,322
   p1_x = ((baro_panel_x+6)+ ((100-barval)/100*144));                                            // p1-p2-p3 corner points for first triangle
   p1_y = ((baro_panel_y+150)- ((100-barval)/100*146));                                           // p1-p4-p3 corner points for second triangle
  
   p2_x = baro_panel_x+2;  
   p2_y = baro_panel_y+154; //was 148 
  
   p3_x = baro_panel_x+152; //was 150
   p3_y = baro_panel_y+154; //was 148
  
   p4_x = baro_panel_x+152; 
   p4_y = p1_y;  

   p1_x_old = p1_x;                                                                             // remember previous positions of points
   p1_y_old = p1_y;
   p2_x_old = p2_x;
   p2_y_old = p2_y;
   p3_x_old = p3_x;
   p3_y_old = p3_y;    
   p4_x_old = p4_x;
   p4_y_old = p4_y; 
   
  gfx->fillTriangle (p1_x, p1_y, p2_x, p2_y, p3_x, p3_y, SCALE2);   //SCALE2                            // make new first triangle
  gfx->fillTriangle (p1_x, p1_y, p4_x, p4_y, p3_x, p3_y, SCALE2);   //SCALE2                            // make new second triangle
  gfx->drawLine (p1_x, p1_y,  p4_x, p4_y, CYAN);                                                // draw horizontal level line      

   gfx->drawLine (baro_panel_x+8, baro_panel_y+150, baro_panel_x+148, baro_panel_y+150, SCALE2);    // correct triangles base    SCALE2
   gfx->drawLine (baro_panel_x+8, baro_panel_y+152, baro_panel_x+144, baro_panel_y+152, SCALE2);    // correct triangles-base    SCALE2
   gfx->drawRoundRect (baro_panel_x, baro_panel_y,  154,  156, 4, GREEN);                          // correct right-of-middle lower panel frame
   
   gfx->drawLine (baro_panel_x+4, baro_panel_y+150, (baro_panel_x+150), (baro_panel_y+4), CYAN);   // redraw line
   gfx->fillCircle (p1_x, p1_y,3,RED);

   gfx->setFont(&Dialog_plain_18);
   gfx->setTextColor (YELLOW,BLACK);
   gfx->setCursor (baro_panel_x+10, baro_panel_y+20);
   gfx->print ("baro ");
   gfx->setTextColor (WHITE,BLACK);
   gfx->setCursor (baro_panel_x+64, baro_panel_y+20); 
       if (press_02>999) gfx->print ("high"); else gfx->print ("low ");
       
   gfx->setFont(0);
}


// ######################################################################################
// # refresh the dynamic barometer panel                                                #
// ######################################################################################


void refresh_dynamic_baropanel (){

  gfx->fillCircle   (p1_x_old, p1_y_old, 3, BLACK);                                              // erase previous position of red circle
  gfx->fillTriangle (p1_x_old, p1_y_old, p2_x_old, p2_y_old, p3_x_old, p3_y_old, BLACK);         // remove previous first triangle
  gfx->fillTriangle (p1_x_old, p1_y_old, p4_x_old, p4_y_old, p3_x_old, p3_y_old, BLACK);         // remove previous second triangle 
  gfx->drawLine (p1_x_old, p1_y_old,  p4_x_old, p4_y_old, BLACK);                                // remove previous horizontal level line  
  gfx->drawLine (baro_panel_x+4, baro_panel_y+150, (baro_panel_x+150), (baro_panel_y+4), CYAN);    // draw new diagonal line

  gfx->drawLine (baro_panel_x+8, baro_panel_y+150, baro_panel_x+148, baro_panel_y+150, SCALE2);     // correct triangles base
  gfx->drawLine (baro_panel_x+8, baro_panel_y+152, baro_panel_x+144, baro_panel_y+152, SCALE2);     // correct triangles-base
//  gfx->drawRoundRect  (minmax_panel_x, minmax_panel_y, 144,  156, 4, GREEN);                       // extreme right lower window                                 

}
 

With regards Ton

I assume there is no solution for this code??

still NO answer

Well i was initially disturbed by having to look thru 2 codes for 1 question, hoping someone else would but in.

What can we do to narrow down the problem. The code is extensive (and still not properly indented which makes reading a tad harder)

It uses libraries i am not familiar with. So i don't really know where to look. Maybe we can exclude some things.

Does the whole JSON thing work as long as you don't display anything on the screen (and vice versa) ?

just assuming that this bitmap actually has the proper size..

Some vague memory is telling me that this can cause issues if the request returns an empty String,
Can't quite remember completely, but how about before converting it to a c-string, test it for content. And make sure there is a NULL terminator in the buffer. I am just fishing here, but i would have suspected you to do the same by now. 2 weeks and what have you tried ...

Anything that can be done with that, that points is in a direction ?

I mean basically it works, but on occasion something happens that causes an error. I am betting on the HTTP request not returning what is expected (probably just nothing) and the method of coding and parsing that does not resolve that.

Thank you for your comment. Now I don't quite understand what you mean by setting the C-string and the something to NULL. The good thing is that the weather station has been working well for almost 10 days without any problems.

If you don't understand what i said, then i suspect you are not the author of the code, and if it does not function properly, you should contact the author.

I have compiled this code myself from various examples from the internet. Everything has been adjusted in such a way that I can present it on a 7 inch display.

Yeah this i understand, but i do advise you to study to understand the principles of the code. In particular the use of the String class, the use of c-strings (aka char array aka char*) and it's conversions. As i said there is a vague memory which probably relates to the issues you have been experiencing. In that case, the conversion did not go as planned when there was an empty String to convert, which resulted in an error parsing the result. It was topic that passed here on the forum a some weeks ago.

Ah i found something !!

You may be fragmenting your memory due to the 'jsonBuffer' variable being global, but used and expanded locally.

It should be just a local variable to the run_the_weatherstation () function.

so instead of having

String jsonBuffer;

at the beginning of your sketch, it should be

void run_the_weatherstation (){
// for(;;){         
          
          String serverPath = "http://api.openweathermap.org/data/2.5/weather?q=" + city + "," + countryCode + "&APPID=" + openWeatherMapApiKey;
      
          String jsonBuffer = httpGETRequest(serverPath.c_str());

declared inside this function instead.

Does that compile ?

Thank you many times, I'm going to work on it this week.

1 Like

Compile is not working. But display is crashed before i can uload (is black), First order new one.

and the error ?

Sorry for the delay, but had to work a lot (holiday period).

Brought the void run_the_weatherstation to the beginning. Get This Error Now

Compilation error: 'GPIO_NUM_46' was not declared in this scope; did you mean 'GPIO_NUM_6'?

This is a part of:

#include <SPI.h>

#include "gfx_conf.h" //Please modify the setting of display driver according to the board you are using in gfx_conf.h.

With regards Ton

Those seem completely unrelated, which makes me think there might be a closing curly brace '}' or a closing brace ')' missing somewhere which can result in the strangest errors at times.

so i don't know what you did or how to resolve that.

Sorry, but had selected the wrong board due to haste. Have to take a good look now in between, I have to adjust another one. Busy with work in the coming period to accommodate holidaymakers in the store.

With regards Ton

Had to make some adjustments, but the compile works. Now I'm waiting for a new display that I ordered.

I had another 7 inch display with GFX code that I had used once and made the changes you suggested, but same problem. Display worked well for a few days and suddenly the problem came back.
So it doesn't matter which display and there is something in the code that causes that. At the time, I converted the code from a 3.5-inch display to a 7-inch display. The 3.5 inch display has been working for months without any problems, but since I have had to adjust the size everywhere, I am afraid that this is the problem.

In the In the meantime I have the code on 2 of the same 7 inch displays. 1 Outside and 1 inside. The very strange thing is that they both get the wrong at the same time.
I'm now removing certain code from 1 display to see if I can find out where the error comes from.meantime I have the code on 2 of the same 7 inch displays. 1 Outside and 1 inside. The very strange thing is that they both get the wrong at the same time.
I'm now removing certain code from 1 display to see if I can find out where the error comes from.

As it stands, I have found the problem. The following code gave the error. If there was a certain "h" value (don't know which one) the error came. This whole feature turned off and all keeps working.
As far as I can see, it has to do with the name of the wind direction. But then why does an error come? Maybe names too long???

void windSectorReporter (){

   h = 0;
   if (wind_dir_02 <22.5) h = 0;
   if (wind_dir_02> 22.5) h = 1; 
   if (wind_dir_02> 67.5) h = 2;
   if (wind_dir_02>112.5) h = 3;
   if (wind_dir_02>157.5) h = 4;  
   if (wind_dir_02>202.5) h = 5;
   if (wind_dir_02>247.5) h = 6;
   if (wind_dir_02>292.5) h = 7; 
   if (wind_dir_02>337.5) h = 8; 

}



 lcd.print (sector[h]);