AT-0.22.b1.0 AT+CIPSEND not reliable even returns success

jyke
Posts: 8
Joined: Mon Feb 09, 2015 4:52 am

AT-0.22.b1.0 AT+CIPSEND not reliable even returns success

Postby jyke » Wed Feb 25, 2015 3:32 am

Hi,

I notised that AT+CIPSEND is not reliable even return value is sucess

Test code that I used under... Same problem hapened if I connect telnet direcly to esp8266 or via wlan router.
Espn8266 baud rate set as: AT+UART=9600,8,1,0,0 because other wice Arduino UNO - Esp8266 communication is not "stable".

Example code sends same data always two times like:

Next Message Len 9: // Tells next sent message len
012345678 // numeric message 01234567890123456....
Next Message Len 9: // Tells next sent message len
012345678 // numeric message 01234567890123456....


esp8266 debug trace stated that send sucess like: (TRUE states command success FALSE == fail)
AT+CIPSEND=0,23

Next Message Len 7:
TRUE
AT+CIPSEND=0,7
0123456TRUE
AT+CIPSEND=0,23

Next Message Len 7:
TRUE
AT+CIPSEND=0,7
0123456TRUE
AT+CIPSEND=0,23

Next Message Len 8:
TRUE
AT+CIPSEND=0,8
01234567TRUE
AT+CIPSEND=0,23

Next Message Len 8:
TRUE
AT+CIPSEND=0,8
01234567TRUE
AT+CIPSEND=0,23

Next Message Len 9:
TRUE
AT+CIPSEND=0,9
012345678TRUE
AT+CIPSEND=0,23

Next Message Len 9:
TRUE
AT+CIPSEND=0,9
012345678TRUE
AT+CIPSEND=0,24

Next Message Len 10:
TRUE
AT+CIPSEND=0,10
0123456789TRUE
AT+CIPSEND=0,24

Next Message Len 10:
TRUE
AT+CIPSEND=0,10
0123456789TRUE
AT+CIPSEND=0,24

Next Message Len 11:
TRUE
AT+CIPSEND=0,11
01234567890TRUE
AT+CIPSEND=0,24

Next Message Len 11:
TRUE
AT+CIPSEND=0,11
01234567890TRUE
AT+CIPSEND=0,24

Next Message Len 12:
TRUE
AT+CIPSEND=0,12
012345678901TRUE
AT+CIPSEND=0,24

Next Message Len 12:
TRUE
AT+CIPSEND=0,12
012345678901TRUE
AT+CIPSEND=0,24

Next Message Len 13:
TRUE
AT+CIPSEND=0,13
0123456789012TRUE
AT+CIPSEND=0,24

Next Message Len 13:
TRUE
AT+CIPSEND=0,13
0123456789012TRUE


and corresponding Telnet received data:

Next Message Len 7:
0123456
Next Message Len 7:

Next Message Len 8:
01234567
Next Message Len 8:

Next Message Len 9:
012345678
Next Message Len 9:
012345678
Next Message Len 10:
01234567890123456789
Next Message Len 11:
0123456789001234567890
Next Message Len 12:

Next Message Len 12:
0123456789010123456789012
Next Message Len 13:
0123456789012



Code: Select all

#include "SoftwareSerial.h"


// espn8266 baud rate set as: AT+UART=9600,8,1,0,0
SoftwareSerial esp8266(2, 3);
char message[200];


