I am using Ir sensor with arduino uno.Through esp8266-01 i successfully send status of IR sensor (i.e Clear and Obstacle) to phpmyadmin database created using xampp control panel.I am using AT command to send data from arduino to database.Now I want my arduino to fetch data from phpmyadmin database and change the status of Led light.How to get response from server using AT command and accordingly change status of sensor.
Arduino code
#include <SoftwareSerial.h>
#define RX 10
#define TX 11
String AP = "Tenda_2704A8";
String PASS = "********";
String Data;
int countTrueCommand;
int countTimeCommand;
boolean found = false;
int LED = 13; // Use the onboard Uno LED
int isObstaclePin = 7; // This is our input pin
int isObstacle = HIGH; // HIGH MEANS NO OBSTACLE
SoftwareSerial esp8266(RX, TX);
void setup() {
pinMode(LED, OUTPUT);
pinMode(isObstaclePin, INPUT);
Serial.begin(9600);
esp8266.begin(115200);
sendCommand("AT", 5, "OK");
sendCommand("AT+CWMODE=1", 5, "OK");
sendCommand("AT+CWJAP=\"" + AP + "\",\"" + PASS + "\"", 20, "OK");
}
void loop() {
String output;
isObstacle = digitalRead(isObstaclePin);
if (isObstacle == LOW)
{
output = "obstacle";
Serial.println("OBSTACLE!!, OBSTACLE!!");
digitalWrite(LED, HIGH);
}
else
{
output = "clear";
Serial.println("clear");
digitalWrite(LED, LOW);
}
Data = "GET /project/ajax/arduino.php?value="+output;
sendCommand("AT+CIPMUX=1",5,"OK");
sendCommand("AT+CIPSTART=0,\"TCP\",\"192.168.0.104\",80",4,"OK");
sendCommand("AT+CIPSEND=0," +String(Data.length()+4),2,">");
esp8266.println(Data);delay(100);countTrueCommand++;
sendCommand("AT+CIPCLOSE=0",2,"OK");
}
void sendCommand(String command, int maxTime, char readReplay[]) {
Serial.print(countTrueCommand);
Serial.print(". at command => ");
Serial.print(command);
Serial.print(" ");
while (countTimeCommand < (maxTime * 1))
{
esp8266.println(command);//at+cipsend
if (esp8266.find(readReplay)) //ok
{
found = true;
break;
}
countTimeCommand++;
}
if (found == true)
{
Serial.println("Yes");
countTrueCommand++;
countTimeCommand = 0;
}
if (found == false)
{
Serial.println("Fail");
countTrueCommand = 0;
countTimeCommand = 0;
}
found = false;
}