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

Committer:
tom_coxon
Date:
Fri Aug 13 14:45:50 2010 +0000
Revision:
1:0734a7b0fd5e
Parent:
0:1b55f626a40f

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tom_coxon 0:1b55f626a40f 1 /*
tom_coxon 0:1b55f626a40f 2 Demo of Embedded Artists LPCXpresso baseboard SD card and ethernet facilities.
tom_coxon 0:1b55f626a40f 3
tom_coxon 1:0734a7b0fd5e 4 This program downloads three .wav files from a website to the SD card.
tom_coxon 1:0734a7b0fd5e 5
tom_coxon 0:1b55f626a40f 6 SD Card setup:
tom_coxon 1:0734a7b0fd5e 7
tom_coxon 0:1b55f626a40f 8 1. Insert all five jumpers in J39 as described in section 4.3.3
tom_coxon 0:1b55f626a40f 9 of base board users guide.
tom_coxon 1:0734a7b0fd5e 10
tom_coxon 1:0734a7b0fd5e 11 2. Remove jumper marked "A" in J55 In order to connect PIO1_11
tom_coxon 0:1b55f626a40f 12 to CS signal of J40 (the SPI-SSEL signal) as described in section 4.3.3
tom_coxon 0:1b55f626a40f 13 of base board users guide.
tom_coxon 1:0734a7b0fd5e 14
tom_coxon 1:0734a7b0fd5e 15 Now uses the HTTPClient from http://mbed.org/users/donatien/programs/HTTPClient/latest
tom_coxon 1:0734a7b0fd5e 16 which downloads the files without errors.
tom_coxon 1:0734a7b0fd5e 17
tom_coxon 0:1b55f626a40f 18 */
tom_coxon 0:1b55f626a40f 19 #include "mbed.h"
tom_coxon 1:0734a7b0fd5e 20 #include "SDHCFileSystem.h"
tom_coxon 1:0734a7b0fd5e 21 #include "EthernetNetIf.h"
tom_coxon 0:1b55f626a40f 22 #include "HTTPClient.h"
tom_coxon 0:1b55f626a40f 23
tom_coxon 0:1b55f626a40f 24 DigitalOut led1(LED1);// blinks when all done
tom_coxon 0:1b55f626a40f 25 DigitalOut led4(LED4);// blinks during file download
tom_coxon 0:1b55f626a40f 26
tom_coxon 1:0734a7b0fd5e 27 EthernetNetIf eth;
tom_coxon 0:1b55f626a40f 28 HTTPClient http;
tom_coxon 0:1b55f626a40f 29
tom_coxon 0:1b55f626a40f 30 Ticker tick;
tom_coxon 0:1b55f626a40f 31
tom_coxon 1:0734a7b0fd5e 32 //SDFileSystem sd(p5, p6, p7, p8, "sd");//mbed Workshop BOB
tom_coxon 1:0734a7b0fd5e 33 SDFileSystem sd(p5, p6, p7, p24, "sd");//EA baseboard mosi, miso, sclk, CS, name
tom_coxon 0:1b55f626a40f 34
tom_coxon 1:0734a7b0fd5e 35 void blinkLED4() {//blinks led4 during download
tom_coxon 0:1b55f626a40f 36 led4 = !led4;
tom_coxon 0:1b55f626a40f 37 }
tom_coxon 0:1b55f626a40f 38
tom_coxon 1:0734a7b0fd5e 39 void downloadFileToSD(char *url, char *path) {
tom_coxon 0:1b55f626a40f 40
tom_coxon 1:0734a7b0fd5e 41 HTTPFile httpfile(path);
tom_coxon 0:1b55f626a40f 42
tom_coxon 0:1b55f626a40f 43 printf("Downloading to ");
tom_coxon 0:1b55f626a40f 44 printf("%s", path);
tom_coxon 0:1b55f626a40f 45 printf(" please wait ... \r\n");
tom_coxon 0:1b55f626a40f 46
tom_coxon 0:1b55f626a40f 47 tick.attach(& blinkLED4, 0.5);
tom_coxon 1:0734a7b0fd5e 48
tom_coxon 1:0734a7b0fd5e 49 HTTPResult result = http.get(url, &httpfile);
tom_coxon 0:1b55f626a40f 50
tom_coxon 1:0734a7b0fd5e 51 if (result == HTTP_OK) {
tom_coxon 1:0734a7b0fd5e 52 printf("File downloaded OK\r\n");
tom_coxon 1:0734a7b0fd5e 53 } else {
tom_coxon 1:0734a7b0fd5e 54 printf("Error during download %d\r\n", result);
tom_coxon 1:0734a7b0fd5e 55 }
tom_coxon 0:1b55f626a40f 56
tom_coxon 0:1b55f626a40f 57 tick.detach();
tom_coxon 0:1b55f626a40f 58
tom_coxon 0:1b55f626a40f 59 led4 = 0;
tom_coxon 0:1b55f626a40f 60 }
tom_coxon 0:1b55f626a40f 61
tom_coxon 1:0734a7b0fd5e 62 int main() {
tom_coxon 0:1b55f626a40f 63
tom_coxon 1:0734a7b0fd5e 64 printf("Connecting to network ...\r\n");
tom_coxon 1:0734a7b0fd5e 65 EthernetErr ethErr = eth.setup();
tom_coxon 1:0734a7b0fd5e 66 if (ethErr) {
tom_coxon 1:0734a7b0fd5e 67 printf("Error %d in setup.\r\n", ethErr);
tom_coxon 1:0734a7b0fd5e 68 return -1;
tom_coxon 1:0734a7b0fd5e 69 }
tom_coxon 1:0734a7b0fd5e 70 printf("Network interface is up\r\n");
tom_coxon 0:1b55f626a40f 71
tom_coxon 0:1b55f626a40f 72
tom_coxon 1:0734a7b0fd5e 73 printf("\r\n----------- Starting download ------------\r\n");
tom_coxon 1:0734a7b0fd5e 74
tom_coxon 1:0734a7b0fd5e 75 downloadFileToSD("http://homepage.ntlworld.com/green_bean/mbed/bong.wav", "/sd/bong.wav" );
tom_coxon 1:0734a7b0fd5e 76 downloadFileToSD("http://homepage.ntlworld.com/green_bean/mbed/quarter.wav", "/sd/quarter.wav" );
tom_coxon 1:0734a7b0fd5e 77 downloadFileToSD("http://homepage.ntlworld.com/green_bean/mbed/hour.wav", "/sd/hour.wav" );
tom_coxon 0:1b55f626a40f 78
tom_coxon 0:1b55f626a40f 79 printf("-------------- All done ------------\r\n");
tom_coxon 0:1b55f626a40f 80
tom_coxon 0:1b55f626a40f 81 while (1) {
tom_coxon 0:1b55f626a40f 82 led1 = !led1;
tom_coxon 0:1b55f626a40f 83 wait(0.2);
tom_coxon 0:1b55f626a40f 84 }
tom_coxon 1:0734a7b0fd5e 85
tom_coxon 0:1b55f626a40f 86 }