Nextion - gettng value from other page

Hy friends.

Here is the code:

#include <Arduino.h>
#include <Nextion.h>
//SD-card
#include "FS.h"
#include "SD.h"
#include "SPI.h"
//RTC-clock
#include <Wire.h>
#include "RTClib.h"
//ESP32-Eprom
#include "EEPROM.h"
//Classes
#include <Classes.h>

/****** Definition of NEXTION-objects*******/
//buttons
NexButton initValStart      = NexButton(0, 2, "initVal");   //page initialization
NexPage displayInit = NexPage(11, 0, "Display");
//numbers
NexNumber brigtNs = NexNumber(11, 7, "n0");



/******Declaration of Nextion-Callbacks********/
void initValStartPopCallback(void *ptr);
void displayInitPopCallback(void *ptr);

/**** all Nextion objects that need to be listened */
NexTouch *nex_listen_list[] =
{
  //buttons
  &initValStart,
  //pages
  &displayInit,
  NULL

};

/******Definition of Nextion-Callbacks*****/
//Init-button. Will be clicked automaticly to initialize saved values from ESP32 EPROM
void initValStartPopCallback(void *ptr) 
{
  uint32_t f;
  brigtNs.getValue(&f);
  currentSettings.brigtness = f;
  Serial.println("lllll");
}

void displayInitPopCallback(void *ptr) 
{
    uint32_t tbrightness;
  brigtNs.getValue(&tbrightness);
  currentSettings.brigtness = tbrightness;
  Serial.println("HHHHH");
}




void setup() {
nexInit();
  //Serial COM
  Serial.begin(9600);
   // while the serial stream is not open, do nothing:
   while (!Serial) ;
  Serial2.begin(9600);
  // put your setup code here, to run once:
  initValStart.attachPop(initValStartPopCallback);
  displayInit.attachPop(displayInitPopCallback);

  

}

void loop() {
  // put your main code here, to run repeatedly:

  Serial.println(currentSettings.brigtness);


  nexLoop(nex_listen_list);
  delay(2000);
}

I dont get it. Why does displayInitPopCallback work and writes the correct value into my membervariable of my struct, but initValStartPopCallback leads to “NexNumber timeout”

I get it that initValStartPopCallback is on a different page, but everything in my nextion is set to global.

Someone has an idea?

Thank you

I would start with removing the delay(2000) and moderating the output with millis().

Jeah thanks for the answer. I know that delay isnt the best thing. I was using daLay just for my testcase. But this cant be the problem?!

Why does one function work and the other not. They are similar

Thank you

Did you look at the Nextion editor documentation?

Page name prefixing is suggested to access a global component’s attributes on another page.
– example: page0.va0.val

Maybe brigtNs.getValue does not work for global objects on different pages,
failing to insert the page name in the request.

I don't use the Nextion library, so I'm not eager to dig into it.

This was the solution. I modified the getvalue function from the nextion lib and it worked.

Thanks sir

Manuel_o:
This was the solution. I modified the getvalue function from the nextion lib and it worked.

Thanks sir

Hi Manuel,
How exactly did you modify the lib?
I'm facing the same problem in that the arduino does not get the value from a checkbox (or button) if it is not currently on that page.
Seems the ".getValue" does not work if you are not specifically on that page you need to read it from? (all set to global)

Many thanks

I'm facing the same problem in that the arduino does not get the value from a checkbox (or button) if it is not currently on that page.

Are the variables you are trying to access declared as global on the Nextion? If not, they are not there to be read when the page is not displayed.

I know that delay isn't the best thing. I was using delay just for my test case. But this cant be the problem?!

You do know that during a delay the Arduino does NOTHING ELSE? So, it won't be getting any data from your Nextion. At the very least, even if delay is not the cause, if you have a delay, and you have a problem, a good first step is to remove the delay and see if that helps. Why on earth do you want a 2 second delay anyway?

PerryBebbington:
Are the variables you are trying to access declared as global on the Nextion? If not, they are not there to be read when the page is not displayed.

Hi Perry,

Yes the "checkbox" is indeed declared as a global variable. So is the page as well.