Webserver and SDWriter on LPC4088QSB

Dependencies:   mbed mbed-rtos EALib EthernetInterface

main.cpp

Committer:
bertonieto
Date:
5 months ago
Revision:
15:08bea8ac9e64
Parent:
11:59dcefdda506

File content as of revision 15:08bea8ac9e64:

#include "mbed.h"
#include "EthernetInterface.h"
#include "MCIFileSystem.h"
#include "TCPSocketConnection.h"

MCIFileSystem mcifs("mci", NC);
TCPSocketServer server;
TCPSocketConnection client;

int main() {
    
    FILE* fp1 = fopen("/mci/test1puta.txt", "a");
    if (fp1) {
        fprintf(fp1, "Hello from EA Pechitos QSB\n");
        for(int i = 0; i < 21; i++) {
            fprintf(fp1, " %d", i);
            //led2 = !led2;
        }
        fprintf(fp1, "\n");
        fclose(fp1);
    }
    
    EthernetInterface eth;
    eth.init(); //Use DHCP
    eth.connect();
    printf("IP Address is %s\n", eth.getIPAddress());
    
    //server.open(&eth);
    server.bind(80);
    server.listen();
    
    while (true) {
        printf("Server bound and listening\n");
 
        while (true) {
            server.accept(client);
    
            printf("Client connected, stack at 0x%08lX\n", client);
        
            char buffer[1024];
            int n; //= client->recv(buffer, sizeof(buffer));
            printf("Received %u bytes from remote host\n", n);
            
            client.send("ESTO ES LA POLLA",16);
            client.close();
            
        }
    }
}