No Output On The Serial Monitor

I’m trying to send a String from the ESP8266 TO an Arduino. The string is collected with a GET request and this works. BUT whenever I try to send this String to an Arduino over Serial, I get a blank screen.

This is the code for the ESP8266:

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

HTTPClient http; 
SoftwareSerial NodeMCU(D7,D8);


const char* ssid = "dummy data";
const char* password = "dummy data";
 
void setup () {
   pinMode(D7,INPUT);
   pinMode(D8,OUTPUT);
   
   Serial.begin(9600);
   NodeMCU.begin(9600);
   
   WiFi.begin(ssid, password);
}




void sendDataToArduino() {
    
      http.begin("http://test.com/test/api/data/1"); 
      http.addHeader("Content-Type", "application/json"); 
      int httpCode = http.GET();
      String payload = http.getString(); //Get the request response payload
      NodeMCU.print("<"); 
      NodeMCU.println(payload); 
      NodeMCU.print(">"); 
      delay(1000);
    
}

 
void loop() {
 
    sendDataToArduino();
 
}

This is the code for the Arduino:

#include <ArduinoJson.h>
#include <SoftwareSerial.h>
SoftwareSerial ArduinoUno(2, 3); // RX | TX

const byte numChars = 94;
char receivedChars[numChars];
boolean newData = false;

void setup() {

  pinMode(2,INPUT);
  pinMode(3,OUTPUT);
  
  Serial.begin(9600);
  ArduinoUno.begin(9600);  

 
}


void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char rc;
 
    while (ArduinoUno.available() > 0 && newData == false) {
        rc = ArduinoUno.read();

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                ndx++;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
                }
            }
            else {
                receivedChars[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newData = true;
            }
        }

        else if (rc == startMarker) {
            recvInProgress = true;
        }
    }
}

void printData() {
    if (newData == true) {
        Serial.println(receivedChars);
        newData = false;
    }
}


void loop() {
    recvWithStartEndMarkers();
    printData();
    
}

I’m not sure why it won’t work. Sending data the other way around (from arduino to esp) did work.

Your multiple posts on the same topic have been reported to the moderator.

The original is at http://forum.arduino.cc/index.php?topic=607370.msg4122853#msg4122853

STAY there!

Threads merged.

Hi,
Try by removing these lines;

 pinMode(2,INPUT);
 pinMode(3,OUTPUT);

The two pins are configured correctly when you declare the SoftwareSerial function.
Have you got 9600 baud setup in the monitor screen?

Tom.... :slight_smile: