This is all about HelloWorld to send message to Twitter with proxy Server
Dependencies: WIZnetInterface mbed
main.cpp
00001 00002 #include "mbed.h" 00003 #include "EthernetInterface.h" 00004 00005 #define TOKEN "3252156354-fG0b1utXYAg5IqeJNMSJFlenx1rgSRXm5wgk21l" 00006 00007 int main() 00008 { 00009 00010 int phy_link; 00011 printf("wait a second...\r\n"); 00012 uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x03, 0x04, 0x02}; 00013 00014 EthernetInterface eth; 00015 eth.init(mac_addr); //Use DHCP 00016 00017 while(1) { 00018 00019 eth.connect(); 00020 00021 phy link 00022 do { 00023 phy_link = eth.ethernet_link(); 00024 printf("..."); 00025 wait(2); 00026 } while(!phy_link); 00027 printf("\r\n"); 00028 00029 printf("IP Address is %s\r\n", eth.getIPAddress()); 00030 00031 TCP socket connect 00032 TCPSocketConnection sock; 00033 sock.connect("arduino-tweet.appspot.com", 80); 00034 00035 printf("connected\r\n"); 00036 00037 char message[] = "test1234"; 00038 00039 char len[10]; 00040 char str[10]; 00041 00042 int length = sizeof(message) - 1 + sizeof(TOKEN) - 1 + 14; 00043 00044 printf("%d\r\n",length); 00045 00046 00047 char *cmd1 = "POST http://arduino-tweet.appspot.com/update HTTP/1.0\r\nContent-Length:"; 00048 char *cmd2 = "72"; 00049 char *cmd3 = "\r\n\r\ntoken="; 00050 char *cmd4 = TOKEN; 00051 char *cmd5 = "&status="; 00052 char *cmd6 = message; 00053 char *cmd7 = "\r\n"; 00054 00055 00056 char send_data[1024]; 00057 char buffer[1024]; 00058 sprintf(send_data, "%s%s%s%s%s%s%s", cmd1, cmd2, cmd3, cmd4, cmd5, cmd6, cmd7); 00059 00060 sock.send_all(send_data, sizeof(send_data)-1); 00061 00062 printf("%s\r\n",send_data); 00063 printf("send message done\r\n"); 00064 00065 sock.receive(buffer, sizeof(buffer)-1); 00066 00067 printf("%s\r\n",buffer); 00068 00069 sock.close(); 00070 00071 eth.disconnect(); 00072 00073 wait(70.0); 00074 00075 }; 00076 00077 }
Generated on Wed Jul 20 2022 10:43:20 by 1.7.2