Go Down

Topic: Arduino WiFi Shield data send issue (Read 1 time) previous topic - next topic

shankar108

I am new to Arduino. I recently purchased an Arduino Mega 2560 and an Arduino WiFi shield. I connected the shield to Arduio Mega 2560. I wrote a small TCP/IP client sketch to connect to a server running on a PC. Everything works fine as long as I send less than 92 bytes with each println() or print() or write() function call.

The following code
count = client.println ("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890");
Serial.print("Wrote bytes = ");
Serial.println(count);

The Serial.println() indicates only 2 bytes were written. I confirmed that Server only received 2 bytes by checking with wireshark. The wireshark shows the server only received the \r\n when I use println().

1. Is there a MAXIMUM Buffer size for TCP DATA?

2. Is there a timimg problem between Mega2560 and AVr32 processor on the WiFi shield when one sends more then 92 bytes?

3. What else could be causing this behaviour?

Why does the WifiClinet's print(), write() and println() functions all fail when trying to send more than 92 bytes.

My environment is
Arduino Mega 2560
Arduino Wifi Shield
Arduino IDE 1.0.4
Windows XP

Any help is greatly appreciated.

Thanks
Shankar

johnwasser

I can't find a place that would cause a crash if the string is larger than 92 bytes.  The EthernetClient::write() function calls send(_sock, buf, size) where '_sock' is the client socket and buf and size are the buffer you provide and its size. The send() function only checks the 'size' against W5100.SSIZE which is 2048.

Could it be that you are running out of SRAM?
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

shankar108

I am doubtful of running out of memory. it seems like a timing issue between the Mega 2560 and the AVR32 processor on the Wifi shield. I also did not see any max size limitaion. I think it is a timing issue in the SPI communication. The Wifi Shield does not use the SPI library, it looks like it has its own SPI code.

Any other suggestion?

Thanks
Shankar

jonboski

Can you provide your code for us?

Thanks  :)

shankar108

Here is my code

Code: [Select]
#include <arduino.h>
#include <SPI.h>
#include <WiFi.h>

char ssid[] = "ABCDEF"; //  your network SSID (name)
char pass[] = "1234567890";    // your network password (use for WPA, or use as key for WEP)

const char dataStr1[] = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";

int status = WL_IDLE_STATUS;

IPAddress server(192,168,3,48);  // numeric IP for Google (no DNS)

WiFiClient client;

boolean connecToWiFi()
{

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED)
  {
     status = WiFi.status();
    // check for the presence of the shield:
    if ( status == WL_NO_SHIELD)
    {
      Serial.println("WiFi shield not present");
      continue;
    }
   
    // Connect to WPA/WPA2 network.
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);
 
    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.println("Connected to wifi");
 
 
  return true;
}

boolean connectToServer()
{
  Serial.println("\nStarting connection to server...");
  // if you get a connection, report back via serial:
 
  client.stop();
  while(client.connect(server, 32155) == false)
  {
    Serial.println("Can not connect to server");
  }
 
  Serial.println("connection to server successful");
 
  return true;
}

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
 
connecToWiFi();
 
connectToServer();
 

}

void loop()
{
  static int count = 0;
   
  // check if the wifi is still connected
  status = WiFi.status();
  if( status != WL_CONNECTED)
  {
    connecToWiFi();
  }

  if (client.connected() == false)
  {
    connectToServer();
  }
 
  // the function below also has the same problem
  //count = client.write((uint8_t*)dataStr1, (sizeof(dataStr1) /sizeof(dataStr1[0])));
  count = client.print(dataStr1);
 
  //Serial.println(count);
  if (count == 0)
  {
     client.println();
     Serial.println("Faild to Write bytes for sendBuf");
     Serial.println(dataStr1);
  }

  delay(3000);

}


void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}






I am using constant literals in the code. However when I finish my implementation I would be reading data from multiple sensors and submitting my request as a single entry (MAX 350 Bytes) to a server running on PC. The sensor reading will replace the constant literal.

rossati

Hello shankar108

I haven't seen any reply to your question (I too have the same problem).
I hope you have solved.

I'll do a more in-depth look at WIFIUPD, which (perhaps) allows to enter the delay; otherwise I'll have to break my data.

Best regards

John Rossati


PaulS

Have you looked at how much memory you are using?
http://playground.arduino.cc/Code/AvailableMemory

Much of the SRAM you are using is unnecessary. Keep string literals out of SRAM by using the F() macro:
     Serial.println(F("WiFi shield not present"));

SurferTim

I tested this and also found the wifi shield send limit was 92 bytes. I can't find my post right now due to the forum search not working. I tried the Google search but couldn't find it.

Go Up