I am working on ESP8266 and I want to send a GET request with AT command to my localhost but I failed every time. Can you help me solve this problem please? Thank you for interest! I attached my terminal code and my code:

#define ag_ismi "SUPERONLINE_WiFi_8022"
#define ag_sifresi "rC5YGNYebuCf"
#define IP "192.168.1.9"

void setup() {
  // put your setup code here, to run once:

  Serial.begin(115200);
  Serial.println("AT");
  delay(3000);
  if(Serial.find("OK")){
    Serial.println("AT+CWMODE=1"); 
    delay(2000);
    String baglantiKomutu=String("AT+CWJAP=\"")+ag_ismi+"\",\""+ag_sifresi+"\"";
    Serial.println(baglantiKomutu);
    delay(5000);     
  }
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(60000);
  Serial.println("AT+CIPMUX=1");
  Serial.println("AT+CIPSTART=\"TCP\",\"192.168.1.9\",8000");
  delay(1000);
  String model = "GET /kanbanDB/arduino?model=1 HTTP/1.1";
  //model+="Host: 192.168.1.9:8000\r\n\r\n";
  model+="r\n\r\n";
  Serial.println("AT+CIPSEND=" + String(model.length()));
  Serial.println("\r\n\r\n");
  delay(1000);
  Serial.println(model);
  Serial.println("\r\n\r\n");
  delay(1000);
  Serial.println(""); 
}

enter image description here

  • problem is, that you connected the esp8266 to Serial. now your Serial debug prints go to esp8266 and disturb it. use SoftwareSerial – Juraj Nov 16 at 20:56

It should be

String model = "GET /kanbanDB/arduino?model=1 HTTP/1.1\r\n";
model+="Host: 192.168.1.9\r\n\r\n";

remove Serial.println("\r\n\r\n"); before Serial.println(model); it is send before GET line

Serial.println("AT+CIPSTART=\"TCP\",\"192.168.1.9\",8000");
String model = "GET /kanbanDB/arduino?model=1 HTTP/1.1\r\n";
model+= "Host: 192.168.1.9\r\n\r\n";
Serial.print("AT+CIPSEND=");
Serial.println(model.length());
delay(1000);
Serial.print(model);
delay(1000);

EDIT: Remove debug prints to Serial or use SoftwareSerial to connect the esp8266 to Uno. Now the debug prints are sent to esp8266 mixed with AT commands and data. For SoftwareSerial change the default baud rate of the AT firmware.

  • I tried this code but its also not working. when I run GET /kanbanDB/arduino?model=1 HTTP/1.1 code, if I send first time wifi module waiting 30 second and send requets but second time I run this code it failed. that failure is about power supply ? – Can Talay Nov 5 at 19:33
  • how do you power it? – Juraj Nov 5 at 20:45
  • I used arduino with USB power – Can Talay Nov 5 at 21:33

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.