oibdrew:
I did read it before and I just read it again. I don't understand how one code can make the Esp read DHT data from the Mega and send it to a specified address such as a RPI. I get the connections but I would imagine that the ESP would have its own code separate from the code on the Mega.
Of course. You write one code for the Mega that reads the sensors then formats and send the data over serial to the ESP. You write another code for the ESP that receives the data and sends it wherever it needs to go. You can write the code for both processors using the Arduino IDE.
Since you seem to already have code for the sensors and MQTT, why don’t just work on a simple set of codes for the Mega and ESP that does nothing but pass data back and forth over a serial interface? Once you get that working, you can worry about integrating it back into your other application code.