anna_x

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:

connect_again: if (client.connect(server, 8001)){ Serial.println("connected");} else{ Serial.println("connection failed"); delay(2000); goto connect_again;} 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.

if( c>0 && c<255 ) { myFile.print(c); i++; if(i==1000) { myFile.close(); Serial.println("Finished"); } } } }}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.

anna_x

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,

anna_x

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 =(