Webserver and SDWriter on LPC4088QSB

Dependencies:   mbed mbed-rtos EALib EthernetInterface

Revision:
15:08bea8ac9e64
Parent:
11:59dcefdda506
--- a/main.cpp	Wed May 14 15:07:26 2014 +0000
+++ b/main.cpp	Wed May 08 12:04:58 2019 +0000
@@ -1,31 +1,49 @@
 #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());
     
-    TCPSocketConnection sock;
-    sock.connect("mbed.org", 80);
+    //server.open(&eth);
+    server.bind(80);
+    server.listen();
     
-    char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
-    sock.send_all(http_cmd, sizeof(http_cmd)-1);
-    
-    char buffer[300];
-    int ret;
     while (true) {
-        ret = sock.receive(buffer, sizeof(buffer)-1);
-        if (ret <= 0)
-            break;
-        buffer[ret] = '\0';
-        printf("Received %d chars from server:\n%s\n", ret, buffer);
+        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();
+            
+        }
     }
-      
-    sock.close();
-    
-    eth.disconnect();
-    
-    while(1) {}
 }