ESP8266 ESP-01 wifi is not receiving message from arduino

Hello.

I'm doing a project and I'm using a arduino uno, ESP8266 ESP-01 wifi and a PostgreSQL database.
I want that arduino sends a message to the wifi sensor and the wifi sensor needs to insert the data received in the database.
Once I'm a beginner with this sensor I followed a tutorial Tutorial page and the differences are that in the tutorial they are using the firebase and other sensors (Distance measuring sensor, Ultrasonic Distance Sensor) and I'm just using the PostgreSQL database.

1º I upload de code to the wifi sensor and I made the connection as shown in the tutorial;
2º I upload de code to the arduino;

My arduino code is a little different, because I was just doing a test to see if the arduino was sending the data to the wifi sensor.
But that is not happening. The arduino write the data in the monitor, but the wifi sensor is not answering.
I don't know why and how I can solve it.
Is someone there who can help me, please?

My code:

  • Arduino:
void setup() {

  //Initializes the serial connection at 9600 to sent sensor data to ESP8266.
  Serial.begin(9600);
}


void loop() {
  while (Serial.available()) {

    Serial.print("TEST");
    delay(2000);

  }
}
  • Wifi sensor:
#include <ESP8266WiFi.h>

#define WIFI_SSID "******"
#define WIFI_PASSWORD "******"

String sensor_data;

void setup() {
  //Initializes the serial connection at 9600 get sensor data from arduino.
  Serial.begin(9600);

  delay(1000);

  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);

  }

}
void loop() {

  while (Serial.available()) {

    //get sensor data from serial put in sensor_data
    sensor_data = Serial.readString();
    Serial.println("WIFI ANWSER: " + sensor_data);
  }

}

how did you wire them together?

Hi.

ESP8266:-------------- >Arduino:

GND -------------------------- GND

GPIO-0 (IO0)---------------------Not connected

GPIO-2 (IO2) -------------------- Not connected

RX -------------------------------- TX

TX --------------------------------- RX

CHPD (EN) ------------------------ 3.3V

RST -------------------------------- Not connected

VCC (3v3) -------------------------- 3.3V

for which board do you have the Serial Monitor open?

To the WiFi sensor

and then how do you send something to the Uno for while (Serial.available())?

Hi, your code and connections are correct, however, esp is bad for logging into serial monitor. You can try logging by sending a request to your server and debug the log there. I will put my working example here:
ESP Code:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <SoftwareSerial.h>

String ssid = "ssid";
String password = "pass";

// Server URL and endpoint
// See this utility that provides a mock server where you can see the requests https://webhook.site/
String serverURL = "http://webhook.site";
String endpoint = "/your-webhook-path";
String fullLink = serverURL + endpoint;

WiFiClient wifiClient;

void setupWifi() {
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
  }
}

void doRequest(String url) {
  if (WiFi.status() == WL_CONNECTED) {
    // Create an HTTPClient object
    HTTPClient http;

    http.setTimeout(10000);

    // Make a GET request to the server
    http.begin(wifiClient, url);
    int httpResponseCode = http.GET();

    if (httpResponseCode > 0) {
      String response = http.getString();
    } else {
    }

    // Close the connection
    http.end();
  }
}

void setup() {
  setupWifi();
  delay(1000);

  //Initializes the serial connection at 9600 to sent sensor data to ESP8266.
  Serial.begin(9600);

  doRequest(fullLink + String("?msg=SET+UP+ESP01"));
}

void loop() {
    while (Serial.available()) {
      String sensor_data = Serial.readString();
      doRequest(fullLink + String("?msg=WIFI+ANWSER:+") + sensor_data);
    }
}


Arduino Code

#include <SoftwareSerial.h>

void setup()
{
  Serial.begin(9600);
  Serial.print("Set up");
}

void loop()
{
  delay(2000);
  Serial.print("Alhamdu+llah");
}

Be sure to use print method rather than println because the esp will send a reqeust to a url with a new line in it which is not valid

BTW, your question helped me resolve the issue I was struggling with for days, so thanks!

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