I am trying to connect my arduino mega to esp8266 and get the data throught web using this code but it is not showing on the web and not working

MEGA CODE:
#include <SoftwareSerial.h>

#define RX_PIN 19 // Arduino RX pin
#define TX_PIN 18// Arduino TX pin

SoftwareSerial espSerial(RX_PIN, TX_PIN); // RX, TX

String wave = "95";
String pulse = "50";
String status = "On";

void setup() {
Serial.begin(115200);
espSerial.begin(115200); // Initialize software serial communication with ESP8266
}
void loop() {
// Construct the message to send to ESP8266
String dataFromArduino = "wave=" + wave + "&pulse=" + pulse + "&status=" + status;

// Send the message over serial to ESP8266
espSerial.println(dataFromArduino);
Serial.println(dataFromArduino);

delay(5000); // Adjust delay according to your needs
}
ESP CODE
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <SoftwareSerial.h>

ESP8266WiFiMulti WiFiMulti;

const char* ssid = "ssid";
const char* password = "password";

#define RX_PIN 3 // GPIO pin to which TX of Arduino is connected
#define TX_PIN 1 // GPIO pin to which RX of Arduino is connected

SoftwareSerial arduinoSerial(RX_PIN, TX_PIN); // RX, TX

void setup() {
Serial.begin(115200);
arduinoSerial.begin(115200); // Initialize software serial communication with Arduino

for (uint8_t t = 4; t > 0; t--) {
    arduinoSerial.printf("[SETUP] WAIT %d...\n", t);
    delay(1000);
}

WiFi.mode(WIFI_STA);
WiFiMulti.addAP(ssid, password);

}

void loop() {
if (Serial.available() > 0) {
String dataFromArduino = arduinoSerial.readStringUntil('\n'); // Read data from Arduino until newline character
arduinoSerial.println("Received data from Arduino:");
arduinoSerial.println(dataFromArduino);

    // Wait for WiFi connection
    if (WiFiMulti.run() == WL_CONNECTED) {
        WiFiClient client;
        HTTPClient http;

        arduinoSerial.print("[HTTP] begin...\n");
        String url = "http://192.168.1.39/ESP/get_data.php?" + dataFromArduino;
        arduinoSerial.println("URL: " + url);

        if (http.begin(client, url)) {
            arduinoSerial.print("[HTTP] GET...\n");
            // start connection and send HTTP header
            int httpCode = http.GET();
            // httpCode will be negative on error
            if (httpCode > 0) {
                // HTTP header has been sent and Server response header has been handled
                arduinoSerial.printf("[HTTP] GET... code: %d\n", httpCode);
                // file found at the server
                if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
                    String payload = http.getString();
                    arduinoSerial.println(payload);
                }
            } else {
                arduinoSerial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
            }
            http.end();
        } else {
            arduinoSerial.println("[HTTP] Unable to connect");
        }
    } else {
        arduinoSerial.println("WiFi not connected");
    }

    delay(10000);
}

}

Hi @haroldmacuha

welcome to the arduino-forum.

I'm pretty sure that you agree and will follow the way how to solve your problem mimimum 200 minutes faster. This requires to invest 20 minutes of your precious time to read how to speedup solving your problems.

Directly after registering you got presented informations how to speed up solving your problem.
You should really read it.

Most important thing is to post your code formatted with a non-proportional font as a so called code-section.
The better you follow the forum-rules the better and faster help you will get

best regards Stefan

"I am trying to connect my arduino mega to esp8266 and get the data throught web using this code but it is not showing on the web and not working"

Yes that is possible but with the gibberish you posted it is not worth the time it takes to read it. Ask yourself why would I spend precious time trying to figure out what you have when you could not take a few minutes and read the forum guidelines and follow the instructions on how to post the code.

Also post an annotated schematic showing all connection and links to technical data on any other hardware connected including power sources.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.