This shows you how to tweet from your mbed

Hello World


This shows you how to tweet from your mbed.

This is basically a simple demo of the HTTPClient and HTTPMap classes, and is a good example for anyone looking to use web-based APIs.


This demo does not yet use the official mbed networking stack


  1. Initialize & setup your network interface (here, Ethernet)
  2. Create your HTTPClient instance
  3. Write your tweet in an HTTPMap instance
  4. POST your tweet ;) (but do not try to recover server's response, it's big and useless!)
  5. Read the result code

...and your tweet is online :).


Example trace with debug on:

Setting up...

HW Addr is : 00:00:00:f0:22:**.

In Setup.

DHCP Started, waiting for IP...

Connected, IP :

Setup OK

URL parsed,
Port: 0
Path: /statuses/update.xml

DNS Query...

DNS Resolved.


Event 0 in HTTPClient::onTcpSocketEvent()

Data [len 22]:

Writing headers:

Authorization: Basic ZGdfY****************==

Content-Length: 22

Content-Type: application/x-www-form-urlencoded

Event 3 in HTTPClient::onTcpSocketEvent()

Event 3 in HTTPClient::onTcpSocketEvent()

Event 2 in HTTPClient::onTcpSocketEvent()

Response OK

Read header : Date: Fri, 09 Apr 2010 16:04:14 GMT
Read header : Server: hi
Read header : Status: 200 OK
Read header : X-Transaction: 1270829053-*****-*****
Read header : ETag: "ab0674524dc*********"
Read header : Last-Modified: Fri, 09 Apr 2010 16:04:13 GMT
Read header : X-Runtime: 0.46079
Read header : Content-Type: application/xml; charset=utf-8
Read header : Content-Length: 1869
Read header : Pragma: no-cache
Read header : X-Revision: DEV
Read header : Expires: Tue, 31 Mar 1981 05:00:00 GMT
Read header : Cache-Control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
Read header : Set-Cookie: guest_id=1270829053758; path=/; expires=Sun, 09 May 2010 16:04:13 GMT
Read header : Set-Cookie: lang=en; path=/
Read header : Set-Cookie: _twitter_sess=********
Read header : Vary: Accept-Encoding
Read header : Connection: close
All headers read.

Done :)!

HTTP Result 0

Req completed.


To go a bit further...

You can also play around with the different storage classes: HTTPMap, HTTPFile, HTTPText (or even create your own)!

You need to log in to post a discussion