In your previous attempts at posting about this issue you said that you were using a NodeMCU with the Mega. You now say that it’s an ESP-01.
If you are using a ESP-01 with your Mega then reading this might help to point you in the right direction…
Pete.