This shows you how to tweet from your mbed
Hello World
Notes
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.
Information
This demo does not yet use the official mbed networking stack
Step-by-step
- Initialize & setup your network interface (here, Ethernet)
- Create your HTTPClient instance
- Write your tweet in an HTTPMap instance
- POST your tweet ;) (but do not try to recover server's response, it's big and useless!)
- Read the result code
...and your tweet is online :).
Results
Example trace with debug on:
Setting up... HW Addr is : 00:00:00:f0:22:**. In Setup. DHCP Started, waiting for IP... Connected, IP : 10.1.193.21 Setup OK URL parsed, Host: twitter.com Port: 0 Path: /statuses/update.xml DNS Query... DNS Resolved. Connecting... Event 0 in HTTPClient::onTcpSocketEvent() Data [len 22]: status=I+am+an+mbed%21 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