After I try many week, now it works. Follow this if you have the same to my cases:
-
programm to the ESP(upload sketch) for wifi connection by configure the DIP to 5:on,6:on,7:on and other off.
-
program to mega(upload sketch) in case you want to send communication to each other by configure Dip to 3:on,4:on, and other off.
-
switch two RX0/TX0(in my case I use Serial.print() and Serial.readString() for communicate between Esp and Mega)
-
after you already upload sketch to both Modules you can test communication between them by configure DIP to: 1:on,2:on,3:on,4:on. and then press Reset Button to restart the boards.
-
In ESP you can get the string from Mega by if(Serial.available()) Serial.readString(); and In mega you can get data from ESP by : if(Serial.available())Serial.readString().
-
After you got a string so you can split or do anything whatever you want.
-
If you want send data to Firebase you must use the Firebase Library at the Esp side, in Mega it not support.
*** This work for me, I hope it can help you. Good luck.