Start a new topic

Return objname from page and id?

I'm working on a project which will utilize the ESP8266 as an MQTT-to-Nextion gateway, allowing a Nextion panel to be controlled and interacted with via MQTT messages commonly used by IoT platforms.  Here is an early look at that effort, including 3D printer models to mount a 2.4" Nextion panel into a standard work box to replace a light switch: https://github.com/aderusha/HASwitchPlate


Anyway, this project is different from a lot of normal Nextion work in that I'd like the user to be able to modify the HMI at will and then gateway all interactions over MQTT in a generic way.  Because of this, the ESP8266 won't know the details of the HMI at run time, it'll simply ferry messages back and forth.


The project makes heavy use of global values on each page, as the automation platform sends updates (like clock time or weather info or alarm status etc) whenever those changes happen, which might not align with the currently-displayed page.  This means the data is shown on the page when the user selects it without the automation system having to manually refresh the page contents.  


This works well, however it has a side-effect: because I'm using globals and setting values off-page, the incoming values are being sent using the object name like this: page1.button2.txt="11:45"


When a touch event happens, I receive the page number and object ID which I can then send back over MQTT.  I can also direct the user to utilize the "p[1].b[2].txt" notation and it will create a direct mapping between the two, and that works as expected.  I suspect this might be the direction I need to go.


However - what I'm wondering is if there is a way for me to send the user the object name (not the object ID) when I pick up a touch event (or whatever).  The Nextion sends me the page number and object number, and I'd like to look up the object name before sending that along to the user.


It looks like I can't do a 'get p[1].b[2].objname'.  Is there any other way for me to lookup the object name if I know the object ID?


No


1 person likes this

As always, a prompt and definitive response.  Thanks Patrick!

.objname is not user accessible via firmware at runtime.


However, as the HMI designer, the user already knows these when designing.

At compile time, they are static and unchanging

So if they wanted to create an MCU side lookup table - user decision.  No?


Two sides of the argument would be:

1) Effort and required space will usually dictate poor use of resources

2) Unused resources might as well be used, doing nothing anyways

So user decision


 - A hobbyist might, they don't pay for the time to do in cash




1 person likes this

But every design change, also means more table changes

- just throwing that out there

The intent is to allow the user to avoid having to work on the Arduino at all, they simply provide their MQTT broker information and flash the Arduino code to the ESP8266.  The Nextion HMI editor is now pretty straightforward for new users (and getting better every release!) and I want to accommodate any HMI design they might dream up.  If I could lookup the objname for the user I could allow them to send and receive object names and the same value would appear going in as it does coming out.  Without that lookup, the user can still send object names, but the response coming out from the panel is always going to be object ID (without forcing the user to learn Arduino and creating a lookup table).


I'm OK with this, I just wanted to make sure I wasn't missing anything.  I'm updating my code, documentation, and examples to switch everything over to Object ID and the result should still be a flexible gateway that won't require the user to learn C++.  Purely by coincidence I had been naming everything as p1b2 etc, having no idea that the p[1].b[2] thing existed until stumbling across it here in the forums, so that should make the transition much easier.


Thanks again for your help (and on a Sunday - DO YOU EVER SLEEP?)!

You should have discovered p[1].b[2] from examining the keyboard page sources. ;)


Sleep?  Recharge!  lol.



1 person likes this
Login or Signup to post a comment