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;
}
If i understood your question you need add in your code ip server ex.192.168.1.4 In my test i have used this library #include WiFiClientSecure.h and wrote this code to receive response from my php file...(using esp8266)
//HTML
char servername[] = "192.168.1.4";
WiFiClient client; //library WiFiClientSecure
.....your code
void send(int temp, int hum) {
if (client.connect(servername, 80)) {
client.println(String("GET /myfolder/index.php?temp=") + temp + String("&hum=") + hum);
client.println("Host: servername");
client.println("Connection: close");
client.println("");
while (client.connected()) {
while (client.available()) {
Serial.write(client.read());//read the response that you receive...in this case on serial monitor
}
}
}
else {
Serial.println("connession faliled");
}
//stop the client
client.stop();
while (client.status() != 0) {
delay(5);
}
}
i hope that this is helpful
inother there is a link youtube that talk about arduino and mysql https://www.youtube.com/watch?v=6hi9Wf99hfg
I simply replaced arduino uno board with nodemcu esp8266.Using library like ESP8266HTTPCLIENT.H , ESP8266.H solved all my issue.Now I am able to fetch data from database or vice versa.