Weird crash, if 2 URL querries are run one after the other.

Hi,

I have to deal with a weird behaviour.
I am compiling for an ESP8266.

I have two 2 JSON URL querries that run perfectly individually.

But if I let them run one after the other, irrespective of which one runs first, I get a crash.

Has someone got a clue what is the problem?

Here are the relevant parts of the (long) program taking 45% of the program space and 40% of the variables.

a) compiler directives and libraries:

// ***Functional Configuration***
#define WEATHER_SOURCE_IS_NONE   //_URL _NONE              Change end accordingly
#define OPEN_WEATHER_MAP_URL   "http://api.openweathermap.org/data/2.5/weather?id=2928810&appid=208085abb5a3859d1e32341d6e1f9079&lang=de&units=metric"

#define SOUND_SOURCE_IS_URL         //_ANAIN _URL _UDP _NONE  Change end accordingly
#define DFLD_URL "http://api.dfld.de/noise/dfld.de/004/020"


//...
#include <ArduinoJson.h> 
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <ESP8266WiFi.h>      // default from Espressif
#include <ESP8266HTTPClient.h>#include <ArduinoJson.h>   // Libs for Webscraping

b) function is called in loop every second.

void data1SRun()  
{
  yield();
  // Getting Weather from OpenWeatherMap every 5 minutes
#if defined WEATHER_SOURCE_IS_URL
  if (Minute % 5 == 1 && Second == 32)   // call every 5 minutes
  {
    http.begin(OPEN_WEATHER_MAP_URL);
    int httpCode2 = http.GET();
    if (httpCode2 == HTTP_CODE_OK)
    {
      JSONpayload = http.getString();
      DynamicJsonDocument doc(1024);
      auto error = deserializeJson(doc, JSONpayload.c_str());
      if ( not error)
      {
        outdoor_temperature  = doc["main"]["temp"];
        outdoor_pressure     = doc["main"]["pressure"];
        outdoor_humidity     = doc["main"]["humidity"];
        wind_speed           = doc["wind"]["speed"];
        wind_direction       = doc["wind"]["deg"];
        cloudiness           = doc["clouds"]["all"];  // %
        weather_summary      = doc["weather"][0]["description"];
        sunrise              = doc["sys"]["sunrise"];
        sunset               = doc["sys"]["sunset"];
      }
    }
    http.end();
  }
#endif

  // Fetching Noise level from URL with reduced resolution
#if defined (SOUND_SOURCE_IS_URL)   // must be a JSON from DFLD.de
  http.begin(DFLD_URL);             //Specify request destination
  int httpCode1 = http.GET();       //Send the request
  if (httpCode1 == HTTP_CODE_OK)    //Check the returning code
  {
    JSONpayload = http.getString();          //Get the request response payload
    // it should be like: {"generator":"DFLD_LIVE","version":"0.9","time":1587592375,"access-control":"ignoredWrongPWD","027":32.0}
    JSONpayload = JSONpayload.substring(100, 104); // taking only the dB value
    sound.A0dBFast = JSONpayload.toFloat();
    sound.A0dBMin = min(sound.A0dBFast, sound.A0dBMin);
    sound.A0dBMax = max(sound.A0dBFast, sound.A0dBMax);
    sound.A0dBSlow += (sound.A0dBFast - sound.A0dBSlow) / 6; // Low Pass filter 6 sec
    if ( sound.A0dBFast > sound.A0dBImpulse)           //A0 in dB with impulse response
    {
      sound.A0dBImpulse = sound.A0dBFast;              //No filter
    }
    else
    {
      sound.A0dBImpulse = sound.A0dBImpulse - 4.3 ; //Linear decay 4,3db /sec
    }
  }
  http.end();   //Close connection
#endif
}

c) crash report

10:03:17.606 -> Exception (28):
10:03:17.606 -> epc1=0x4000bf80 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
10:03:17.606 -> 
10:03:17.606 -> >>>stack>>>
10:03:17.606 -> 
10:03:17.606 -> ctx: cont
10:03:17.606 -> sp: 3ffffd80 end: 3fffffc0 offset: 01a0
10:03:17.606 -> 3fffff20:  3fffdad0 3ffef618 3fff095b 40206f8b  
10:03:17.606 -> 3fffff30:  00000000 4bc6a7f0 48f5c28f 3fff0d9c  
10:03:17.640 -> 3fffff40:  007a1200 09bbf143 3ffe8800 00000000  
10:03:17.640 -> 3fffff50:  401057b9 00277f75 3fff0ea4 00000000  
10:03:17.640 -> 3fffff60:  3ffeeec0 3fff0ea4 3fff337c 0000000d  
10:03:17.640 -> 3fffff70:  3fffdad0 3fff0ea4 00000032 40215437  
10:03:17.640 -> 3fffff80:  40215c51 00000032 3fff0d9c 3fff0d9c  
10:03:17.640 -> 3fffff90:  3fffdad0 0000007c 3ffef5f8 40207686  
10:03:17.640 -> 3fffffa0:  3fffdad0 00000000 3fff0d5c 4021554c  
10:03:17.640 -> 3fffffb0:  feefeffe feefeffe 3ffe8588 40101231  
10:03:17.674 -> <<<stack<<<
10:03:17.674 -> 
10:03:17.674 ->  ets Jan  8 2013,rst cause:2, boot mode:(3,6)
10:03:17.674 -> 
10:03:17.708 -> load 0x4010f000, len 1392, room 16 
10:03:17.708 -> tail 0
10:03:17.708 -> chksum 0xd0
10:03:17.708 -> csum 0xd0
10:03:17.708 -> v3d128e5c
10:03:17.708 -> ~ld
10:03:20.763 ->

I finally got it:

I have invoked
HTTPClient http;
only once in setup.

now I call it at every querry:

HTTPClient http;
    http.begin(...

it runs well now.