Referencing event target within handler

My HMI has about 50 buttons across multiple screens, all with nice objnames that are descriptive and unique. I would like the screen to notify my microcontroller each time one is pressed.

I would like my handlers to contain something like:

prints this.objname,32

Of course this doesn’t work. I also tried .objname, self.objname, target.objname, and similar, but none worked.

So instead I have made each button handler contain a literal string that matches its objname. This works but is redundant, probe to typos, etc.

prints "bStopMachine",32

Is there a better way?

Background

I’m new to Nextion and want to use it with esp32 using the esp-idf. I prefer to keep most of the smarts in the microcontroller, and have all buttons trigger a handler on the microcontroller. It’s straightforward to communicate with the Nextion over serial, but I’m looking for a simple way to make the Nextion publish these events over serial.

I know I can use the button ids, but there are some pretty major problems with that:

  • Microcontroller needs a huge mapping of arbitrary ids to semantic labels. It would be nice if it sent the objname which is already a nice semantic label
  • Deleting an object renumbers all ids on that page, so the mapping would need to manually be updated!
  • ids are only unique to a page, so the microcontroller needs to also keep a stateful representation of the current screen state and monitor page state transitions. :face_vomiting:

Am I missing something? What does everyone else do?