Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

myNex.readNumber() #2

Closed
axelpablo opened this issue Apr 13, 2020 · 17 comments
Closed

myNex.readNumber() #2

axelpablo opened this issue Apr 13, 2020 · 17 comments

Comments

@axelpablo
Copy link

In my case i have a Variable in nextion(ntu).
ntu.val=489
In Arduino code:
uint32_t number = 0;
number = myNex.readNumber("ntu.val");
Serial.println(number);

But the output(Serial.println(number);) is "4294967066".
Not the real val(489).

@Seithan
Copy link
Owner

Seithan commented Apr 13, 2020

Check that the number component that you ask for its value is on the current loaded page.
you can see at ChangePagesAndSendFloatValues example how you can use the myNex.currentPageId
and keep the sketch code synchronized with Nextion page.
For get the value of a numeric component from a page that is not loaded you must turn it to global scope and access it with a refer to page name:

number = myNex.readNumber("pageName.n0.val");

The folowing is from the Nextion Editor Guide

In an HMI project a page is a localized unit. When changing pages, the
existing page is removed from memory and the requested page is then
loaded into memory. As such components with a variable scope of local
are only accessible while the page they are in is currently loaded.
Components within a page that have a variable scope of global are
accessible by prefixing the page name to the global component
.objname.

As an Example: A global Number component n0 on page1 is accessed by
page1.n0. A local Number component n0 on page1 can be accessed by
page1.n0 or n0, but there is little sense to try access a local
component if the page is not loaded. Only the component attributes of
a global component are kept in memory. Event code is never global in
nature.

@Seithan
Copy link
Owner

Seithan commented Apr 13, 2020

I made some changes to the .cpp file in order to have a return of 7777 at readNumber() function and for the case that Nextion hasn't sent the data we want. This is going to cover the case of asking to read a number from a page that is not loaded. You can try it and see if it covers your needs.
Thank you for opening an issue and letting me know something that I may not had noticed.
If you do not need anything else for this issue, please close it.

@axelpablo
Copy link
Author

Thanks
I have change .ccp file with the new version.
In nextion,is open page2,and with pciture in this page i send command("printh 23 02 54 03")
In same page i have "Number" component(ntu.val),with value is "574"
In the Arduino code:
void trigger3(){
uint32_t number = 0;
number = myNex.readNumber("page2.ntu.val");
Serial.println(number);
}
But the output is "page2.ntu.val⸮⸮⸮4294967066".
(But the real value in nextion is "574".

@axelpablo
Copy link
Author

And all component are set to global.(ntu,picture,...)

@axelpablo
Copy link
Author

I have try to change val of ntu.
But the output in Serial.println,is always "print page2.ntu.val⸮⸮⸮4294967066".

@axelpablo
Copy link
Author

axelpablo commented Apr 13, 2020

I have remove from Touch Release Event of picture(use for send command),the code: page page0.
And now it work "myNex.readNumber("page2.nut.val")"!

But always first time it give me the real value.
In the next "myNex.readNumber("page2.nut.val")" it give me always 7777.
This the output:
page page1⸮⸮⸮page page2⸮⸮⸮printh 23 05 52⸮⸮⸮print page2.ntu.val⸮⸮⸮574
printh 23 05 52⸮⸮⸮print page2.ntu.val⸮⸮⸮7777
printh 23 05 52⸮⸮⸮print page2.ntu.val⸮⸮⸮7777
printh 23 05 52⸮⸮⸮print page2.ntu.val⸮⸮⸮7777
printh 23 05 52⸮⸮⸮print page2.ntu.val⸮⸮⸮7777

@Seithan
Copy link
Owner

Seithan commented Apr 13, 2020

Sorry that I miss it before.
As I can see you configure the Library to use the Serial ( Serial):

EasyNex myNex(Serial);

and to the trigger3() function

void trigger3(){
uint32_t number = 0;
number = myNex.readNumber("page2.ntu.val");
Serial.println(number);
}

you call the Serial and you are sending a println for the number variable, I'm guessing that the Serial is connected on Nextion and if I'm guessing right then you send to Nextion an unknown command.
If you want to check, for debug reasons, that the value of ntu.val is the right one and that there is no problem with reading the components value :
Create a new temporary numeric component on the page that is loaded. Supposing that the name of the new numeric is n22 then format the trigger3() fuction like this:

void trigger3(){
uint32_t number = 0;
number = myNex.readNumber("page2.ntu.val");
//Serial.println(number);
myNex.writeNum("n22.val", number);
}

Now you are going to see the number that is listed on ntu

@axelpablo
Copy link
Author

Thanks for your help.
I've solved with this code:

uint32_t number = 0;
uint32_t lastnumber = 0;
void trigger3(){
number = myNex.readNumber("page2.ntu.val"); 
if(number != 7777){       // 7777 is the return value if the code fails to read the new value
  lastnumber = number;
} else if(number == 7777){
    number = lastnumber;
}
   Serial.println(number);  
}

You think is correct with this?
It work.

@Seithan
Copy link
Owner

Seithan commented Apr 13, 2020

This is a way to confirm that the reading of the the value doesn't fail.
Try the code that I was sent you before to see the value on the display and tell me if you have the right value.
Can you please tell me where are you sending the number with the Serial.println(number); ?
and where you are viewing it ?

@axelpablo
Copy link
Author

Can you please tell me where are you sending the number with the Serial.println(number); ?
and where you are viewing it ?
In serial monitor,in Arduino IDE.

@axelpablo
Copy link
Author

Is possible to read a text from Text component in Nextion ?

@Seithan
Copy link
Owner

Seithan commented Apr 13, 2020

No, I haven't add this feature as I thing that the usage is almost unnecessary as a Display is most for display message and not to sent text to MCU, I tried hard to put as less functions as possible.
The profit of adding this function is small in front of keep the simplicity.

@Seithan
Copy link
Owner

Seithan commented Apr 13, 2020

but if someone need to send text, he can do it, using the custom protocol

@axelpablo
Copy link
Author

okok,thanks.
If i want print "number" in Text component in Nextion,is possible convert it ?
I see "number" is a uint32_t.

And not possible with:
myNex.writeStr("tTEMPSET.txt", number);

@Seithan
Copy link
Owner

Seithan commented Apr 13, 2020

This is from the example ChangePagesAndSendFloatValues it is for float but uint is the same

String tempString = String(temperature, 1); // Convert the float value to String, in order to send it to t0 textbox on Nextion
    myNex.writeStr("t0.txt", tempString);       //Write the String value to t0 Textbox component

@Seithan
Copy link
Owner

Seithan commented Apr 13, 2020

Im going to add a case for this, on the write text example

@axelpablo
Copy link
Author

Thanks,it work.
Thanks for the help and congratulations for this library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants