ESP8266 read by Rx data by IR using and sending data via wifi

0

Greetings I have a project, I need to get the data sent by IR through the module D1 mini that I own and send them to my cell via wifi I did it as a webservice I have the code already done but it does not work, it does not read if someone could help me, This is my code:

#include <ESP8266WiFi.h>
const char* ssid = "WHF";
const char* password = "prueba123";
String num="";
String dig="";
String ReadString="";
String req="";
WiFiClient client;
bool cont=false;
// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);

void setup() {
Serial.begin(1200);
delay(10);

// prepare GPIO14
pinMode(14, OUTPUT);
digitalWrite(14, 0);

// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");

// Start the server
server.begin();
Serial.println("Server started");

// Print the IP address
Serial.println(WiFi.localIP());

}

void loop() {
//Leer desde el IR Reciver por Rx  
if (Serial.available()>0);
{
ReadString=Serial.readString();
cont=ReadString.startsWith("ABC");
if(cont){
Serial.println(ReadString);
num = ReadString.substring(5,10);
}
}
// Check if a client has connected
client = server.available();
if (!client) {
 return;
}

// Wait until the client sends some data
Serial.println("new client");
while (!client.available()) {
delay(1);
}

// Read the first line of the request
req = client.readStringUntil('\r');
Serial.println(req);
client.flush();
// Match the request
int val;
if (req.indexOf("/gpio/0") != -1) {
val = 0;
} else if (req.indexOf("/gpio/1") != -1) {
  val = 1;
} else {
Serial.println("invalid request");
client.stop();
return;
}

// Set GPIO14 according to the request
digitalWrite(14, val);
client.flush();

// Prepare the response
String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r     
\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ";
s += (val) ? "high" : "low";
s += num;
s += "</html>\n";

// Send the response to the client
client.print(s);
delay(1);
Serial.println("Client disonnected");

// The client will actually be disconnected
// when the function returns and 'client' object is detroyed
}

and first of all thank you.

    
asked by Senly Martin Geronimo 30.09.2018 в 15:49
source

0 answers