Test of Embedded Artists LPCXpresso baseboard SD card and ethernet facilities. This program downloads files from a website to the SD card. This program now uses the HTTPClient from: http://mbed.org/users/donatien/programs/HTTPClient/latest which downloads the files without errors. The previous version of this program was used to demonstrate that an earlier HTTPClient downloaded files with errors.

Dependencies:   EthernetNetIf FatFileSystem HTTPClient mbed

Fork of EA_DownloadToSD by Tom Coxon

Revision:
0:1b55f626a40f
Child:
1:0734a7b0fd5e
diff -r 000000000000 -r 1b55f626a40f main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jul 09 14:43:39 2010 +0000
@@ -0,0 +1,83 @@
+/*
+ Demo of Embedded Artists LPCXpresso baseboard SD card and ethernet facilities.
+
+ This program downloads three files from a website to the SD card.
+ 
+ SD Card setup:
+ 
+ 1. Insert all five jumpers in J39 as described in section 4.3.3
+ of base board users guide.
+ 
+ 2. Remove jumper marked "A" in J55 In order to connect PIO1_11 
+ to CS signal of J40 (the SPI-SSEL signal)  as described in section 4.3.3
+ of base board users guide.
+ 
+ Please note that there seems to be some problem with the libraries used.  This program
+ downloads the files to the SD card but often looses some of the file data.
+ 
+*/
+
+#include "mbed.h"
+#include "SDFileSystem.h"
+#include "HTTPClient.h"
+
+DigitalOut led1(LED1);// blinks when all done
+DigitalOut led4(LED4);// blinks during file download
+
+HTTPClient http;
+
+Ticker tick;
+
+SDFileSystem sd(p5, p6, p7, p24, "sd");
+
+void blinkLED4() {
+    led4 = !led4;
+}
+
+void dowloadFileToSD(char *url, char *path) {
+
+    // Open a file to write.
+    FILE *fd = fopen(path, "w");
+    if (fd == NULL) {
+        error("Can not write to SD, check SD and reset mbed.\r\n");
+    }
+
+    printf("Downloading to ");
+    printf("%s", path);
+    printf(" please wait ... \r\n");
+
+    tick.attach(& blinkLED4, 0.5);
+    
+    http.get(url, fd);
+
+    // Close the file.
+    fclose(fd);
+
+    tick.detach();
+
+    printf("File downloaded to SD card\r\n");
+    led4 = 0;
+}
+
+
+int main(void) {
+
+    printf("\r\n----------- Starting ------------\r\n");
+
+    printf("Initialising NetServer ....\r\n");
+    //Initialize NetServer which obtains our DHCP address and gets the network interface ready
+    NetServer * net = NetServer::ready();
+
+    printf("\r\nNetwork interface is up\r\n");
+    
+    dowloadFileToSD("http://homepage.ntlworld.com/green_bean/mbed/bong.wav", "/sd/bong.wav" );
+    dowloadFileToSD("http://homepage.ntlworld.com/green_bean/mbed/quarter.wav", "/sd/quarter.wav" );
+    dowloadFileToSD("http://homepage.ntlworld.com/green_bean/mbed/hour.wav", "/sd/hour.wav" );
+
+    printf("-------------- All done ------------\r\n");
+
+    while (1) {
+        led1 = !led1;
+        wait(0.2);
+    }
+}