Start a new topic

SetComponentText to Global variables

Hi

It could be that I just need a toddlers guide to globals and refreshing them. Hopefully someone can assist


I have 4 pages on my Nextion, Each of the text field is set as vscope- global and each text field as a unique name


From my Arduino I am sending  


myNextion.setComponentText("t10", WiFi.SSID(0));

   // delay (10);

   myNextion.setComponentText("t11", WiFi.SSID(1));

   // delay (10);

   myNextion.setComponentText("t12", WiFi.SSID(2)); 


If I am on the page where the above fields are I get a  clean write. If on another page and move to this page they are not there


I assume that this has something to do with the refresh, but I would have thought that if they are global then the value would have been picked up as soon as the page is selected.

In this context can someone please explain pre and postinitialize event for a page



Any green bold component attribute in the Editor gets an auto-refresh on all changes.


The Nextion Instruction Set gives a lot of insight into the commands


t10 is being a Text component? or a Variable component? ...

in the instruction set, you will see t10.txt="text" no spaces is a correct format.

I am not an Arduino user, so I send t10.text="text" over serial, I think Arduino has a serial.write?


Every time a page is entered, there is a Pre-initialized Event (that code gets run), then next up is the Design that was declared in your HMI file (values get initialized to design time settings), then next up is the Post-initialize Event (this code gets run).


I lost all that I typed before, so this will be the condensed version.  Remember Pre-Design-Post.


So Global for a text component means that its value can be set or retrieved from another page. You have to keep track of its states in the way you design your project.  So I am on Page3, a user setting was on Page2.  I can on Page3 set Text component t10 to the value from Page2 Text Component user2 using


t10.txt=Page2.user2.txt


Still remember Pre-Design-Post, so as the user changes Pages into Page2, the Visual Text Component will be reset to the design value.  If you were to have a non-visual Variable component sitting on Page0 called user2 (sta text, and vscope global) then in a pre-init you could copy values somewhere, (design time reset occurs) and in the Post-init you can retrieve t10.txt=Page0.user.txt


Or on your Arduino you could simply track the page the user is on, and when you user changes into the page, set the t10 text value using a serial write (t10.txt="value")


Hope this was at least somewhat helpful


Hi, I know this is an old topic but I I think is not necessaryto create a new one.

 

I am working in a project with a Nextion Screen and I have read several posts about global variables and the Pre-initialized and Post-initialize events.

 

But cheking my code I realised that I have some global variables in page 0 that I have changed since page 1 and when I return to page 0 again and the load of the HMI design occurs, thouse variables aren´t return to the design values.

 

Example:

 

I have a botton b0 in page 0 with the txt component "Select time" in HMI design and the botton b1 in page 1

 

Tounch release event of b1 on page 1 change the text of b0 in page 0 and return to page 0:

 

page0.b0.txt="10 minutes"

page 0

 

When the page chage to page 0 and the charge of HMI design values occurs, the text of b0 must change to the HMI design value that is "Select time" if there is not code that save the value in the preinitialize event and charge it again in post initialized event.

 

But the value of b0.txt is in page 0 is "10 minutes" not the HMI design value of "Select time"

 

It has been a change in the way the global variables and the pre-initialize events, the charge of HMI design values and the Post-Initialize events works?

 

I´m using Nextion Editor v 0.50 and a screen NX4024T032_011



no

Any idea of why the global variables didn't return to the design values in this case?

Sure. 

Firmware was much older then.  vscope Global only stored .val or .txt attributes.

Firmware has evolved.  See new forum:

Basic Understandings for Designing a Nextion HMI - Nextion Order of Events



Also user was implementing from MCU side and not fully qualifying variable.

Called in a local convention, was not available as local did not exist on current page.

User also used non-Itead Library that is now super old.

Ok. I found the topic in the new forum. Thanks a lot.