Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@0:bebc049c43f8, 2010-05-25 (annotated)
- Committer:
- donatien
- Date:
- Tue May 25 09:33:50 2010 +0000
- Revision:
- 0:bebc049c43f8
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| donatien | 0:bebc049c43f8 | 1 | #include "mbed.h" |
| donatien | 0:bebc049c43f8 | 2 | #include "EthernetNetIf.h" |
| donatien | 0:bebc049c43f8 | 3 | #include "HttpClient.h" |
| donatien | 0:bebc049c43f8 | 4 | |
| donatien | 0:bebc049c43f8 | 5 | EthernetNetIf eth; |
| donatien | 0:bebc049c43f8 | 6 | |
| donatien | 0:bebc049c43f8 | 7 | int main() { |
| donatien | 0:bebc049c43f8 | 8 | |
| donatien | 0:bebc049c43f8 | 9 | printf("Init\n"); |
| donatien | 0:bebc049c43f8 | 10 | |
| donatien | 0:bebc049c43f8 | 11 | printf("\r\nSetting up...\r\n"); |
| donatien | 0:bebc049c43f8 | 12 | EthernetErr ethErr = eth.setup(); |
| donatien | 0:bebc049c43f8 | 13 | if(ethErr) |
| donatien | 0:bebc049c43f8 | 14 | { |
| donatien | 0:bebc049c43f8 | 15 | printf("Error %d in setup.\n", ethErr); |
| donatien | 0:bebc049c43f8 | 16 | return -1; |
| donatien | 0:bebc049c43f8 | 17 | } |
| donatien | 0:bebc049c43f8 | 18 | printf("\r\nSetup OK\r\n"); |
| donatien | 0:bebc049c43f8 | 19 | |
| donatien | 0:bebc049c43f8 | 20 | HttpClient twitter; |
| donatien | 0:bebc049c43f8 | 21 | |
| donatien | 0:bebc049c43f8 | 22 | HttpMap msg; |
| donatien | 0:bebc049c43f8 | 23 | msg["status"] = "I am tweeting from my mbed!"; //A good example of Key/Value pair use with Web APIs |
| donatien | 0:bebc049c43f8 | 24 | |
| donatien | 0:bebc049c43f8 | 25 | twitter.basicAuth("myuser", "mypass"); //We use basic authentication, replace with you account's parameters |
| donatien | 0:bebc049c43f8 | 26 | |
| donatien | 0:bebc049c43f8 | 27 | //No need to retieve data sent back by the server |
| donatien | 0:bebc049c43f8 | 28 | HttpResult r = twitter.post("http://twitter.com/statuses/update.xml", msg, NULL); |
| donatien | 0:bebc049c43f8 | 29 | if( r == HTTP_OK ) |
| donatien | 0:bebc049c43f8 | 30 | { |
| donatien | 0:bebc049c43f8 | 31 | printf("Tweet sent with success!\n"); |
| donatien | 0:bebc049c43f8 | 32 | } |
| donatien | 0:bebc049c43f8 | 33 | else |
| donatien | 0:bebc049c43f8 | 34 | { |
| donatien | 0:bebc049c43f8 | 35 | printf("Problem during tweeting, return code %d\n", r); |
| donatien | 0:bebc049c43f8 | 36 | } |
| donatien | 0:bebc049c43f8 | 37 | |
| donatien | 0:bebc049c43f8 | 38 | return 0; |
| donatien | 0:bebc049c43f8 | 39 | |
| donatien | 0:bebc049c43f8 | 40 | } |