Pages: [1]   Go Down
Author Topic: Arduino WiFi Shield data send issue  (Read 947 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8856
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you provide your code for us?

Thanks  smiley
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is my code

Code:
#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.
Logged

Pages: [1]   Go Up
Jump to: