Serial and client print confusion - ESP8266 & Arduino

Hi guys.

Im currently programming a device to send a command via serial to an Arduino when it receives the corresponding request form the web client.

I originally used GPIO pins as triggers for the arduino but it’s come to the point when i want to send ricther communication between the devices (alarm time, conformations ect).

I am using serial.print and client.print but every time a request is sent from the browser ("/BLIND=OPEN") it is sending “GET /BLIND=OPEN HTTP/1.1” to the serial monitor along with what i requested via serial.print.

I have tried changing the baud rate and the code but i can’t seem to stop it happening :angry:

my code is:

#include <ESP8266WiFi.h>

const char* ssid = “…”;
const char* password = “…”;

int ledStatus = 15;
int iPosSet = 0;
int iLoop = 0;
int Config = 1;
int request = 0;
WiFiServer server(80);

void setup() {
Serial.begin(115200);
pinMode(ledStatus, OUTPUT);
digitalWrite(ledStatus, LOW);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
digitalWrite(ledStatus, HIGH);
delay(1000);
digitalWrite(ledStatus, LOW);
delay(1000);
}
server.begin();
}
void loop() {

WiFiClient client = server.available();
if (!client) {
return;
}
while(!client.available()){
delay(1);
}
String request = client.readStringUntil(’\r’);
Serial.println(request);
client.flush();

if (request.indexOf("/BLIND=OPEN") != -1&& iLoop == 1) {
Serial.println(‘2’);
}
if (request.indexOf("/BLIND=CLOSE") != -1&& iLoop == 1) {
Serial.println(‘3’);
}
client.println(“HTTP/1.1 200 OK”);
client.println(“Content-Type: text/html”);
client.println(""); // do not forget this one
client.println("");
client.println("");

client.print(“Blind Controls”);

client.println("

“);
client.println(”<a href="/BLIND=OPEN"">Open Blind “);
client.println(”<a href="/BLIND=CLOSE"">Close Blind
“);
client.println(”");

delay(1);

iLoop = 1;

}

luke725:
Hi guys.

Im currently programming a device to send a command via serial to an Arduino when it receives the corresponding request form the web client.

I originally used GPIO pins as triggers for the arduino but it’s come to the point when i want to send ricther communication between the devices (alarm time, conformations ect).

I am using serial.print and client.print but every time a request is sent from the browser ("/BLIND=OPEN") it is sending “GET /BLIND=OPEN HTTP/1.1” to the serial monitor along with what i requested via serial.print.

I have tried changing the baud rate and the code but i can’t seem to stop it happening :angry:

my code is:

#include <ESP8266WiFi.h>

const char* ssid = “…”;
const char* password = “…”;

int ledStatus = 15;
int iPosSet = 0;
int iLoop = 0;
int Config = 1;
int request = 0;
WiFiServer server(80);

void setup() {
 Serial.begin(115200);
 pinMode(ledStatus, OUTPUT);
 digitalWrite(ledStatus, LOW);
 
 WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
   digitalWrite(ledStatus, HIGH);
   delay(1000);
   digitalWrite(ledStatus, LOW);
   delay(1000);
 }
 server.begin();
}
void loop() {

WiFiClient client = server.available();
 if (!client) {
   return;
 }
 while(!client.available()){
   delay(1);
 }
   String request = client.readStringUntil(’\r’);
     Serial.println(request);
     client.flush();

if (request.indexOf("/BLIND=OPEN") != -1&& iLoop == 1)  {
   Serial.println(‘2’);
 }
 if (request.indexOf("/BLIND=CLOSE") != -1&& iLoop == 1) {
  Serial.println(‘3’);
 }
   client.println(“HTTP/1.1 200 OK”);
   client.println(“Content-Type: text/html”);
   client.println(""); //  do not forget this one
   client.println("");
   client.println("");

client.print(“Blind Controls”);

client.println("

“);
 client.println(”<a href="/BLIND=OPEN"">Open Blind “);
 client.println(”<a href="/BLIND=CLOSE"">Close Blind
“);
 client.println(”");

delay(1);
 
 iLoop = 1;

}

Serial() uses pins 0, and 1 to communicate with your PC. Your WiFi client/server is also using Serial() to communicate with the ESP8266.

You are going to have to use either SoftwareSerial() on different pins to communicate with the ESP8266, or use a MEGA that has 4 HardwareSerial ports (Serial(),Serial1(),Serial2(),Serial3()).

I do not know if SoftwareSerial() can keep up at 115200 baud. Personally I would Just use a MEGA.

If you are “programming” the ESP8266, you could use I2C communications, Have the ESP act as master, the Arduino as slave. You would be limited to 32 byte messages. Since the Arduino is the slave, it cannot initiate an I2C message, so the ESP8266 would need to either frequently poll(Wire.requestFrom()) the arduino. Or you could use a GPIO pin as a message flag. The ESP8266 would then poll the arduino.

Chuck.