Reading data in background after changing pages

Hello,
Is there any way to keep my main page reading data and update other pages even after changing to another page?
I am working on a small project and trying to simplify the Arduino code by taking one reading and then processing more data from it in the nextion itself. All looks very well and works perfectly. I have only one problem so far. The main page includes the sizeable digital number of temperature and humidity readings (for example), the second page contains a small digital number of data and waveform. I connect both pages’ data, so the temperature reading of page two is equal to the temperature reading of page one. So far, all is fine, but once leave page one to page two, only the last reading was sent, and the temperature reading on page two is not being updated. When I went back to page one, I found it stopped reading the data in the background after leaving it. Is there any way to keep my main page reading sensors data and update other pages even after changing to another page?
Your support is highly appreciated.
Thank you.

I would only get the data necessary for the active page. It’s a waste of bandwidth to get it for a page that isn’t visible. You can also just store all of the data in global variables, then read those when initializing a page

Hi

I have same issue.
You can look this at 0:52.
Video
How did you solve it?

Thanks!

When you write to a global variable from the mcu, you can read it from any page on the Nextion.

One way to read the variable on a page is to use a timer object which is initialized in the page preinitialization event.

Another method would be to send the page id to the mcu and have the mcu send the data directly to a control on the current page.

Hi
Currently, not all variables are global.
The page is switched in Nextion and sending the page number when I press the arrow. I only send the data from Mcu that is on that page. MCU knows this from the page number.
I don’t use any timers, and any variables.
MCU writes directly the displayed variables(pic, txt field)
Can you show me an example?

Thanks

What isn’t working for you?

It is visible at 52 seconds, for a moment the default values are displayed.
For each screen change, there is a lack of data for a moment.

Are you starting the data transfer in the preinitialization event or the postinitialization event? It should be in the preinitialization. Posting your code may help getting a better answer.

On the main screen, when I press the arrow, I send the screen number to ESP32. So I send it right away, but I’m not sure it will happen right away. I don’t know if I can check it out. Debug on Serial, Nextion on Serial2.

