D1 R2 ESP8266 restart after first loop

I use this code to gather data from sensors and send it do mysql database.
I raised char query[128] to 255 but I need to send much longer string in variables sumPM25=",10,10,10,10";sumPM10=",10,10,10,10";
If I put such a long string I got Exception and program stops after the first loop. These long strings are saved correctly to mysql database.
What should I do to send long strings without getting exception and stopping the program? There is a lot of dynamic memory to use variables. So this is not a problem.

char INSERT_DATA[] = "INSERT INTO sh177864_alberts.ruchLog (ruch1, hum, pres, pm25, pm10) VALUES (%s,%s,%s,'%s','%s')";
char query[255];
String sumPM25, sumPM10;

void setup(){...}

void loop() {
  printBME280Data(&Serial);
   //delay(500);
  
}

void printBME280Data
(
   Stream* client
)
{
   
   float temp(NAN), hum(NAN), pres(NAN), tempAVG, humAVG, presAVG;

   BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
   BME280::PresUnit presUnit(BME280::PresUnit_hPa);
   tempAVG=0; humAVG=0;presAVG=0;
   
   sumPM25=",10,10,10,10";sumPM10=",10,10,10,10"; // here is problem!!!
   
   for (int a=0; a<10; a++) 
{
  bme.read(pres, temp, hum, tempUnit, presUnit);

   client->print("Temperatura: ");
   client->print(temp);
   client->print("°"+ String(tempUnit == BME280::TempUnit_Celsius ? 'C' :'F'));
   client->print("\t\tWilgotność: ");
   client->print(hum);
   client->print("% RH");
   client->print("\t\tCiśnienie: ");
   client->print(pres);
   client->println(" hPa\t\t");
   tempAVG+=temp;
   humAVG+=hum;
   presAVG+=pres;
   //for (int b=0; b<12; b++) 
   // {
      if(Serial.find(0x42))    
    Serial.readBytes(bufor,N);

     if(bufor[0] == 0x4d){
      if(sprawdzLancuch(bufor,N)){  
        PM25=wartoscPM25(bufor);
        PM10=wartoscPM10(bufor);  
     }
    }
   sprintf(linia1,"%d",PM25);
   
   sprintf(linia2,"%d",PM10);
   
  
   delay(5000);
   //}
   
}
    MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
    // Save
    dtostrf(tempAVG/10, 1, 3, temperature);
    dtostrf(humAVG/10, 1, 3, wilgotnosc);
    dtostrf(presAVG/10, 1, 2, cisnienie);
    sprintf(query, INSERT_DATA, temperature, wilgotnosc, cisnienie, sumPM25.c_str(), sumPM10.c_str());
    
    cur_mem->execute(query);
   
    delete cur_mem;
    Serial.println("Data saved.");
  
  delay(1000);
}

Hello,

As far as I know, you can not use functions that handle long-term processing, such as "for" "while", etc.

Therefore, it would be necessary to use another timing medium, such as cycle counting, millis (), etc.

You can test, try using an infinite loop like:

while(1);

I got Exception

Why don't you think the nature of that exception would be pertinent? I would think that would be the main piece of information I wanted to give out. That is what is going to tell what the chip thinks the problem is. Why would you leave that out?

void printBME280Data
(
   Stream* client
)
{

Can
you
post
a
link
to
a
single
example
where
this
crap
style
of
function
declaration
is
used?

All code I based is in the example arduino library BME280. I am newbie and I think the best solution is to learn on examples by modification.

Yeah but not just any old examples. There are LOTS of bad examples out there.

The best method, trust me, is to do a couple of good C++ tutorials all the way through and learn the basics of the language. Then the rest is trivial after that. It gets WAY easier to play with the examples once you know the basics of the language.