Updating text field while the page is not active?

I have made a Nextion GUI, where there is a ‘page 1’, where there is a textfield (or label) for temperature and humidity, and there is a ‘page 2’ where I display the temperature, humidity, air pressure and altitude.
The datas are sent by an ESP32 module every 5 seconds, however I have a small problem.

When I am on page 1, and go to page 2, I have to wait a few seconds, for the Nextion to get the fresh data, due the ESP sends it every 5 seconds. Of course I can erase this 5 sec, but is there any other way to update a textfield that is not on the active page? For example, I am on page 1, but the fields on page 2 are also updated every time.

Hope you can understand what I want to achieve.

Hello,

this will not work because the page will load “fresh” without any value known.

You can check the page number with your ESP32 and if it change then send the text immediately.

Set the field in question to “global” instead of “local”, and then you can set the value while that object is off-page with p[1].b[2].txt="new value". Note that b[2] references Object ID, not the actual object name. See this for more info.

2 Likes

Thanks, I’ll try it.

One more thing, I would like to implement a “sleep mode”, after a few minutes the display turns off or at least sets the brightness to 0, and if I touch the screen it wakes up. Is it possible to make somehow?

Check out the thsp variable to set a sleep timer.

I have no trouble in populating a text field with this MCU code writing to non-active page on an enhanced display:

  // Write serial number to alarms page
  Serial.print("alarms.serialNumber.txt=");  
  Serial.print("\"");           
  Serial.print(serNum);      
  Serial.print("\"");           
  Serial.write(0xFF);
  Serial.write(0xFF);
  Serial.write(0xFF);

Where ‘alarms’ is the name of the page, and ‘serialNumber’ is a text field.

That works only under the condition that the text field’s vscope property has been changed from “local” (default) to “global”. If this isn’t done, the object will be invisible to the runtimes interpreter while its container page is not loaded and an error will be thrown.

That assumption was made!