// Soros portról olvasás
  if (Serial2.available()) {
    String indata = Serial2.readStringUntil('#');                                                                    // # jelig várjuk az adatot
    // Képernyő szám megváltoztatása, oldalra lépéskor adatfrissítés
    if (indata.indexOf("page0") > -1) {                                                                              // Ha "page0" string érkezik
      kepernyo_szam = 0;                                                                                             // Képernyő változó értéke 0 lesz
    }
    else if (indata.indexOf("page1") > -1) {                                                                         // Ha "page1" string érkezik
      kepernyo_szam = 1;                                                                                             // Képernyő szám változó értéke 1 lesz
      szerviz_oldal_nem_folyamatos_kiiras ();                                                                        // 1. oldalon nem folyamatosan kijelzett adatok frissítése
    }
    else if (indata.indexOf("page2") > -1) {                                                                         // Ha "page2" string érkezik
      kepernyo_szam = 2;                                                                                             // Képernyő szám változó értéke 2 lesz
      elokep_nem_folyamatos_kiiras();                                                                                // 2. oldalon nem folyamatos megjelenített változók frissítése váltáskor
    }
    else if (indata.indexOf("page3") > -1) {                                                                         // Ha "page3" string érkezik
      kepernyo_szam = 3;                                                                                             // Képernyő szám változó értéke 3 lesz
      beallito_oldal1_kiiras_nem_folyamatos();                                                                       // 3. oldalon változók frissítése belépéskor                                                              
    }
    else if (indata.indexOf("page4") > -1) {                                                                         // Ha "page4" string érkezik
      kepernyo_szam = 4;                                                                                             // Képernyő szám változó értéke 4 lesz
      beallito_oldal2_kiiras_nem_folyamatos();                                                                       // 4. oldalon változók frissítése belépéskor
    }
    // Napi számláló nullázás
    else if ((indata.indexOf("kmreset") > -1) && !Flags.napi_nullazas ) {                                            // Ha "kmreset" string érkezik
      Flags.napi_nullazas = 1;                                                                                       // Napi számláló nullázó flag 1 lesz
    }
    // Grafikon törlés
    else if (indata.indexOf("graftorl") > -1) {                                                                      // Ha "graftorl" string érkezik
      grafikon_torles();                                                                                             // Grafikon törlés meghívása
    }
    // Rádió gomb állapot figyelés
    else if ((indata.indexOf("sebkijel") > -1) && (radiogomb_mentes != 1)) {                                         // Ha sebesség kijelzés rádiógombot kiválasztjuk és jelenleg nem ez van kiválasztva
      grafikon_torles();                                                                                             // Grafikon törlése
      radiogomb_mentes = 1;                                                                                          // radio gomb változó értéke 1 lesz
      ExtEEPR.put(EEPROM_cim_radiogomb_mentes, radiogomb_mentes);                                                    // radio gomb értékének mentése EEPROM-ba
      r1_val ();                                                                                                     // érték küldése Nextionra
    }
    else if ((indata.indexOf("fordkijel") > -1) && (radiogomb_mentes != 2)) {                                        // Ha fordulatszám kijelzés rádiógombot kiválasztjuk és jelenleg nem ez van kiválasztva
      grafikon_torles();                                                                                             // Grafikon törlése
      radiogomb_mentes = 2;                                                                                          // radio gomb változó értéke 2 lesz
      ExtEEPR.put(EEPROM_cim_radiogomb_mentes, radiogomb_mentes);                                                    // radio gomb értékének mentése EEPROM-ba
      r2_val ();                                                                                                     // érték küldése Nextionra
    }
    else if ((indata.indexOf("gyorskijel") > -1) && (radiogomb_mentes != 3)) {                                       // Ha gyorsulás kijelzés rádiógombot kiválasztjuk és jelenleg nem ez van kiválasztva
      grafikon_torles();                                                                                             // Grafikon törlése
      radiogomb_mentes = 3;                                                                                          // radio gomb változó értéke 3 lesz
      ExtEEPR.put(EEPROM_cim_radiogomb_mentes, radiogomb_mentes);                                                    // radio gomb értékének mentése EEPROM-ba
      r3_val ();                                                                                                     // érték küldése Nextionra
    }
    else if ((indata.indexOf("megtettut") > -1) && (radiogomb_mentes != 4)) {                                        // Ha megtett út kijelzés rádiógombot kiválasztjuk és jelenleg nem ez van kiválasztva
      grafikon_torles();                                                                                             // Grafikon törlése
      radiogomb_mentes = 4;                                                                                          // radio gomb változó értéke 4 lesz
      ExtEEPR.put(EEPROM_cim_radiogomb_mentes, radiogomb_mentes);                                                    // radio gomb értékének mentése EEPROM-ba
      r4_val ();                                                                                                     // érték küldése Nextionra
    }
    else if ((indata.indexOf("imapkijel") > -1) && (radiogomb_mentes != 5)) {                                        // Ha imap nyomás kijelzés rádiógombot kiválasztjuk és jelenleg nem ez van kiválasztva
      grafikon_torles();                                                                                             // Grafikon törlése
      radiogomb_mentes = 5;                                                                                          // radio gomb változó értéke 5 lesz
      ExtEEPR.put(EEPROM_cim_radiogomb_mentes, radiogomb_mentes);                                                    // radio gomb értékének mentése EEPROM-ba
      r5_val ();                                                                                                     // érték küldése Nextionra
    }
    else if ((indata.indexOf("emapkijel") > -1) && (radiogomb_mentes != 6)) {                                        // Ha emap nyomás kijelzés rádiógombot kiválasztjuk és jelenleg nem ez van kiválasztva
      grafikon_torles();                                                                                             // Grafikon törlése
      radiogomb_mentes = 6;                                                                                          // radio gomb változó értéke 6 lesz
      ExtEEPR.put(EEPROM_cim_radiogomb_mentes, radiogomb_mentes);                                                    // radio gomb értékének mentése EEPROM-ba
      r6_val ();                                                                                                     // érték küldése Nextionra
    }
    else if ((indata.indexOf("belevkij") > -1) && (radiogomb_mentes != 7)) {                                         // Ha beszívott levegő hőmérséklet kijelzés rádiógombot kiválasztjuk és jelenleg nem ez van kiválasztva
      grafikon_torles();                                                                                             // Grafikon törlése
      radiogomb_mentes = 7;                                                                                          // radio gomb változó értéke 7 lesz
      ExtEEPR.put(EEPROM_cim_radiogomb_mentes, radiogomb_mentes);                                                    // radio gomb értékének mentése EEPROM-ba
      r7_val ();
.
.
.
.
.
}

Sorry for hungarian comments
Example:
kepernyo_szam = 2;
Here is the screen number = 2 —> page2

  // Képernyőn lévő adatok megjelenítése az adott oldalon folyamatosan
  switch (kepernyo_szam) {
    case 0: fooldal_kiiras();                                                                                        // Főoldalon minden adat folyamatos frissítése
      break;
    case 1: szerviz_oldal_folyamatos_kiiras();                                                                       // Szerviz oldalon folyamatos adatok frissítése
      break;
    case 2: elokep_folyamatos_kiiras();                                                                              // Élőkép adatok frissítése amíg az élőadatok oldalon vagyunk
      break;
    case 3: beallito_oldal1_kiiras_folyamatos();                                                                     // 3. oldalon változók frissítése belépéskor
  }

The Touch Press Event code would probably be better in the Touch Release Event.

In the Preinitialize event on page 1, try adding ‘delay=500’. You shouldn’t be able to visually detect the delay. If you are updating the page in the Postinitilize event, you will probably still see that update after the page shows, and it would be better to move that code to the Preinitialize event.

I tried some settings.
I’m using global variables everywhere, then the flash is only on the first entry after not.
If I’m sending all the variables to the display after turning it on doesn’t help.