Twittering with mbed

A simple demo how to use the HTTPClient.

You might find this useful: [http://mbed.org/users/chris/programs/EA_Twitter]

It twitters a message to your twitter account.

Library

Import Library:

http://mbed.org/projects/cookbook/svn/EMAC/lwip/trunk

or import precompiled Library:

http://mbed.org/projects/cookbook/svn/EMAC/lwip/precomp

Import Example program:

http://mbed.org/projects/cookbook/svn/EMAC/lwip/examples/HTTPClient

Hello World

#include "mbed.h"
#include "HTTPClient.h"

using namespace std;
DigitalOut led(LED1);
HTTPClient http;
const char user[] = "<username>";
const char pass[] = "<password>";
const char msg[] = "status=<message>";
const char url[]  = "http://twitter.com/statuses/update.xml";
int main(void) {
    http.auth(user, pass);
    http.post(url, msg);
    while(1) {
        led = !led;
        wait(0.2);
    }
}

API

HTTPClientA simple Class to fetch HTTP Pages.
Functions
HTTPClientCreates an HTTPClient object.
~HTTPClientDestroys the HTTPClient class.
headersAdd header additional Information to the next post or get requests.
authEnables basic authentication.
getA simple get-request just insert the url.
getA simple get-request just insert the url and a FILE Pointer.
postA simple post-request just insert the url.
postA simple get-request just insert the url and a FILE Pointer.
postA simple get-request just insert the url and a two FILE Pointers to send the content of the file out and store you results.
postA simple get-request just insert the url and a two FILE Pointers to send the content of the file out and store you results.
timeoutSets the timout for a HTTP request.
class HTTPClient : public TCPConnection
A simple Class to fetch HTTP Pages.
HTTPClient(const char *hostname =  NULL,
struct ip_addr ip =  ip_addr_any,
struct ip_addr nm =  ip_addr_any,
struct ip_addr gw =  ip_addr_any,
struct ip_addr dns =  ip_addr_any)
Creates an HTTPClient object.
virtual ~HTTPClient()
Destroys the HTTPClient class.
void headers(const char *fields)
Add header additional Information to the next post or get requests.
void auth(const char *user,
const char *password)
Enables basic authentication.
unsigned int get(const char *url,  
char *result =  NULL,
int rsize =  64)
A simple get-request just insert the url.
unsigned int post(const char *url,  
const char *data =  NULL,
char *result =  NULL,
int rsize =  64)
A simple post-request just insert the url.
void timeout(int value)
Sets the timout for a HTTP request.

Resources


Development Log