Upload file over ethernet to USB or SD

05 Jun 2010

I've been looking thru this all day if someone did it before, but I was unseccessful.

My skills are certainly not high enough to make it by myself :-/

Any ideas?

06 Jun 2010

Hi Josef,

You could do something like this:

#include "mbed.h"
#include "HTTPClient.h"

HTTPClient http;
LocalFileSystem local("local");

 int main(void) {
  FILE *fd = fopen("/local/audio.wav", "w");
  http.get("http://path/to/my/file", fd);
  fclose(fd);
}

Where the local filesystem could of course be an SDFileSystem.

Thanks,

Simon

28 Jul 2010

Did you get any joy with this?

 

I'm trying:

FILE *fp = fopen("/sd/snd.wav", "w");

http.get("http://copelj.f2s.com/talk/snd.wav", fp);

fclose(fp);

but get:

"No instance of overloaded function "HTTPClient::get" matches the argument list (E304)" in file "/EA_WavPlayer_Downloader/main.cpp"

Any help massively appreciated!

Jim

 

28 Jul 2010

Jim:

What were your include files for the above code?

28 Jul 2010

Hi Doug,

#include "mbed.h"

#include "wavplayer.h"

#include "SDHCFileSystem.h"

#include "EthernetNetIf.h"

#include "HTTPClient.h"

I imported the files in the normal way and I'm pretty sure they're the latest versions.

Thanks for any help you can offer on this!

Jim

28 Jul 2010

And I assume that you also define in your code?

HTTPClient http;
28 Jul 2010

Hi Jim,

You can use the HTTPFile class:

#include "mbed.h"
#include "HTTPClient.h" 
... 
HTTPClient http
LocalFileSystem local("local"); 
int main(void)
{
/* Ethernet setup */ 
... 
/* */
HTTPFile file("/local/audio.wav");
http.get("http://path/to/my/file", &file);
}

Donatien

28 Jul 2010

Hi Doug, yes I did define HTTPClient.

I've just tried Donatien's suggestion and it's compiled but I can't get the SD card to recognise (once's configured an IP address). Why is it always 2 steps forwards and 1 step back (Probably because my programming skills are se bad ;).

 

Thanks for all the help though

 

Jim

28 Jul 2010

Is there a known problem with the SDcard working whilst also using an Ethernet connection? My code plays the wav files okay when I REM out all the network configuration code: Equally, when the network code is left in, I get an IP address okay but the SDCard fails to go into an idle state.

#include "mbed.h"

#include "wavplayer.h"

#include "SDHCFileSystem.h"

#include "EthernetNetIf.h"

#include "HTTPClient.h"

 

DigitalOut led1(LED1);

DigitalOut led4(LED4);

HTTPClient http;

EthernetNetIf eth;

 

SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sclk, cs, name

 

int main() {

// printf("Start\n");

//  printf("\r\nSetting up...\r\n");

//  EthernetErr ethErr = eth.setup();

//  if(ethErr)

//  {

//    printf("Error %d in setup.\n", ethErr);

//    return -1;

//  }

//  printf("\r\nSetup OK\r\n");

// Open a file to write. Get the file. Close the file

 

//HTTPFile file("/sd/snd.wav");

//HttpResult r = http.get("http://copelj.f2s.com/talk/snd.wav", &file);

 

// if(r==HTTP_OK)

// {

//   printf("Result :\"%d\"\n",r);

// }

// else

// {

//   printf("Error %d\n", r);

// }

 

WavPlayer myWavPlayer;

 

led1 = 1 ;

printf("\r\n--------------- Starting -----------------\r\n");

 

myWavPlayer.play_wave("/sd/alive.wav"); //  8 bit sample size

 

 

myWavPlayer.play_wave("/sd/complete.wav");  // 8 bit sample size

 

printf("<<<<<<<<<<<<<<<< All done >>>>>>>>>>>>>>>>\r\n");

led1 = 0;

led4 = 1;

 

}

29 Jul 2010

It seems to work intermittently. I changed the code to:

 

HTTPFile file("/sd/snd.wav");

HTTPResult r = http.get("http://copelj.f2s.com/snd.wav", &file);

----

So I could at least see if there was an error by printing r. I managed to have it download a text file at 6 Bytes but the snd.wav file at 160KB fails with a connectivity error. Is this a temperamental glitch does anyone know?

Thanks in advance

Jim

29 Jul 2010

Jim:

What was the error code you were receiving in variable r ?

Sounds like something is timing out in the http.get code. I expect that 6 bytes would be transferred in one TCP packet, however 160K bytes would require many TCP packets to transfer the file. Maybe Donatien can shed some light on this.

29 Jul 2010

Hi Doug,

I think you're right, It varies between 8 and 9: So either Connection or Timeout. I've been trying different file sizes and basically small text files are all it seems to manage. Also when it fails on a larger file, the SDcard fails to initialise for the second bit of code. I suspect something is still going on with it!

Is there anyway of debugging what's going on in the http.get code?

29 Jul 2010

Jim:

I'm planning on using this capability in the near future so hope we can resolve it. My application will be sending files the size of 500k to 1M every 24hrs or so.

I think there may be a timeout setting in the http class somewhere. I've haven't delved into the http code yet as I'm still debugging PCBs at the lower level now. But in about 2 weeks I'll have to begin familiarizing better with the whole Net Interface provided by Donatien. If Donatien doesn't see this thread, maybe you could shoot him a private email and braoch the subject.

Doug

 

 

03 Aug 2010

Hi everyone,

I have been out of office during these last days, so I will give the SD Card + HTTPFile combination a go soon, and check for the timeout issue on large files.

Donatien

03 Aug 2010

How was the beach? :)

05 Aug 2010 . Edited: 05 Aug 2010

Good thanks;).

I checked this out and it looks like that the FATFileSystem library (used by the SD Cards one) is buggy. On a call to fwrite, a random number is returned instead of the actual number of bytes written.

This messes up with the HTTPFile class which uses this data.

I will try to figure out exactly where does that bug come from today.

Donatien

05 Aug 2010

Well,

I was actually wrong, fwrite is working fine!

However the SD*FileSystem.h file defines some weird types that don't go along well with the stack, but putting the SD stuff in a separate cpp file solves the problem.

For a working example, see http://mbed.org/users/donatien/programs/HTTPClientSDCardTest/latest.

This uses a new version of the HTTPClient that will be published today.

Donatien

05 Aug 2010

Hi again,

Just updated the stack and the example:

http://mbed.org/users/donatien/programs/HTTPClientSDCardTest/latest

05 Aug 2010

Great timing, Donatien! Thanks! Am going to getting back to using the stack tomorrow.

Doug

05 Aug 2010 . Edited: 05 Aug 2010

Donatien, is there a reason you are using SDHCfilesystem rather than SDFileSystem or something else?

06 Aug 2010

Hi,

I just pulled up this library rather than the SDFileSystem since it was being used in the above piece of code; actually I might switch this example back to the "generic" SDFileSystem library.

13 Aug 2010

Thanks Donatien,

Works a treat.

13 Aug 2010

Hi Donatien,

Thank you for the update, this solves the problem I was having with errors on file downloads.

14 Apr 2011

I am now testing the example HTTPClientSDCardTest and worked well with small files, but always returns with error 8 when I try another larger file (8MB), not found anywhere the description of this error.

I think the problem is not where files are hosted, because my browser can download it without problems.

It will be some time overflow error or something? any suggestions?

Thanks

Please log in to post a reply.