Hello to everyone, i have an a question and I Didn´t Find a documentation about that
I'm programing a connected ESP8266 into my Arduino Uno. when i uses the GET method i can't read the response. here is my code
#include <SoftwareSerial.h>
#define DEBUG true
SoftwareSerial esp8266(7,6); // make RX Arduino line is pin 7, make TX Arduino line is pin 6.
// This means that you need to connect the TX line from the esp to the Arduino's pin 2
int senderdata=0;
String currentLine="";// and the RX line from the esp to the Arduino's pin 3
void setup()
{
Serial.begin(9600);
esp8266.begin(9600); // your esp's baud rate might be different
pinMode(11,OUTPUT);
digitalWrite(11,LOW);
pinMode(10,OUTPUT);
digitalWrite(10,LOW);
pinMode(12,OUTPUT);
digitalWrite(12,LOW);
sendData("AT+RST\r\n",2000,DEBUG); // reset module
sendData("AT+CWMODE=3\r\n",1000,DEBUG);
sendData("AT+CWJAP=\"D-link\",\"%123456789\"\r\n",1000,DEBUG);// configure as client
delay(10000);
sendData("AT+CIFSR\r\n",1000,DEBUG); // get ip address
}
void loop()
{
//sendData("POST /index.aspx HTTP/1.1\r\nHost: 192.168.0.14\r\nContent-Type: text/html\r\nContent-Length: 20\r\n\r\nToken=1234\r\n\r\n",1000,DEBUG);
if (senderdata==0){
sendData("AT+CIPSTART=\"TCP\",\"192.168.0.14\",80 \r\n",1000,DEBUG);
delay(1000);
sendData("AT+CIPSEND=63\r\n",1000,DEBUG);
delay(500);
sendData("GET /index.aspx?token=1234 HTTP/1.1\r\nHost: 192.168.0.14\r\n\r\n\r\n\r\n",1000,DEBUG);
//sendData("\r\n",1000,DEBUG);
delay(2000);
senderdata=1;
esp8266.find("pin=");
int pinNumber= esp8266.read();
Serial.println(pinNumber);
digitalWrite(pinNumber,HIGH);
}
}
/*
* Name: sendData
* Description: Function used to send data to ESP8266.
* Params: command - the data/command to send; timeout - the time to wait for a response; debug - print to Serial window?(true = yes, false = no)
* Returns: The response from the esp8266 (if there is a reponse)
*/
String sendData(String command, const int timeout, boolean debug)
{
String response = "";
esp8266.print(command); // send the read character to the esp8266
long int time = millis();
while( (time+timeout) > millis())
{
while(esp8266.available())
{
// The esp has data so display its output to the serial window
char c = esp8266.read(); // read the next character.
response+=c;
}
}
if(debug)
{
Serial.print(response);
}
return response;
}
Finally i cant turn on my led ![]()
Response of get method is:
SEND OK
+IPD,638:HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/10.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Sun, 09 Aug 2015 23:30:32 GMT
Content-Length: 417
<!DOCTYPE html>
<body>
<form method="get" action="index.aspx?token=1234" id="form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="agBjWUpqN0n3l9O+RShzWRr0gMzlaFT0femxE3d6vjDsyPy2n1qlzMzwYw/Cfb+1lx1tzeVOC2zqiXk+e5FkxbRfFGiZWBX/A2SJsKMRlMo=" />
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="90059987" />
pin=200</form>
</body>
</html>
OK