This is all about HelloWorld to send message to Twitter with proxy Server

Dependencies:   WIZnetInterface mbed

main.cpp

Committer:
joon874
Date:
2015-08-26
Revision:
0:43bcaa586f60

File content as of revision 0:43bcaa586f60:


#include "mbed.h"
#include "EthernetInterface.h"

#define TOKEN "3252156354-fG0b1utXYAg5IqeJNMSJFlenx1rgSRXm5wgk21l"

int main()
{

    int phy_link;
    printf("wait a second...\r\n");
    uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x03, 0x04, 0x02};

    EthernetInterface eth;
    eth.init(mac_addr); //Use DHCP

    while(1) {

        eth.connect();

         phy link 
        do {
            phy_link = eth.ethernet_link();
            printf("...");
            wait(2);
        } while(!phy_link);
        printf("\r\n");

        printf("IP Address is %s\r\n", eth.getIPAddress());

         TCP socket connect 
        TCPSocketConnection sock;
        sock.connect("arduino-tweet.appspot.com", 80);

        printf("connected\r\n");

        char message[] = "test1234";

        char len[10];
        char str[10];

        int length = sizeof(message) - 1 + sizeof(TOKEN) - 1 + 14;

        printf("%d\r\n",length);

          
        char *cmd1 = "POST http://arduino-tweet.appspot.com/update HTTP/1.0\r\nContent-Length:";
        char *cmd2 = "72";
        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];
        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);

        printf("%s\r\n",send_data);
        printf("send message done\r\n");

        sock.receive(buffer, sizeof(buffer)-1);

        printf("%s\r\n",buffer);

        sock.close();

        eth.disconnect();

        wait(70.0);

    };

}