I recently purchased a Arduino WiFi shield. I connetced the shield to Arduio Mega 2560. I wrote a small TCP/IP client sketch to connect to a PC server. 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 ("12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012");
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.
#include <SPI.h>
#include <WiFi.h>
char ssid[] = "MYssid"; // your network SSID (name)
char pass[] = "MYPASSWORD"; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0; // your network key Index number (needed only for WEP)
int status = WL_IDLE_STATUS;
IPAddress server(192,168,1,100);
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");
printWifiStatus();
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()
{
int count;
// check if the wifi is still connected
status = WiFi.status();
if( status != WL_CONNECTED)
{
connecToWiFi();
}
if (client.connected() == false)
{
connectToServer();
}
// send data to server
count = client.write("12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012");
Serial.print("Wrote bytes = ");
Serial.println(count);
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");
}
If I create a String object and use the string object as the input parameter to println(), then I can send more then 92 byes. But if I define a char dataStr[] and fill it up with data that is more then 92 bytes, it does not work.