Post topics, source code that relate to the Arduino Platform

User avatar
By Adem Kayar
#73829
kluszon wrote:I tried it, but it don't work too.

@EDIT - Problem Solved!

1. You can't manual send GET or POST request using Arduino IDE and Arduino Serial Monitor, becauese there is problem with coding "\r\n" - carriage return and new line. ( At least I can't do this, though I spent a lot of time on it)
2. Very important things are delays ( delay() ) between AT commands.
3. Correct GET request.

I correct all errors and everything is working fine! :)

Below I attached my code:

Code: Select all#include "SoftwareSerial.h"

SoftwareSerial ESP8266(2, 3);// RX, TX

String server = "adres_serwera"; // np. www.examble.pl albo adres ip 129.75.1.32

void setup()
{
  ESP8266.begin(115200); //odpowiednia prędkość dla twojego modułu
  Serial.begin(115200);
  Serial.print("Start");
  reset();
  ESP8266.println("AT+CWMODE=1");
  delay("1000");
  ESP8266.println("AT+CIPMUX=1");
  delay("1000");
 
  connectWifi();
}

void loop()
{
  String cmd;
  cmd = "AT+CIPSTART=1,\"TCP\",\"";
  delay(500);
  cmd += server;
  delay(500);
  cmd += "\",80";
  delay(500);
  ESP8266.println(cmd);
  delay(500);
 
  if(ESP8266.find("OK"))
  {
    Serial.println("Connected to the web!");
  }
 
  float weight = 257;
  bool state = 1;
  cmd =  "GET /skrypty/add_k.php?w=" + (String)weight + "&k=" + (String)state + " HTTP/1.1\r\n"; 
  delay(500);
  cmd += "Host: www.kluszon.cba.pl\r\n\r\n";
  delay(500); 
  ESP8266.print("AT+CIPSEND=1,");
  delay(500);
  ESP8266.println(cmd.length()); 
  delay(500);
 
  if(ESP8266.find(">"))
  {
    Serial.println(">");
  }
 
  ESP8266.println(cmd);
  delay(500);
 
  if(ESP8266.find("OK"))
  {
    Serial.println("send!");
  }
}

void connectWifi()
{

  String cmd = "AT+CWJAP=\"My_wifi\",\"hasło\"";
  ESP8266.println(cmd);
  delay(4000);
 
  if(ESP8266.find("OK"))
  {
    Serial.println("Connected!");
  }else{
    connectWifi();
    Serial.println("Cannot connect to wifi");
  }
}

void reset()
{
  ESP8266.println("AT+RST");
  delay(1000);
  if(ESP8266.find("OK")) Serial.println("Module Reset");
}



i try your code but it dont work :( i think esp connect wifi but it dont continue :(