const char endl[] = "\r\n";
const char OK[] = "OK";
const char ERROR[] = "ERROR";
const char AT[] = "AT\r\n";
const char GMR[] = "AT+GMR\r\n";
const char RESET[] = "AT+RST\r\n";
const char CIPSEND[] = "AT+CIPSEND=%i,%u\r\n";
const char CWMODE[] = "AT+CWMODE?\r\n";
const char SET_CWMODE[] = "AT+CWMODE=%i\r\n";
const char AP[] = "AT+CWJAP?\r\n";
const char SET_AP[] = "AT+CWJAP=\"%s\",\"%s\"\r\n";
const char ESP8266_AP[] = "AT+CWSAP?\r\n";
const char SET_ESP8266_AP[] = "AT+CWSAP=\"%s\",\"%s\",%i,%i\r\n";
const char ESP8266_AP_IP[] = "AT+CIPAP?\r\n";
const char AP_IP[] = "AT+CIPSTA?\r\n";
const char MUX[] = "AT+CIPMUX?\r\n";
const char SET_MUX[] = "AT+CIPMUX=%i\r\n";
const char SET_TCP_SERVER[] = "AT+CIPSERVER=%i,%i\r\n";
const char CLOSE_CONNECTION[] = "AT+CIPCLOSE";
const char RECEIVE_DATA[] = "+IPD,";
const char SEND_MODE[] = "AT+CIPMODE?\r\n";
const char SET_SEND_MODE[] = "AT+CIPMODE=%i\r\n";

#define DEBUG_F(VAL) Debug(VAL);

      void Debug(const char *val)
      {
         Serial.print(val);
      }

      void Debug(bool val)
      {
         val ? Serial.print("TRUE\n") : Serial.print("FALSE\n");
      }

      void Debug(int val)
      {
         Serial.print(val);
         Serial.print("\n");
      }

      void Debug(unsigned int val)
      {
         Serial.print(val);
         Serial.print("\n");
      }

      void AtCommand(const char *command)
      {
         esp8266.print(command);
         DEBUG_F(command);
         delay(20);
      }

      bool AtReturnOK()
      {
         bool ret = false;
         if (esp8266.find("OK"))
         {
            ret = true;
         }
         DEBUG_F(ret);
         return ret;

      }

      bool SetBaudRate(const unsigned int val)
      {
         DEBUG_F("Set baud: ")
            DEBUG_F(val)
            esp8266.begin(val);
         delay(250);
         AtCommand(AT);
         return AtReturnOK();
      }

      bool SetWifiMode(int mode)
      {
         char command[64];
         sprintf(command, SET_CWMODE, mode);
         AtCommand(command);
         return AtReturnOK();

      }
      bool Reset()
      {
         DEBUG_F(RESET)
         esp8266.print(RESET);
         bool ret = AtReturnOK();
         for (int i = 0; i < 10; i++)
         {
            delay(200);
            AtCommand(AT);
            if (AtReturnOK())
            {
               break;
            }
         }
         return ret;
      };

      void SetEsp8266Accesspoint(char *ssid, char *pwd, int channel, int security)
      {
         int len = strlen(ssid) + strlen(pwd) + strlen(SET_ESP8266_AP) + 1;
         char *command = new char[len];
         esp8266.setTimeout(5000);
         sprintf(command, SET_ESP8266_AP, ssid, pwd, channel, security);
         AtCommand(command);
         esp8266.setTimeout(1000);
         delete[]command;
         Reset();
      }



      bool SetAccesspoint(char *ssid, char *pwd)
      {
         int len = strlen(ssid) + strlen(pwd) + strlen(SET_AP) + 1;
         char *command = new char[len];
         sprintf(command, SET_AP, ssid, pwd);
         AtCommand(command);
         delete[]command;

         bool ret = false;
         esp8266.setTimeout(20000);
         if (AtReturnOK())
         {
            ret = true;
         }
         esp8266.setTimeout(1000);

         return ret;
      }
      bool SetConnectionMode(int mode)
      {
         char command[64];
         sprintf(command, SET_MUX, mode);
         AtCommand(command);
         return(AtReturnOK());
      }

      bool SetTcpServer(int mode, int port)
      {
         char command[64];
         sprintf(command, SET_TCP_SERVER, mode, port);
         AtCommand(command);
         esp8266.setTimeout(5000);
         AtReturnOK();
         esp8266.setTimeout(1000);
         return true;

      }
      bool DataReceived(int &id, int &len)
      {
         if (esp8266.available())
         {
            if (esp8266.find((char*)RECEIVE_DATA))
            {
               DEBUG_F("Data available:\n")
                  String str = esp8266.readStringUntil(':');
               DEBUG_F(str.c_str())
                  DEBUG_F(":\n")
                  int first;
               int second;

               int cnt = sscanf(str.c_str(), "%i,%i", &first, &second);

               if (cnt == 1)
               {
                  len = first;
                  id = -1;
                  return true;
               }
               else if (cnt == 2)
               {
                  id = first;
                  len = second;
                  return true;
               }
            }

         }
         return false;
      }
      size_t ReceiveData(size_t len, char *buf)
      {
         esp8266.setTimeout(5000);
         len = esp8266.readBytes(buf, len);
         esp8266.setTimeout(1000);
         return len;
      }

      bool SendIpMessage(int connection, char *message, long unsigned int msglen)
      {
         bool ret = false;
         esp8266.setTimeout(5000);
         bool retry = true;
         while (msglen)
         {
            unsigned int dataLen = msglen < 2048 ? msglen : 2048;
         tryAgain:
            char val[5];
            char command[64];
            sprintf(command, "AT+CIPSEND=");
            if (connection != -1)
            {
               strcat(command, itoa(connection, val, 10));
               strcat(command, ",");
            }
            strcat(command, itoa(dataLen, val, 10));
            strcat(command, "\r\n");
            AtCommand(command);
            command[0] = 0;
            if (!esp8266.findUntil((char*)&command, ">"))
            {
               DEBUG_F(command);
               if (retry)
               {
                  retry = false;
                  goto tryAgain;
               }
               else return false;

            }
            esp8266.write(message, dataLen);
            Serial.write(message, dataLen);
            if (!AtReturnOK() && retry)
            {
               goto tryAgain;
            }

            msglen -= dataLen;
            message += dataLen;
            delay(50);
         }
         esp8266.setTimeout(1000);

         return ret;
      };
      bool CloseConnection(int connection = -1)
      {
         char command[64];
         if (connection == -1)
         {
            sprintf(command, "%s\r\n", CLOSE_CONNECTION);
         }
         else
         {
            sprintf(command, "%s=%i\r\n", CLOSE_CONNECTION, connection);
         }
         AtCommand(command);
         return AtReturnOK();
      }

