Sending GET request from ESP8266+Arduino

I am trying to send GET request through AT command,

AT+CWJAP=“","

AT+CIPSTART=“TCP”,“shotlu.usrs0.com”,80

AT+CIPSEND=73 (length of the url)

GET /receiver.php?apples=56&oranges=23 HTTP/1.1\r\nHost: shotlu.usrs0.com\r\n\r\n

**/*

But after sending the url it’s giving me this message;

GET /receiver.php?apples=56&oranges=23 HTTP/1.1\r\nHost: shotlu.usrs0.com\r\n\r\nbusy s…

SEND OK

+IPD,168:

400 Bad Request

400 Bad Request


hosting

OK
CLOSED

OK

any guess why this happened?

/***
I used this php code for saving data to a text file,

<?php $var1 = $_GET['apples']; $var2 = $_GET['oranges']; $fileContent = "You have ".$var1." apples, and ".$var2." oranges.\n"; $fileStatus = file_put_contents('myFile.txt',$fileContent,FILE_APPEND); if($fileStatus != false) { echo "success: data written to file"; } else { echo "FAIL: could not write to file"; } ?>

For one thing, the GET request is 83 characters long, not 73.

Can you please tell me how you calculate the length of the url?

In this link I got to know that something is different about the measuring length of a url. http://blog.huntgang.com/2015/01/20/arduino-esp8266-tutorial-web-server-monitor-example/

Can you please tell me how you calculate the length of the url?

How is it stored? If it is in a NULL terminated array of chars, strlen() is the function to use.

If you've pissed away resources using a String, go look up for yourself how to get the length of the char array that it wraps.

hey Pauls I used this web app to calculate the string length. Here is the link "https://mothereff.in/byte-counter". It show me 81 for this GET request.

and i got to know that from this link "http://blog.huntgang.com/2015/01/20/arduino-esp8266-tutorial-web-server-monitor-example/"

"AT+CIPSEND=50

Finally we can perform an HTTP get against the server. Note the number 50 above is the total number of characters in this command. We count \r & \n as single characters and we do not count the last \r\n sequence.

GET /status.html HTTP/1.0\r\nHost: 192.168.88.35\r\n\r\n"

so I am sending 73 instead of 81. That's why i need to know how you calculate the length which is actually 83.

That's why i need to know how you calculate the length which is actually 83.

I pasted it into Notepad++ which told me the length. I forgot about the escaped characters counting as two in Notepad.

Still, there are 6 escaped characters, to the total length should have been 77. Subtracting the last two, you get 75, not 73 or 77.

after passing 75… still it shows me this message :frowning:

"AT+CIPSEND=75

GET /receiver.php?apples=56&oranges=23 HTTP/1.1\r\nHost: shotlu.usrs0.com\r\n\r\nbusy s…

SEND OK

+IPD,168:

400 Bad Request

400 Bad Request


hosting

OK
CLOSED

OK"

3.jpg

and one thing i forgot to mention that I send this get request "GET /receiver.php?apples=56&oranges=23 HTTP/1.1\r\nHost: shotlu.usrs0.com\r\n\r\n"

but after sending it becomes "GET /receiver.php?apples=56&oranges=23 HTTP/1.1\r\nHost: shotlu.usrs0.com\r\n\r\nbusy s..."

"busy s..." don't know where it comes from

Busy s, module needs a reset. Read this for more info.

How to increase the serial monitor buffer size in arduino? I have tried those AT command in different IDE which is "RealTerm" and also I need to change the firmware version (ESP8266_AT_V00180902_04 (0018000902-AI03)_unconfirm version) . I can successfully send data to a web server from this IDE, using same command pattern. But in Arduino IDE for the limitation of serial monitor buffer size (64 byte) it can not send more than 64 byte/character at a time. Now I need to know how to change the buffer size, I saw a tutorial in youtube but that was not clear enough.

https://www.youtube.com/watch?v=Aqc1SAtIJeU

and in this video link this arduino is older version 1.0.3, I am using arduino version 1.6.5 r5, so any idea how can i increase the serial monitor buffer size?

I am trying to send GET request through AT command,

It is my understanding that a GET request usually does not require a content length value to be sent (POST request usually send the data size). Below is some simple get test code you might modify for testing with your ESP8266.

//zoomkat 3-1-13
//simple client checkip test
//for use with IDE 1.0.1 or later
//with DNS, DHCP, and Host
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address

char serverName[] = "checkip.dyndns.com"; // test web page server
EthernetClient client;

//////////////////////

void setup(){

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }

  Serial.begin(9600); 
  Serial.println("Better client ip test 3/1/13"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
}

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
  {
    byte inChar; // sets inChar as a byte
    inChar = Serial.read(); //gets byte from buffer
    if(inChar == 'e') // checks to see byte is an e
    {
      sendGET(); // call sendGET function below when byte is an e
    }
  }  
} 

//////////////////////////

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET / HTTP/1.1"); //download text
    client.println("Host: checkip.dyndns.com");
    client.println("Connection: close");  //close 1.1 persistent connection  
    client.println(); //end of get request
  } 
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor 
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client

}

How to increase the serial monitor buffer size in arduino?

You can't. The Serial Monitor is an application that runs on the PC. The buffer is not on the Arduino.

The Arduino does have buffers for incoming and outgoing Serial data. The size can be changed, but the usual reason for thinking that it needs to be is because the Arduino is f**king around, not reading the data. When it wants to, the Arduino can read data orders of magnitude faster than it can arrive.

Nothing I've seen in this thread suggests that a 128 megabyte serial buffer would help.

But in Arduino IDE for the limitation of serial monitor buffer size (64 byte) it can not send more than 64 byte/character at a time.

That is nonsense. When the outgoing buffer gets full, the Arduino simply waits for there to be more room. One could pass a 512 character char array to Serial.print(), an EVERY SINGLE CHARACTER would be sent.

zoomkat: It is my understanding that a GET request usually does not require a content length value to be sent (POST request usually send the data size). Below is some simple get test code you might modify for testing with your ESP8266.

I think in AT command you need this, cause in;

AT+CIPSEND= here you need to initialize the string length,

after that you can send GET/POST request;

T+CIPSEND= here you need to initialize the string length,

What string is being discussed, just the GET data or the GET command, GET data, and the cr/lf bytes that mark the end of the data packet? Is the length value required by the ESP8266 or the final end point server? I'd like to get a ESP8266 when they get a little more user friendly.

hi Asadujjaman, i've faced the same problem as i am trying the same method to retrieve weather station info using GET on AT command on arduino IDE, i have found a youtube link that solve my problem i hope it help u too.

https://www.youtube.com/watch?v=xZePXRjQOe8

he send his data separately, i think every time we hit enter to the serial monitor it automatically generates a \r\n

the total length of data he is sending [i count from his notepad] is 98 characters, i think he adds another 4 to make a total of 102 because of the extra \4 times of \r\n