Basically I created a web page to control 4 channel relay, then I made an HTTP get request from that page and got the following response:
Linked
T+CIPSEND=4,50
> GET /ard/sensor.html HTTP/1.1
Host: localho
SEND OK
+IPD,4,351:HTTP/1.1 200 OK
Date: Sat, 07 Apr 2018 01:22:58 GMT
Server: Apache/2.4.9 (Win32) PHP/5.5.12
Last-Modified: Sat, 07 Apr 2018 01:17:13 GMT
ETag: "72-56937eec1c277"
Accept-Ranges: bytes
Content-Length: 114
Content-Type: text/html
<p> Relay1 = 1# </p> </br>
<p> Relay2 = 0# </p> </br>
<p> Relay3 = 0# </p> </br>
<p> Relay4 = 1# </p> </br>
OK
OK
Unlink
Now I want to store Relay1 status (which is 1 here) in a variable, also all other Relays in order to control them high or low Note : # is supposed to be the separator and here is my code:
#include <SoftwareSerial.h>
const int LED_PIN = 13;
String ssid = "ABC";
String password = "a14102016a";
const byte rxPin = 6;
const byte txPin = 7;
SoftwareSerial ESP8266 (rxPin, txPin);
unsigned long lastTimeMillis = 0;
void setup() {
Serial.begin(9600);
ESP8266.begin(9600);
reset();
connectWifi();
delay(2000);
}
//reset the esp8266 module
void reset() {
ESP8266.println("AT+RST");
ESP8266.println("AT+CIOBAUD=9600");
delay(1000);
if (ESP8266.find("OK") ) Serial.println("Module Reset");
}
//connect to your wifi network
void connectWifi() {
String cmd = "AT+CWJAP=\"" + ssid + "\",\"" + password + "\"";
ESP8266.println(cmd);
delay(4000);
if (ESP8266.find("OK")) {
Serial.println("Connected!");
}
else {
connectWifi();
Serial.println("connect to wifi");
}
}
void printResponse() {
while (ESP8266.available()) {
Serial.println(ESP8266.readStringUntil('\n'));
}
}
void loop() {
if (millis() - lastTimeMillis > 30000) {
lastTimeMillis = millis();
ESP8266.println("AT+CIPMUX=1");
delay(1000);
printResponse();
ESP8266.println("AT+CIPSTART=4,\"TCP\",\"192.168.1.161\",80");
delay(1000);
printResponse();
String cmd = "GET /ard/sensor.html HTTP/1.1\r\nHost: localhost";
ESP8266.println("AT+CIPSEND=4," + String(cmd.length() + 4));
delay(1000);
ESP8266.println(cmd);
delay(1000);
ESP8266.println("");
}
if (ESP8266.available()) {
Serial.write(ESP8266.read());
Byte R[ ] = ESP8266.read () ;
Serial write (R[ ]);
// if (readString.indexOf("Relay1=1">0))
{
Serial.write("found");
}
}
}
Any suggestions ?
1001