Wiznet twitter Program

Dependencies:   Adafruit_GFX WIZnetInterface mbed

Fork of Tweeting_Machine_HelloWorld_WIZwiki-W7500 by IOP

Files at this revision

API Documentation at this revision

Comitter:
ajeet3004
Date:
Fri Sep 15 09:35:35 2017 +0000
Parent:
1:5f4bd210e2f0
Commit message:
Changed the method from POST to GET

Changed in this revision

main.cpp 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 5f4bd210e2f0 -r 6d3ef3381abe main.cpp
--- a/main.cpp	Wed May 11 00:51:18 2016 +0000
+++ b/main.cpp	Fri Sep 15 09:35:35 2017 +0000
@@ -2,7 +2,7 @@
 #include "EthernetInterface.h"
 #include "Adafruit_SSD1306.h"
 
-#define TOKEN "3252156354-fG0b1utXYAg5IqeJNMSJFlenx1rgSRXm5wgk21l"
+#define TOKEN "904626807491530753-sOaChz44g9YFS7EuvRkR75l1W9T303K"
 //#define TOKEN "UserToken"
 
 // an SPI sub-class that provides a constructed default
@@ -23,7 +23,7 @@
 int main()
 {
         int phy_link;
-        printf("Wait a second...\r\n");
+         printf("................................Tweeting Machine Program..........................\r\n\r\n");
         //--------- Have to modify the mac address-------------
         uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x03, 0x04, 0x22}; 
         
@@ -35,29 +35,35 @@
         while(1){
                 
             /* phy link */
-            do{
+             while(!phy_link){
+                printf("Failed to obtain IP Adress\r\n\r\n");
                 phy_link = eth.ethernet_link();
                 printf("...");
                 wait(2);
-            }while(!phy_link);
+            }
             printf("\r\n");
-                 
-            printf("IP Address is %s\r\n", eth.getIPAddress());
-              
+            printf("IP Adress obtained\r\n\r\n");    
+            printf("IP Address is: %s\r\n", eth.getIPAddress());
+             while(1){ 
             /* TCP socket connect */
             TCPSocketConnection sock;
             sock.connect("arduino-tweet.appspot.com", 80);
-    
-            printf("connected\r\n\r\n");
-            
+            if(sock.is_connected())
+            {
+                printf("\r\nConnected to the DNS Server\r\n\r\n");
+            }
+            else
+            {
+                printf("\r\nDNS Server connection error\r\n\r\n");
+            }
             /* typing message */        
-            printf("typing twitter message :");
+            printf("Type your tweet:");
             
-            char* message;
+           char* message;
             scanf("%s",message);   
             printf("%s",message);
             printf("\r\n\r\n");
-            
+           
             int len = strlen(message);
             
             /* data length measure */
@@ -74,27 +80,25 @@
             data_len[1] = one + 48;
             data_len[0] = ten + 48;
         
-            char *cmd1 = "POST http://arduino-tweet.appspot.com/update HTTP/1.0\r\nContent-Length:";
-            char *cmd2 = data_len;
-            char *cmd3 = "\r\n\r\ntoken=";
-            char *cmd4 = TOKEN;
-            char *cmd5 = "&status=";
-            char *cmd6 = message;
-            char *cmd7 = "\r\n";
-    
+        
             char send_data[1024];
             char buffer[1024] = {0};
-            sprintf(send_data, "%s%s%s%s%s%s%s", cmd1, cmd2, cmd3, cmd4, cmd5, cmd6, cmd7);
-    
-            sock.send_all(send_data, sizeof(send_data)-1);
+              sprintf(send_data, "GET http://arduino-tweet.appspot.com/update?token=%s&status=%s\r\n",TOKEN,message);
     
-            printf("%s\r\n",send_data);
-            printf("send message done\r\n");
+             if(sock.send_all(send_data, sizeof(send_data))!=-1)
+            {
+                printf("The sent URL is: %s\r\n",send_data);
+                printf("The sent Tweet is: %s",message);
+                printf("\r\nMessage sent successfully\r\n\r\n");
+            }
+            else
+            {
+                printf("\r\nMessage sending failed\r\n\r\n");
+            }
+            printf("Response from the server:\r\n\r\n");
+            sock.receive(buffer, sizeof(buffer));
     
-            sock.receive(buffer, sizeof(buffer)-1);
-    
-            printf("%s\r\n",buffer);
-            
+            printf("%s\r\n",buffer); 
             gOled.begin();
             gOled.printf("%s\r\n",message);
             gOled.display();
@@ -109,3 +113,4 @@
     };
 
 }
+}
\ No newline at end of file
diff -r 5f4bd210e2f0 -r 6d3ef3381abe mbed.bld
--- a/mbed.bld	Wed May 11 00:51:18 2016 +0000
+++ b/mbed.bld	Fri Sep 15 09:35:35 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/a330f0fddbec
\ No newline at end of file