Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WiFi101 TCP data corrupted on MKR1000 after reading large number of bytes #184

Closed
Sudeshna19 opened this issue Jul 10, 2017 · 6 comments
Closed
Labels
status: waiting for information More information must be provided before work can proceed type: imperfection Perceived defect in any part of project

Comments

@Sudeshna19
Copy link

Sudeshna19 commented Jul 10, 2017

I am using MKR1000 as WiFi TCP server and an application in Windows7 machine as WiFi TCP client. The idea is to connect the client to TCP server and send many bytes (~ 200 bytes). TCP server reads the received data and sends it back to client. I am using Hercules SETUP utility 3.2.8 (http://www.hw-group.com/products/hercules/index_en.html) as the TCP client on Windows.

The code is below:

 #include <SPI.h>
 #include <WiFi101.h>

 int configureSuccess = WL_IDLE_STATUS;
 char ssid[] = "TP-LINK_POCKET_3020_C051E6"; //  your network SSID (name)
 char pass[] = "83378669";    // your network password (use for WPA, or use as key for WEP)
 WiFiServer server(40000);
 uint8_t alreadyConnected = false; 
 uint8_t data1;
 void setup() {
    Serial.begin(57600);
   // Serial1.begin(57600);
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    while ( configureSuccess != WL_CONNECTED) {
        configureSuccess = WiFi.begin(ssid, pass);
        unsigned long startMillis  = millis();
        while(millis()- startMillis < 10000)
                        {
                        };
       }
              
         server.begin();
      for(int trialcount=0;trialcount<5;trialcount++)
      {
          if(Serial)
          {
              break;
          }else
          {
              unsigned long startMillis  = millis();
              while(millis()- startMillis < 1000)
                        {
                        };
          }
      }
      
      
      if (configureSuccess==WL_CONNECTED)
       { 
         IPAddress ip = WiFi.localIP();
         Serial.print("<<<IP address: ");
         Serial.print(ip);  
         Serial.println(">>>");            
      }
     else
     {
         // If the Configuration failed,relay back the error message.
         Serial.println("<<< IP address :Failed to configure. >>>");
     }

     Serial.println("Server: started");
}

void loop() {
   // wait for a new client:
   int avlBytes = 0;
   int st = 0;
   Serial.println("loop");

   
  WiFiClient client1 = server.available();
  if (!client1){
    Serial.println("Server: No client");
  }

    avlBytes = client1.available();
    if(avlBytes >= 1){
         st = client1.read(&data1,1);  
                
         switch(data1){
          case 'A': Serial.println("rcvd A");     break;
          case 'B': Serial.println("rcvd B");     break;
          case 'C': Serial.println("rcvd C");     break;
          case 'D': Serial.println("rcvd D");     break;
          case 'E': Serial.println("rcvd E");     break;
          case 'F': Serial.println("rcvd F");     break;
          case 'G': Serial.println("rcvd G");     break;
          case 'H': Serial.println("rcvd H");     break;
          case 'I': Serial.println("rcvd I");     break;
         }
         Serial.println("Server sending..");
         server.write("Sent ");
         if (data1 == 'A'){
         server.write("**---S--");
         server.write(data1);
         }
         else if (data1 == 'I'){         
         server.write(data1);
         server.write("--X---**");
         }
         else
         server.write(data1);
      }
    else{
      Serial.println("Server: no data");
      }
    
  
 unsigned long startMillis  = millis();
  while(millis()- startMillis < 500)
                        {
                        };

}

Attached below is the snapshot of the data sent and received using Hercules Utility
hostreceive

I sent a repeating pattern of ABCDEFGHI (7 times in 3 rows) resulting in ~210 bytes. In the attached snapshot you can see in area marked under red that the data read from TCP buffer gets corrupted after reading some 100 bytes. I receive something as:
Sent ÎSent YSent óSent ½Sent Sent 'Sent ÝSent WSent �Sent Sent ÛSent ¹Sent 9Sent Sent ÊSent ÆSent  Sent eSent Sent Sent þSent aSent ôSent °Sent sSent îSent øSent �Sent /Sent YSent ¯Sent ¼Sent ÖSent §Sent ´Sent ¥Sent ÕSent ¨Sent _Sent Sent 3Sent ÎSent vSent 'Sent ºSent 2Sent ¡Sent ùSent îSent ÆSent {FF}Sent WSent Sent i

@sandeepmistry
Copy link
Contributor

Hi @Sudeshna19,

I've tried to reproduce this using netcat on macOS, it seems fine to me:

$ nc 10.0.1.63 40000 ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ Sent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent **---S--ASent BSent CSent DSent ESent FSent GSent HSent I--X---**Sent JSent

Could you please try again and use Wireshark to capture the data transfer, then upload a saved capture here?

@sandeepmistry sandeepmistry added the status: waiting for information More information must be provided before work can proceed label Oct 19, 2017
@sandeepmistry
Copy link
Contributor

Also, please provide the output of the sketch to the serial monitor.

@Sudeshna19
Copy link
Author

@sandeepmistry
I am attaching the Wireshark data and data of TCP Client on Host . For Serial monitor output I had to take a screenshot so could not save the entire output.
serial_monitor_out
TCPClient_data.txt
wireshark_capture.zip

I have tried on Windows10 this time. Same issue. Let me know if you need further info.

@Sudeshna19
Copy link
Author

In the above test IP addresses are as below:
MKR1000 - 192.168.0.101 port 40000
Host (Win10 application) - 192.168.0.100
Router - 192.168.0.254

@sandeepmistry
Copy link
Contributor

So in the Wireshark trace, the first two TCP packets have 99 bytes of data: ABCDEFGHIABCDEFGHIABCDEFGHIABCDEFGHIABCDEFGHIABCDEFGHIABCDEFGHIABCDEFGHIABCDEFGHIABCDEFGHIABCDEFGHI

screen shot 2018-01-02 at 12 08 55 pm

This is followed by 3 TCP packets contain 1 byte with value 0x01:

screen shot 2018-01-02 at 12 08 38 pm

@Sudeshna19 could you please provide the exact sketch you used to produce #184 (comment), it seems to differ from the sketch provided in #184 (comment).

Please also try the master version of this library, it includes some changes from pull request #204 - just want to confirm the issue still exists with these changes, or if they are resolved.

@sandeepmistry
Copy link
Contributor

I'm closing this for now due to lack of feedback.

@per1234 per1234 added the type: imperfection Perceived defect in any part of project label Jan 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting for information More information must be provided before work can proceed type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

3 participants