wf

Dependencies:   Adafruit_GFX WIZnetInterface mbed

Fork of Tweeting_Machine_HelloWorld_WIZwiki-W7500 by IOP

Files at this revision

API Documentation at this revision

Comitter:
wiznetw7500
Date:
Thu Jun 21 06:44:33 2018 +0000
Parent:
1:5f4bd210e2f0
Commit message:
iuytres

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
--- a/main.cpp	Wed May 11 00:51:18 2016 +0000
+++ b/main.cpp	Thu Jun 21 06:44:33 2018 +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
@@ -18,7 +18,9 @@
 
 I2CPreInit gI2C(PA_10,PA_9);
 Adafruit_SSD1306_I2c gOled(gI2C,NC,0x78,64,128);
-
+  const char ip_addr[] = "192.168.0.112"; // WIZwiki-W7500 IP-address
+    const char mask_addr[] = "255.255.255.0"; 
+    const char gateway_addr[] = "192.168.0.1"; 
 
 int main()
 {
@@ -28,7 +30,7 @@
         uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x03, 0x04, 0x22}; 
         
         EthernetInterface eth;
-        eth.init(mac_addr); //Use DHCP
+        eth.init(mac_addr,ip_addr,mask_addr,gateway_addr); //Use DHCP
             
         eth.connect();
         
@@ -46,36 +48,37 @@
               
             /* TCP socket connect */
             TCPSocketConnection sock;
-            sock.connect("arduino-tweet.appspot.com", 80);
-    
+            sock.connect("192.168.93.1", 21);
+    if(sock.is_connected())
             printf("connected\r\n\r\n");
-            
+    else
+            printf("No connection\r\n");
             /* typing message */        
             printf("typing twitter message :");
             
             char* message;
-            scanf("%s",message);   
+           /* scanf("%s",message);   
             printf("%s",message);
             printf("\r\n\r\n");
             
             int len = strlen(message);
             
             /* data length measure */
-            char data_len[2]={0};
-            int ten=0;
-            int one=0;
+          //  char data_len[2]={0};
+            //int ten=0;
+            //int one=0;*/
             
-            int length = len + sizeof(TOKEN) - 1 + 14;
+         //   int length = len + sizeof(TOKEN) - 1 + 14;
             
-            printf("length : %d\r\n\r\n",length);
+       //     printf("length : %d\r\n\r\n",length);
             
-            ten = length/10;
-            one = length%10;
-            data_len[1] = one + 48;
-            data_len[0] = ten + 48;
+           // ten = length/10;
+            //one = length%10;
+            //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 *cmd2 = data_len;
             char *cmd3 = "\r\n\r\ntoken=";
             char *cmd4 = TOKEN;
             char *cmd5 = "&status=";
@@ -84,14 +87,14 @@
     
             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);
+            sprintf(send_data, "GET https://api.thingspeak.com/update?api_key=WQ0EX0W6CA5JK57Z&field1=200\r\n",TOKEN,message);
     
-            sock.send_all(send_data, sizeof(send_data)-1);
+            sock.send_all(send_data, sizeof(send_data));
     
             printf("%s\r\n",send_data);
             printf("send message done\r\n");
     
-            sock.receive(buffer, sizeof(buffer)-1);
+            sock.receive(buffer, sizeof(buffer));
     
             printf("%s\r\n",buffer);
             
--- a/mbed.bld	Wed May 11 00:51:18 2016 +0000
+++ b/mbed.bld	Thu Jun 21 06:44:33 2018 +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/b484a57bc302
\ No newline at end of file