user19181: Sending data to the server(thingspeak.com/184.106.153.14) with AT commands on serial monitor works fine but whenever i upload the sketch ,the following always return false if(Serial.find( ">" ) ). I am not sure if AT+CIPSEND is not working correctly or what. I am using Arduino with ESP8266. Any help will be appreciated.Thanks you in advance. Here is my code.
  #include <SoftwareSerial.h>
  SoftwareSerial softSerial(2, 3); // RX, TX

  #define SSID "myssid"
  #define PASS "Mypass"
  #define IP "184.106.153.149" // ThingSpeak 

  void setup() 
  {
   uint32_t baud = 9600;
   Serial.begin(baud);
   softSerial.begin(baud);

   connectWiFi();
   }

   void loop() 
   {
    updateTS();
    }

    void updateTS()
    {
    String cmd = "AT+CIPSTART=\"TCP\",\"";// Setup TCP connection
    cmd += IP;
    cmd += "\",80";
    sendDebug(cmd);
    delay(2000);

    String url = "GET /update?key=P55Z0BDASNQBFQKT&field1=15&field2=25\r\n\r\n"; //hard code value 15 and 25
    String stringLength="AT+CIPSEND=";
    stringLength +=String(url.length( ));
    Serial.println(stringLength);
    //delay(10000); I even tried to delay for few seconds

   //Here is where it fails,it jumps to closing the connection
   if(Serial.find( ">" ) )
    {
     softSerial.print(">");
     softSerial.print(cmds);
     Serial.print(cmds);
    }
    else
    {
     sendDebug( "AT+CIPCLOSE" );//close TCP connection
    }

    }


   void sendDebug(String cmd)
    {
      softSerial.print("SEND: ");
      softSerial.println(cmd);
      Serial.println(cmd);
     }

     boolean connectWiFi()
    {
      Serial.println("AT+CWMODE=1");
      delay(2000);
      String cmd="AT+CWJAP=\""; // Join accespoint
      cmd+=SSID;
      cmd+="\",\"";
      cmd+=PASS;
      cmd+="\"";
      sendDebug(cmd);
      delay(5000);
      if(Serial.find("OK"))
      {
       softSerial.println("RECEIVED: OK");
       return true;
      }
      else
      {
       softSerial.println("RECEIVED: Error");
       return false;
       }
     }


user11763: Your code looks like you connected the ESP to the hardware serial port, but your comment says otherwise so:
Your sketch isnt working because you're writing to the wrong serial port half the time, and even when you do use the right serial port (softSerial) you're sending garbage along with it.
Serial.println(stringLength); and Serial.find("OK") should be softSerial.println(stringLength); and softSerial.find("OK").
Serial.find( ">" ) should be softSerial.find( ">" ). You should look for '>' in the buffer between the Arduino and the ESP8266 and not the one between the Arduino and the PC.
softSerial.print(">");, softSerial.println("RECEIVED: OK"); and similar statements should not be there at all. They are not commands or arguments to a command so why are you printing them to the ESP? Whenever you write to softSerial, make sure its a command. Dont send your debug messages to softSerial; use Serial instead.
There's no variable called cmds and yet you're printing it to the serial port. Assuming this code compiled, its probably a typo in your question?
Finally, your code structure is unreliable at best, what with all the delays in it and not a single Serial.available() or softSerial.available(), not to mention the abundant usage of Arduino Strings. I suggest you first learn how to read from a serial port and build C strings from the results and then re-design your code again. Majenko's blog is as good a tutorial as any. Or you could download a library like this one that provides an easy API to the ESP8266, shielding you from the mess of AT commands, while providing you with example sketches that already do what you want. Of course, you could choose to go through their library (.cpp and .h files are the place to be) and figure out how they used AT commands with the ESP and then write your own sketch, library or whatever. Good luck.

19181: <p>Sending data to the server(thingspeak.com/184.106.153.14) with AT commands on serial monitor works fine but whenever i upload the sketch ,the following always return false <code>if(Serial.find( "&gt;" ) )</code>. I am not sure if <code>AT+CIPSEND</code> is not working correctly or what. I am using Arduino with ESP8266. Any help will be appreciated.Thanks you in advance. Here is my code.</p>

