Using Ethernet Interface to communicate and add a RFID reader

Dependencies:   EthernetInterface ID12RFID mbed-rtos mbed

Revision:
0:053082d6a270
Child:
1:ccc5641be0cd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Oct 17 23:56:29 2013 +0000
@@ -0,0 +1,43 @@
+
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "ID12RFID.h"
+
+ID12RFID rfid(p14); // uart rx
+EthernetInterface eth;
+const char* ECHO_SERVER_ADDRESS = "130.207.234.205";
+const int ECHO_SERVER_PORT = 7;
+
+int main() {
+    printf("Hello World\n");
+    eth.init(); //Use DHCP
+    //print out the MAC address first
+    printf("MAC Address is %s\n", eth.getMACAddress());
+    
+    while(1) {
+        if(rfid.readable()) {
+            int j=rfid.read();
+            //check if using right tag
+            if (j==36902518){
+                printf("Right RFID, Here is the Monitor Info\r\n");
+                eth.connect(7000);//Longer timeout here
+                printf("Client IP Address is %s\n", eth.getIPAddress());
+                TCPSocketConnection socket;
+                while (socket.connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT) < 0) {
+                    printf("Unable to connect to (%s) on port (%d)\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT);
+                    wait(1);
+                }
+                char buf[256]={0};
+                int n = socket.receive(buf, 256);
+                buf[n] = '\0';
+                printf("%s", buf);
+                socket.close();
+                eth.disconnect();        
+            }
+            else
+                printf("Wrong RFID Tag\r\n");
+           
+            printf("Wait for next RFID Tag\r\n");     
+        }
+    }
+}