Arduino Mega send data to ESP8266-01 then ESP forward to RPI (MQTT)

So it looks like to me that all I have to do is write a code for the esp to read the incoming data and then send it to an IP address and that I can leave my code alone that is on the Mega.