Connect esp node mcu 32s to arduino mega through wifi

Hello, I am trying to connect esp node mcu 32s to arduino mega through wifi by using wifi module to the arduino and send data form mpu6050 that is connected to esp,to control robotic arm,I am still at the beginning and lost with the code, can anyone guide me how to do it

I moved your topic to an appropriate forum category @mohamedyasserr.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

what WiFi module do you have on the Mega?

Esp01s,esp8266 wifi

why not connect the MPU6050 to the Mega ? you then don't require the ESP01

Bec the robotic arm will be controlled by mpu6050 that will be placed on my hand so i have to do it with another microcontroller and send the data , till now i did it by uart but , i want to do it wireless through wifi or beletouth, can't decide till now

https://github.com/JAndrassy/WiFiEspAT#getting-started

replace the Mega with an ESP32 device ? you could then use Bluetooth, BLE or WiFi to communicate between the devices

It isTo late now the robotic arm is setup with the mega

Do u know where can i look it up that someone did something similar, communication between esp node mcu 32s and mega , Bluetooth or wifi

Thanks, i will look into it

it is certainly possible to connect a ESP-01S to a mega
the ESP-01 uses 3.3V logic and the Mega 5V so you require a potential divider on the Mega serial Tx output to the ESP-01 Rx input, e.g. using Mega Serial1

the serial data transmitted by the Mega is transmitted to the Serial of the ESP-01, e.g. using the WiFiEspAT library as suggested in post 8 by @Juraj

Then i will be able to send data form esp nodemcu 32s to the mega, which is easier to make it with wifi or Bluetooth?, thanks alot

the ESP-01 only supports WiFi not Bluetooth
I have not used WiFiEspAT library so cannot recommend which is the simplest approach to use
I would tend to use ESP-NOW on both ESP-01 and ESP32 but that would require you programming the ESP-01 which is not simple

Yeah i mean i can get Bluetooth module that can be connected to arduino mega and then try to make communication between esp node mcu 32s and arduino mega via Bluetooth instead of wifi, but i still can't make decision

You need to check out examples of #8 link

Wifi client example (Arduino mega)

/*
  Web client

 This sketch connects to https
 using the WiFi module.

 created 13 July 2010
 by dlf (Metodo2 srl)
 modified 31 May 2012
 by Tom Igoe
 modified in Jul 2019 for WiFiEspAT library
 by Juraj Andrassy https://github.com/jandrassy
 */

#include <WiFiEspAT.h>

const char* server = "api.github.com";

WiFiSSLClient client;

void setup() {
  Serial.begin(115200);
  while (!Serial);

  Serial1.begin(115200);
  WiFi.init(Serial1);

  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println();
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  // waiting for connection to Wifi network set with the SetupWiFiConnection sketch
  Serial.println("Waiting for connection to WiFi");
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print('.');
  }
  Serial.println();
  Serial.println("Connected to WiFi network.");

  Serial.println("Starting connection to server...");
  if (client.connect(server, 443)) { // port 443 is the default https port
    Serial.println("connected to server");

    client.println("GET /repos/jandrassy/WiFiEspAT/commits/master/status HTTP/1.1");
    client.print("Host: ");
    client.println(server);
    client.println("User-Agent: Arduino");
    client.println("Connection: close");
    client.println();
    client.flush();
  }
}

void loop() {

  // if there are incoming bytes available
  // from the server, read them and print them
  while (client.available()) {
    char c = client.read();
    Serial.write(c);
  }

  // if the server's disconnected, stop the client
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting from server.");
    client.stop();

    // do nothing forevermore
    while (true);
  }
}

Example for wifi server (node MCU 32 in your case)

/*
  WiFi Web Server

 A simple web server that shows the value of the analog input pins.

 created 13 July 2010
 by dlf (Metodo2 srl)
 modified 31 May 2012
 by Tom Igoe
 modified in Jul 2019 for WiFiEspAT library
 by Juraj Andrassy https://github.com/jandrassy
 */

#include <WiFiEspAT.h>

// Emulate Serial1 on pins 6/7 if not present
#if defined(ARDUINO_ARCH_AVR) && !defined(HAVE_HWSERIAL1)
#include <SoftwareSerial.h>
SoftwareSerial Serial1(6, 7); // RX, TX
#define AT_BAUD_RATE 9600
#else
#define AT_BAUD_RATE 115200
#endif

WiFiServer server(80);

void setup() {

  Serial.begin(115200);
  while (!Serial);

  Serial1.begin(AT_BAUD_RATE);
  WiFi.init(Serial1);

  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  // waiting for connection to Wifi network set with the SetupWiFiConnection sketch
  Serial.println("Waiting for connection to WiFi");
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print('.');
  }
  Serial.println();

  server.begin();

  IPAddress ip = WiFi.localIP();
  Serial.println();
  Serial.println("Connected to WiFi network.");
  Serial.print("To access the server, enter \"http://");
  Serial.print(ip);
  Serial.println("/\" in web browser.");
}

void loop() {

  WiFiClient client = server.available();
  if (client) {
    IPAddress ip = client.remoteIP();
    Serial.print("new client ");
    Serial.println(ip);

    while (client.connected()) {
      if (client.available()) {
        String line = client.readStringUntil('\n');
        line.trim();
        Serial.println(line);

        // if you've gotten to the end of the HTTP header (the line is blank),
        // the http request has ended, so you can send a reply
        if (line.length() == 0) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of analog input pins
          for (int analogChannel = 0; analogChannel < 4; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("<br />");
          }
          client.println("</html>");
          client.flush();
          break;
        }
      }
    }

    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}

this code doesn't compile with esp node mcu 32s

it is for Mega with esp8266 with AT firmware connected

oh, he said this for node MCU 32 in your case, so how i can send this data from esp to Ardunio through wifi, i cant find anything till now