void setup()
{
   for (int i = 0; i < 200; i++)
   {
      message[i] = i % 10 + '0';
   }
   Serial.begin(115200);
   delay(200);
   SetBaudRate(9600);
   SetWifiMode(3);
   SetEsp8266Accesspoint("test", "", 7, 0);
   SetAccesspoint("wlan", "1234567890123");
   SetConnectionMode(1);
   SetTcpServer(1, 80);
  /* add setup code here */

}

void loop()
{

   int id;
   int len;
   if (DataReceived(id, len))
   {
      //      char *buf = new char[64];
      char buf[64];
      while (len)
      {
         int read = ReceiveData(len > 64 ? 64 : len, buf);
         if (!read)
         {
            break;
         }
         Serial.write(buf, read);
         len -= read;
      }
      char msg[64];
      for (int i = 1; i < 50; i++)
      {
         for (int x = 0; x < 2; x++)
         {
            sprintf(msg, "\r\nNext Message Len %i:\r\n", i);
            SendIpMessage(id, (char*)&msg, strlen(msg));
            SendIpMessage(id, (char*)&message, i);
         }
      }
      CloseConnection(id);
   }

}


br,
jyke

ESP_Faye
Posts: 1646
Joined: Mon Oct 27, 2014 11:08 am

Re: AT-0.22.b1.0 AT+CIPSEND not reliable even returns succes

Postby ESP_Faye » Fri Feb 27, 2015 4:04 pm

Hi,

Thanks for your interest in ESP8266 !

Sorry that I can‘t understand what is your question?

