![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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
main.cpp@0:1b55f626a40f, 2010-07-09 (annotated)
- Committer:
- tom_coxon
- Date:
- Fri Jul 09 14:43:39 2010 +0000
- Revision:
- 0:1b55f626a40f
- Child:
- 1:0734a7b0fd5e
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:1b55f626a40f | 4 | This program downloads three files from a website to the SD card. |
tom_coxon | 0:1b55f626a40f | 5 | |
tom_coxon | 0:1b55f626a40f | 6 | SD Card setup: |
tom_coxon | 0:1b55f626a40f | 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 | 0:1b55f626a40f | 10 | |
tom_coxon | 0:1b55f626a40f | 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 | 0:1b55f626a40f | 14 | |
tom_coxon | 0:1b55f626a40f | 15 | Please note that there seems to be some problem with the libraries used. This program |
tom_coxon | 0:1b55f626a40f | 16 | downloads the files to the SD card but often looses some of the file data. |
tom_coxon | 0:1b55f626a40f | 17 | |
tom_coxon | 0:1b55f626a40f | 18 | */ |
tom_coxon | 0:1b55f626a40f | 19 | |
tom_coxon | 0:1b55f626a40f | 20 | #include "mbed.h" |
tom_coxon | 0:1b55f626a40f | 21 | #include "SDFileSystem.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 | 0:1b55f626a40f | 27 | HTTPClient http; |
tom_coxon | 0:1b55f626a40f | 28 | |
tom_coxon | 0:1b55f626a40f | 29 | Ticker tick; |
tom_coxon | 0:1b55f626a40f | 30 | |
tom_coxon | 0:1b55f626a40f | 31 | SDFileSystem sd(p5, p6, p7, p24, "sd"); |
tom_coxon | 0:1b55f626a40f | 32 | |
tom_coxon | 0:1b55f626a40f | 33 | void blinkLED4() { |
tom_coxon | 0:1b55f626a40f | 34 | led4 = !led4; |
tom_coxon | 0:1b55f626a40f | 35 | } |
tom_coxon | 0:1b55f626a40f | 36 | |
tom_coxon | 0:1b55f626a40f | 37 | void dowloadFileToSD(char *url, char *path) { |
tom_coxon | 0:1b55f626a40f | 38 | |
tom_coxon | 0:1b55f626a40f | 39 | // Open a file to write. |
tom_coxon | 0:1b55f626a40f | 40 | FILE *fd = fopen(path, "w"); |
tom_coxon | 0:1b55f626a40f | 41 | if (fd == NULL) { |
tom_coxon | 0:1b55f626a40f | 42 | error("Can not write to SD, check SD and reset mbed.\r\n"); |
tom_coxon | 0:1b55f626a40f | 43 | } |
tom_coxon | 0:1b55f626a40f | 44 | |
tom_coxon | 0:1b55f626a40f | 45 | printf("Downloading to "); |
tom_coxon | 0:1b55f626a40f | 46 | printf("%s", path); |
tom_coxon | 0:1b55f626a40f | 47 | printf(" please wait ... \r\n"); |
tom_coxon | 0:1b55f626a40f | 48 | |
tom_coxon | 0:1b55f626a40f | 49 | tick.attach(& blinkLED4, 0.5); |
tom_coxon | 0:1b55f626a40f | 50 | |
tom_coxon | 0:1b55f626a40f | 51 | http.get(url, fd); |
tom_coxon | 0:1b55f626a40f | 52 | |
tom_coxon | 0:1b55f626a40f | 53 | // Close the file. |
tom_coxon | 0:1b55f626a40f | 54 | fclose(fd); |
tom_coxon | 0:1b55f626a40f | 55 | |
tom_coxon | 0:1b55f626a40f | 56 | tick.detach(); |
tom_coxon | 0:1b55f626a40f | 57 | |
tom_coxon | 0:1b55f626a40f | 58 | printf("File downloaded to SD card\r\n"); |
tom_coxon | 0:1b55f626a40f | 59 | led4 = 0; |
tom_coxon | 0:1b55f626a40f | 60 | } |
tom_coxon | 0:1b55f626a40f | 61 | |
tom_coxon | 0:1b55f626a40f | 62 | |
tom_coxon | 0:1b55f626a40f | 63 | int main(void) { |
tom_coxon | 0:1b55f626a40f | 64 | |
tom_coxon | 0:1b55f626a40f | 65 | printf("\r\n----------- Starting ------------\r\n"); |
tom_coxon | 0:1b55f626a40f | 66 | |
tom_coxon | 0:1b55f626a40f | 67 | printf("Initialising NetServer ....\r\n"); |
tom_coxon | 0:1b55f626a40f | 68 | //Initialize NetServer which obtains our DHCP address and gets the network interface ready |
tom_coxon | 0:1b55f626a40f | 69 | NetServer * net = NetServer::ready(); |
tom_coxon | 0:1b55f626a40f | 70 | |
tom_coxon | 0:1b55f626a40f | 71 | printf("\r\nNetwork interface is up\r\n"); |
tom_coxon | 0:1b55f626a40f | 72 | |
tom_coxon | 0:1b55f626a40f | 73 | dowloadFileToSD("http://homepage.ntlworld.com/green_bean/mbed/bong.wav", "/sd/bong.wav" ); |
tom_coxon | 0:1b55f626a40f | 74 | dowloadFileToSD("http://homepage.ntlworld.com/green_bean/mbed/quarter.wav", "/sd/quarter.wav" ); |
tom_coxon | 0:1b55f626a40f | 75 | dowloadFileToSD("http://homepage.ntlworld.com/green_bean/mbed/hour.wav", "/sd/hour.wav" ); |
tom_coxon | 0:1b55f626a40f | 76 | |
tom_coxon | 0:1b55f626a40f | 77 | printf("-------------- All done ------------\r\n"); |
tom_coxon | 0:1b55f626a40f | 78 | |
tom_coxon | 0:1b55f626a40f | 79 | while (1) { |
tom_coxon | 0:1b55f626a40f | 80 | led1 = !led1; |
tom_coxon | 0:1b55f626a40f | 81 | wait(0.2); |
tom_coxon | 0:1b55f626a40f | 82 | } |
tom_coxon | 0:1b55f626a40f | 83 | } |