HTTP_SERVER

Dependencies:   mbed mbed-rtos SDFileSystem EthernetInterface BME280

Committer:
barti19941
Date:
Tue Nov 06 19:47:08 2018 +0000
Revision:
0:795a02b2bb68
Child:
1:baaf95f8d272
Wersja 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
barti19941 0:795a02b2bb68 1 #include "mbed.h"
barti19941 0:795a02b2bb68 2 #include "SDFileSystem.h"
barti19941 0:795a02b2bb68 3
barti19941 0:795a02b2bb68 4 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS
barti19941 0:795a02b2bb68 5 Serial pc(USBTX, USBRX);
barti19941 0:795a02b2bb68 6 FILE *fp;
barti19941 0:795a02b2bb68 7 char buffer[1024];
barti19941 0:795a02b2bb68 8
barti19941 0:795a02b2bb68 9 int main() {
barti19941 0:795a02b2bb68 10 pc.printf("Initializing \n");
barti19941 0:795a02b2bb68 11 wait(2);
barti19941 0:795a02b2bb68 12 /*
barti19941 0:795a02b2bb68 13 fp = fopen("/sd/hello.txt", "r");
barti19941 0:795a02b2bb68 14 if (fp != NULL) {
barti19941 0:795a02b2bb68 15 fclose(fp);
barti19941 0:795a02b2bb68 16 remove("/sd/hello.txt");
barti19941 0:795a02b2bb68 17 pc.printf("Remove an existing file with the same name \n");
barti19941 0:795a02b2bb68 18 }
barti19941 0:795a02b2bb68 19
barti19941 0:795a02b2bb68 20 printf("\nWriting data to the sd card \n");
barti19941 0:795a02b2bb68 21 fp = fopen("/sd/hello.txt", "w");
barti19941 0:795a02b2bb68 22 if (fp == NULL) {
barti19941 0:795a02b2bb68 23 pc.printf("Unable to write the file \n");
barti19941 0:795a02b2bb68 24 } else {
barti19941 0:795a02b2bb68 25 fprintf(fp, "mbed SDCard application!");
barti19941 0:795a02b2bb68 26 fclose(fp);
barti19941 0:795a02b2bb68 27 pc.printf("File successfully written! \n");
barti19941 0:795a02b2bb68 28 }
barti19941 0:795a02b2bb68 29
barti19941 0:795a02b2bb68 30 printf("\nReading data from the SD card. \n");
barti19941 0:795a02b2bb68 31 fp = fopen("/sd/hello.txt", "r");
barti19941 0:795a02b2bb68 32 if (fp != NULL) {
barti19941 0:795a02b2bb68 33 int size = fread(buffer, sizeof(char), 1024, fp);
barti19941 0:795a02b2bb68 34 printf("Number of data read: %d, text from hello.txt file: %s \n", size, buffer);
barti19941 0:795a02b2bb68 35 fclose(fp);
barti19941 0:795a02b2bb68 36 }
barti19941 0:795a02b2bb68 37 printf("End of Lab 4. \n");
barti19941 0:795a02b2bb68 38 */
barti19941 0:795a02b2bb68 39 }