<pre><code>  #include &lt;SoftwareSerial.h&gt;
  SoftwareSerial softSerial(2, 3); // RX, TX

  #define SSID "myssid"
  #define PASS "Mypass"
  #define IP "184.106.153.149" // ThingSpeak 

  void setup() 
  {
   uint32_t baud = 9600;
   Serial.begin(baud);
   softSerial.begin(baud);

   connectWiFi();
   }

   void loop() 
   {
    updateTS();
    }

    void updateTS()
    {
    String cmd = "AT+CIPSTART=\"TCP\",\"";// Setup TCP connection
    cmd += IP;
    cmd += "\",80";
    sendDebug(cmd);
    delay(2000);

    String url = "GET /update?key=P55Z0BDASNQBFQKT&amp;field1=15&amp;field2=25\r\n\r\n"; //hard code value 15 and 25
    String stringLength="AT+CIPSEND=";
    stringLength +=String(url.length( ));
    Serial.println(stringLength);
    //delay(10000); I even tried to delay for few seconds

   //Here is where it fails,it jumps to closing the connection
   if(Serial.find( "&gt;" ) )
    {
     softSerial.print("&gt;");
     softSerial.print(cmds);
     Serial.print(cmds);
    }
    else
    {
     sendDebug( "AT+CIPCLOSE" );//close TCP connection
    }

    }


   void sendDebug(String cmd)
    {
      softSerial.print("SEND: ");
      softSerial.println(cmd);
      Serial.println(cmd);
     }

     boolean connectWiFi()
    {
      Serial.println("AT+CWMODE=1");
      delay(2000);
      String cmd="AT+CWJAP=\""; // Join accespoint
      cmd+=SSID;
      cmd+="\",\"";
      cmd+=PASS;
      cmd+="\"";
      sendDebug(cmd);
      delay(5000);
      if(Serial.find("OK"))
      {
       softSerial.println("RECEIVED: OK");
       return true;
      }
      else
      {
       softSerial.println("RECEIVED: Error");
       return false;
       }
     }
</code></pre>
 11763: <p>Your code looks like you connected the ESP to the hardware serial port, but your comment says otherwise so:</p>

<p>Your sketch isnt working because you're writing to the wrong serial port half the time, and even when you do use the right serial port (<code>softSerial</code>) you're sending garbage along with it.</p>

<p><code>Serial.println(stringLength);</code> and <code>Serial.find("OK")</code> should be <code>softSerial.println(stringLength);</code> and <code>softSerial.find("OK")</code>.</p>

<p><code>Serial.find( "&gt;" )</code> should be <code>softSerial.find( "&gt;" )</code>. You should look for '>' in the buffer between the <strong>Arduino and the ESP8266</strong> and not the one between the Arduino and the PC.</p>

<p><code>softSerial.print("&gt;");</code>, <code>softSerial.println("RECEIVED: OK");</code> and similar statements should not be there at all. They are not commands or arguments to a command so why are you printing them to the ESP? Whenever you write to <code>softSerial</code>, make sure its a <strong>command</strong>. Dont send your debug messages to <code>softSerial</code>; use <code>Serial</code> instead.</p>

<p>There's no variable called <code>cmds</code> and yet you're printing it to the serial port. Assuming this code compiled, its probably a typo in your question?</p>

<p>Finally, your code structure is unreliable at best, what with all the delays in it and not a single <code>Serial.available()</code> or <code>softSerial.available()</code>, not to mention the abundant usage of Arduino Strings. I suggest you first learn how to read from a serial port and build C strings from the results and <strong>then</strong> re-design your code again. <a href="https://hackingmajenkoblog.wordpress.com/2016/02/01/reading-serial-on-the-arduino/" rel="nofollow noreferrer">Majenko's blog</a> is as good a tutorial as any. Or you could download a library like <a href="https://github.com/itead/ITEADLIB_Arduino_WeeESP8266" rel="nofollow noreferrer">this one</a> that provides an easy API to the ESP8266, shielding you from the mess of AT commands, while providing you with example sketches that already do what you want. Of course, you could choose to go through their library (.cpp and .h files are the place to be) and figure out how <em>they</em> used AT commands with the ESP and <em>then</em> write your own sketch, library or whatever. Good luck.</p>
