init

Dependencies:   WIZnet_Library mbed

Fork of W5500HelloWorld by Ganesh Gore

Files at this revision

API Documentation at this revision

Comitter:
ganeshgore
Date:
Tue Jun 30 06:35:18 2015 +0000
Parent:
2:1e8031dab116
Commit message:
Initial Commit;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Jun 06 15:37:41 2015 +0000
+++ b/main.cpp	Tue Jun 30 06:35:18 2015 +0000
@@ -1,51 +1,30 @@
 #include "mbed.h"
 #include "WIZnetInterface.h"
 
-#define USE_DHCP    1
-
-#define LOOPBACKPORT    5000
-
-const char * IP_Addr    = "192.168.1.20";
-const char * IP_Subnet  = "255.255.255.0";
-const char * IP_Gateway = "192.168.1.1";
 unsigned char MAC_Addr[6] = {0x00,0x08,0xDC,0x12,0x07,0x07};
 
-DigitalOut myled1(LED1);
+char* Public_Key = "0lJg1p2RXrSRqvODNmQj";
+char* Private_Key = "D6XGDjbZPdHRYABzqmVl";
+char* ServerIP = "192.168.44.70";
+
 Serial pc(USBTX, USBRX);
-
-//#ifdef TARGET_LPC11U68
 SPI spi(PTD2,PTD3,PTD1);
 WIZnetInterface ethernet(&spi,PTD0,PTA20);
-//#endif
+AnalogIn temp(PTC1);
+
 
 int main()
 {
-    
-    uint8_t mac[6];
-    
-    // set these to match the mac address on the Arduino Ethernet Shield
-    mac[0] = 0x90; mac[1] = 0xa2; mac[2] = 0xda; 
-    mac[3] = 0x0f; mac[4] = 0x0e; mac[5] = 0x07;  // 90:a2:da:0f:0e:63
-    
-    
-    
     //Set serial port baudrate speed: 115200
     pc.baud(115200);
-    pc.printf("Started\r\n");
-
-    //mbed_mac_address((char *)MAC_Addr); //Use mbed mac addres
+    pc.printf("Start\r\n");
+    
+    char count;
 
-    pc.printf("Start\r\n");
-
-    char buffer[256];
 
     while(1) {
-#if USE_DHCP
-        int ret = ethernet.init(mac);
-#else
-        int ret = ethernet.init(MAC_Addr,IP_Addr,IP_Subnet,IP_Gateway);
-#endif
-
+        int ret = ethernet.init(MAC_Addr);
+        
         if (!ret) {
             pc.printf("Initialized, MAC: %s\r\n", ethernet.getMACAddress());
             ret = ethernet.connect();
@@ -60,25 +39,38 @@
             pc.printf("Error ethernet.init() - ret = %d\r\n", ret);
             exit(0);
         }
-        while(1);
-        TCPSocketServer server;
-        server.bind(LOOPBACKPORT);
-        server.listen();
-
-        while (1) {
-            pc.printf("\nWait for new connection...\r\n");
-            TCPSocketConnection client;
-            server.accept(client);
-            client.set_blocking(false, 0); // Timeout=0.
-            pc.printf("Connection from: %s\r\n", client.get_address());
-            while (client.is_connected() == true) {
-                int n = client.receive(buffer, sizeof(buffer));
-                if(n > 0)
-                    client.send_all(buffer, n);
-                if(client.is_fin_received())
-                    client.close();
-            }
-            pc.printf("Disconnected.\r\n");
+        
+    count = 0;    
+    
+    TCPSocketConnection sock;
+    sock.connect(ServerIP, 8080);
+    if(sock.is_connected())
+        printf("Socket Connected\n\r");
+    else
+        printf("Socket NoT Connected\n\r");
+    
+    char buffer[300];
+    int ret_t;
+    
+    
+    for (count=0;count<10;count++){
+        char http_cmd[256]; 
+        
+        sprintf(http_cmd,"GET /input/%s?private_key=%s&var1=%d HTTP/1.0\n\n",Public_Key,Private_Key,count);
+        sock.send_all(http_cmd, sizeof(http_cmd)-1);
+        
+        while (true) {
+            ret_t = sock.receive(buffer, sizeof(buffer)-1);
+            if (ret_t <= 0)
+                break;
+            buffer[ret_t] = '\0';
+            printf("Received %d chars from server:\n%s\n", ret_t, buffer);
         }
     }
-}
+    sock.close();
+    
+    ethernet.disconnect();
+    printf("Socket Closed");
+    
+    while(1) {}
+}}