Smart irrigation with Arduino Mega + ESP8266 + Cayenne

Hello,
I have created kind of smart irrigation system with Arduino Mega and sensors like described in high level schema picture attached.

Now I would like to extend my project with introducing ESP8266 as WiFi adapter and target is to finally connect to Cayenne (green marked in the picture)

Does anyone has experience with:

  1. How to connect Arduino Mega with ESP8266 NodeMCU using it as WiFi
  2. Working code example for ESP8266 would be appreciated

Many thanks.
Br,
Petar.
P.S. If someone is interested for already working part of project I am glad to share it.

you can connect the nodemcu directly to cayenne without the use of mega. here is the code Cayenne-MQTT-Arduino/examples/Connections/ESP8266 at master · myDevicesIoT/Cayenne-MQTT-Arduino · GitHub

Thx Shramik for your response.

Maybe I did not explain very well, but due to so many sensors and relay outputs, I need to have Arduino Mega 2560 connected.

So my idea would be to have next (as explained in picture in my initial post):

Sensors/Relays → Arduino Mega 2560 → ESP8266 nodeMCU v3 → Cayenne

Do you have exampe for this configuration?

Thx.

not sure about this but you can use a generic esp01.
Sensors/Relays → Arduino Mega 2560 → ESP01 → Cayenne

thx. Will try to figure out.