A program that sends a image saved to the sd card to a server through a tcp socket connection

Dependencies:   EthernetInterface SDFileSystem mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
pwilson39
Date:
Fri May 01 15:37:20 2015 +0000
Commit message:
Initial commit of program sending an image through tcp socket

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 5cbd9389d9ca EthernetInterface.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Fri May 01 15:37:20 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/EthernetInterface/#097a9996f8d5
diff -r 000000000000 -r 5cbd9389d9ca SDFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Fri May 01 15:37:20 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/mbed_official/code/SDFileSystem/#7b35d1709458
diff -r 000000000000 -r 5cbd9389d9ca main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri May 01 15:37:20 2015 +0000
@@ -0,0 +1,56 @@
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "SDFileSystem.h"
+
+const char* SERVER_ADDRESS = "";
+const int SERVER_PORT = 5005;
+SDFileSystem fs(p5, p6, p7, p8, "sd");
+//LocalFileSystem local("local");               // Create the local filesystem under the name "local"
+
+
+int main() {
+    EthernetInterface eth;
+    eth.init(); //Use DHCP
+    eth.connect();
+    printf("IP Address is %s\n\r", eth.getIPAddress());
+    
+    TCPSocketConnection socket;
+    while (socket.connect(SERVER_ADDRESS, SERVER_PORT) < 0) {
+        printf("Unable to connect to (%s) on port (%d)\n\r", SERVER_ADDRESS, SERVER_PORT);
+        wait(1);
+    }
+    
+    FILE *file;
+    char *buffer;
+    unsigned long fileLen;
+
+    //Open file
+    file = fopen("/sd/IMG_0001.jpg", "rb");
+    if (!file)
+    {
+        fprintf(stderr, "Unable to open file");
+        exit(0);
+    }
+    
+    //Get file length
+    int size;
+
+    fseek(file, 0, SEEK_END);
+    size=ftell(file);
+    fseek(file, 0, SEEK_SET);
+    
+    char send_buffer[size];
+    while(!feof(file)) {
+        fread(send_buffer, 1, sizeof(send_buffer), file);
+        socket.send(send_buffer, sizeof(send_buffer));
+    }
+    
+    free(buffer);
+    printf("Done Sending\n\r");
+
+    
+    socket.close();
+    eth.disconnect();
+    
+    while(true) {}
+}
diff -r 000000000000 -r 5cbd9389d9ca mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Fri May 01 15:37:20 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#5dfe422a963d
diff -r 000000000000 -r 5cbd9389d9ca mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri May 01 15:37:20 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/8ab26030e058
\ No newline at end of file