Hi forum,
I have the Arduino Due and the Ethernet Shield (W5100). My testing project is transmit a text file from LabVIEW throught Ethernet to the Due, then storage to the SD card. I tried with the SD standard library and they can work well, but the transmission and writting speed too slow (about 1kB/s). Then i tried the sdfat library (SdFatBeta20130621) hope they can work faster. I test individual Ethernet and write data to SD card both work well, but when i paired together, just some first characters from text file can write to SD file, all characters later are 每每每每每每每每每每每每每...
This is my code:
Forget everything you know about basic. Lose the label and the goto statement. Learn to use a while loop and the break statement.
You are not reading all the data from the client. You need a while loop that executes the body as long as client.connected() is true.
In the body of that while loop, you need to read any available data, and write to the SD card, if the count is less than 1000. Do NOT stop reading from the client if the response contains more than 1000 characters.
while(client.connected())
{
聽 while(client.available() > 0)
聽 {
聽 聽 聽 // Read and possibly store data
聽 }
}
The way your code is structured, you tell the client to go away as soon as you have read all data that has arrived, even though the client may still be sending data.
You can read data far faster than the client can send it, in the same way you can read this reply in far less time than it took me to hunt and peck it out.
I would try to determine if it is the ethernet or the SD card. It sounds like it may be the SD. Add the "Serial.print(c);" call again to see what you are getting from the w5100.
This code will cause the sketch to lock up if the connection breaks or the server stalls. It will never exit the "while(client.connected())" loop. It needs a timeout to prevent that. This code has the timeout feature: http://playground.arduino.cc/Code/WebClient
edit: And it does not close the connection. There should be a "client.stop()" call after the "while(client.connected())" loop exits.
Thank you very much sir,
I try with your suggest code and it print back to serial monitor " aaa...a每每每...每 " , with 526 first characters "a", later "每..."
Seem no problem with SD card, so i will try to check the timeout from your link. Thank you,
Try the code on the link I posted without the SD code, just the w5100 code and no SD card in the slot. See if it does the same thing. If it does, let me know. Maybe I can help you debug it.
There was an ethernet library problem in IDE versions prior to V1.0.1. It would not exit the "while(client.available())" loop.
Sorry about my feedback late, my health not good yesterday
I checked the code just only Ethernet code, it work very well, all characters read and print true.
My IDE version is 1.5.4 r2 (the latest version for Due).
So, i really do not know what happen when use Ehernet and SD together =(