Could you please have a try with the latest AT http://bbs.espressif.com/viewtopic.php?f=7&t=205 if it still has your problem?

jyke
Posts: 8
Joined: Mon Feb 09, 2015 4:52 am

Re: AT-0.22.b1.0 AT+CIPSEND not reliable even returns succes

Postby jyke » Sat Feb 28, 2015 5:51 pm

Hi,
Same problem exist on:
AT 0.22.b1.0
SDK 0.9.6(b1)

I try to explain more clear:
espn sends following messages with return SEND OK (each line is send as own message "AT+CIPSEND=0,<mesage line len>" wait ´>´ and then <message line>)

Next Message Len 10:
0123456789
Next Message Len 10:
0123456789
Next Message Len 11:
01234567890
Next Message Len 11:
01234567890
Next Message Len 12:
012345678901
Next Message Len 12:
012345678901


But Telnet client receives:

Next Message Len 10:
01234567890123456789
Next Message Len 11:
0123456789001234567890
Next Message Len 12:

Next Message Len 12:
0123456789010123456789012


So chip not send all data to TCP client event it so claims. a code that I used to re-peat the problem is attached.

br,
Jyke

Her Mary
Posts: 537
Joined: Mon Oct 27, 2014 11:09 am

Re: AT-0.22.b1.0 AT+CIPSEND not reliable even returns succes

Postby Her Mary » Mon Mar 02, 2015 11:21 am

??

you sent “0123456789”, you received “0123456789”,I can‘t see where is the problem。。

jyke
Posts: 8
Joined: Mon Feb 09, 2015 4:52 am

Re: AT-0.22.b1.0 AT+CIPSEND not reliable even returns succes

Postby jyke » Tue Mar 03, 2015 12:01 am

Hi,

Lets make send and received messages on same line. after each AT+CIPSEND ">" is waited and after data write chip returns "SEND OK". I also test other than telne and same results, randomly messages drops...

Send Messages with AT+CIPSEND=0,<lineLen>\r\n ------> Received Messages

"\r\nNext Message Len 10:\r\n" ------> "\r\nNext Message Len 10:\r\n"
"123456789" ------> "0123456789"
"\r\nNext Message Len 10:\r\n" ------>Message not received
"0123456789" ------> "0123456789"
"\r\nNext Message Len 11:\r\n" ------> "\r\nNext Message Len 11:\r\n"
"01234567890" ------> "01234567890"
"\r\nNext Message Len 11:\r\n" ------> Message not received
"01234567890" ------> "01234567890"
"\r\nNext Message Len 12:\r\n" ------> "\r\nNext Message Len 12:\r\n"
"012345678901" ------> Message nor received
\r\nNext Message Len 12:\r\n ------> "\r\nNext Message Len 12:\r\n"
"012345678901" ------> "012345678901"
\r\nNext Message Len 13:\r\n ------> Message not received
"0123456789012" ------> "0123456789012"

jyke
Posts: 8
Joined: Mon Feb 09, 2015 4:52 am

Re: AT-0.22.b1.0 AT+CIPSEND not reliable even returns succes

Postby jyke » Thu Mar 26, 2015 3:19 am

Hi,
After taking esp_iot_sdk_v1.0.0_15_03_20 version in the use and using 400ms delay after AT+CIPSEND=.... command returns OK send come reliable,
But if delay was e.g. 200ms after SEND OK next send command can return SEND OK but receiving end newer got message...

br,
jyke

ESP_Faye
Posts: 1646
Joined: Mon Oct 27, 2014 11:08 am

Re: AT-0.22.b1.0 AT+CIPSEND not reliable even returns succes

Postby ESP_Faye » Thu Apr 16, 2015 10:28 am

jyke wrote:if delay was e.g. 200ms after SEND OK next send command can return SEND OK but receiving end newer got message...


Hi,

Could you explain more about your question ? Could you offer your test steps ?

Thanks for your interest in ESP8266 !

Who is online

Users browsing this forum: No registered users and 1 guest