It is also tricky which firmware is running on the ESP. Earlier ESP
firmware versions had issues.
Firmware version 1.0.0 (AT v0.22) or later is needed.
I have an ESP02 running fine, and ESP07, and ESP12s, but I have never tried
Also critical are the connections to the device. ESP12s require an external
capacitor to keep from resetting themselves. We have had users have issues
where they have I/O configured improperly, driving lines that are meant as
input, or the config bits are just not set right, so on boot up you get
unreliable mode selection.
The Mega has multiple serial ports. I would try and pass the output of your
ESP to the serial monitor and see what kind of error messages you are
getting back. There is also an Arduino IDE add on for interpreting those
messages you can install.