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 mbed

Revision:
1:0734a7b0fd5e
Parent:
0:1b55f626a40f
--- a/main.cpp	Fri Jul 09 14:43:39 2010 +0000
+++ b/main.cpp	Fri Aug 13 14:45:50 2010 +0000
@@ -1,78 +1,80 @@
 /*
  Demo of Embedded Artists LPCXpresso baseboard SD card and ethernet facilities.
 
- This program downloads three files from a website to the SD card.
- 
+ This program downloads three .wav 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 
+
+ 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.
- 
+
+ Now uses the HTTPClient from http://mbed.org/users/donatien/programs/HTTPClient/latest
+ which downloads the files without errors.
+
 */
-
 #include "mbed.h"
-#include "SDFileSystem.h"
+#include "SDHCFileSystem.h"
+#include "EthernetNetIf.h"
 #include "HTTPClient.h"
 
 DigitalOut led1(LED1);// blinks when all done
 DigitalOut led4(LED4);// blinks during file download
 
+EthernetNetIf eth;
 HTTPClient http;
 
 Ticker tick;
 
-SDFileSystem sd(p5, p6, p7, p24, "sd");
+//SDFileSystem sd(p5, p6, p7, p8, "sd");//mbed Workshop BOB
+SDFileSystem sd(p5, p6, p7, p24, "sd");//EA baseboard mosi, miso, sclk, CS, name
 
-void blinkLED4() {
+void blinkLED4() {//blinks led4 during download
     led4 = !led4;
 }
 
-void dowloadFileToSD(char *url, char *path) {
+void downloadFileToSD(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");
-    }
+    HTTPFile httpfile(path);
 
     printf("Downloading to ");
     printf("%s", path);
     printf(" please wait ... \r\n");
 
     tick.attach(& blinkLED4, 0.5);
-    
-    http.get(url, fd);
+
+    HTTPResult result = http.get(url, &httpfile);
 
-    // Close the file.
-    fclose(fd);
+    if (result == HTTP_OK) {
+        printf("File downloaded OK\r\n");
+    } else {
+        printf("Error during download %d\r\n", result);
+    }
 
     tick.detach();
 
-    printf("File downloaded to SD card\r\n");
     led4 = 0;
 }
 
-
-int main(void) {
-
-    printf("\r\n----------- Starting ------------\r\n");
+int main() {
 
-    printf("Initialising NetServer ....\r\n");
-    //Initialize NetServer which obtains our DHCP address and gets the network interface ready
-    NetServer * net = NetServer::ready();
+    printf("Connecting to network ...\r\n");
+    EthernetErr ethErr = eth.setup();
+    if (ethErr) {
+        printf("Error %d in setup.\r\n", ethErr);
+        return -1;
+    }
+    printf("Network interface is up\r\n");
 
-    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("\r\n----------- Starting download ------------\r\n");
+
+    downloadFileToSD("http://homepage.ntlworld.com/green_bean/mbed/bong.wav", "/sd/bong.wav" );
+    downloadFileToSD("http://homepage.ntlworld.com/green_bean/mbed/quarter.wav", "/sd/quarter.wav" );
+    downloadFileToSD("http://homepage.ntlworld.com/green_bean/mbed/hour.wav", "/sd/hour.wav" );
 
     printf("-------------- All done ------------\r\n");
 
@@ -80,4 +82,5 @@
         led1 = !led1;
         wait(0.2);
     }
+
 }