Problem with receiving data from nextion to esp32

Please send help with my school project. I cannot seem to get data from nextion to esp32(when I change page/press the button

Code

#include <Nextion.h>
#include <SPI.h>
#include <MFRC522.h>
#define RXD2 16
#define TXD2 17

String stringPage = "page page";
String stringPageS;
int Number;
int randomVals[10];
int currentdata;
int CurrentPage;

#define RST_PIN 22 // Configurable, see typical pin layout above
#define SS_PIN 5 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance

NexPage page2 = NexPage(2, 0, "page2"); // Page added as a touch event
NexButton b1 = NexButton(2, 3, "b1"); // Button added

void DisplayPage(int pg) {
stringPageS = stringPage + pg;
Serial2.print(stringPageS);
Serial2.write(0xFF);
Serial2.write(0xFF);
Serial2.write(0xFF);
}
//RFID
int readRFID() {
int RFID = 0;
// Look for new cards
while ( ! mfrc522.PICC_IsNewCardPresent());

// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
}
RFID = mfrc522.uid.uidByte[1]; //Read card value and store into the variable "RFID"
return RFID;
}

NexTouch *nex_listen_list[] =
{
&b1, // Button added
&page2, // Page added as a touch event
NULL // String terminated
};

void page2PushCallback(void *ptr) // If page 2 is loaded on the display, the following is going to execute:
{
CurrentPage = 2; // Set variable as 2 so from now on arduino knows page 2 is loaded on the display
} // End of press event

void b1PushCallback(void *ptr) // Press event for button b1
{
Serial.print("bye");
} // End of press event

void b1PopCallback(void *ptr) // Release event for button b1
{
Serial.print("hi");
} // End of release event

void setup() {
// put your setup code here, to run once:

nexInit();
Serial.begin(115200);
DisplayPage(0);
delay(2000);
DisplayPage(1);

page2.attachPush(page2PushCallback); // Page press event
b1.attachPush(b1PushCallback); // Button press
b1.attachPop(b1PopCallback); // Button release
}

void loop() {
nexLoop(nex_listen_list);
if (CurrentPage == 2) {
delay(3000);
Serial.println("hi");
}

}

Moved your topic to it's current location as it is more suitable.

Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Hello leedeen,

Welcome to the forum.

Support for Nextion on these fora is pretty much as follows:
You can follow the methods I set out in using Nextion displays with Arduino. My methods do not use the Nextion libraries, so while I am happy to offer help on using my methods I cannot offer anything very helpful for any Nextion library.
The original Nextion libraries are full of bugs. There is a link from my tutorial to some improved Nextion libraries created by Ray Livingston, I suggest those might be worth trying if you prefer to use a library.

There's also a separate tutorial on how to write code with Nextion and Arduino. by Seithan, his methods are different to mine, chose which works best for you.

You have posted long and complicated code with too many problems to list. The way to write code successfully is to break the problem into small steps and get each step working individually, then combine them into a bigger program to do what you want. I strongly suspect you have not done this.

Both the tutorials listed above, as well as the Nextion libraries, assume some basic knowledge of writing code on an Arduino. If, as I suspect, you don't have the basic knowledge then please work thorough the various introductory tutorials on this web site, in the IDE and elsewhere and learn how to do basic programming.

And please, read the instructions Ballscrewbob pointed out and post your code properly.

Enjoy.