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.
Dependencies: EthernetInterface HTTPClient mbed-rtos mbed
Fork of HTTPClient_HelloWorld by
Revision 3:561e6a2908ab, committed 2012-09-24
- Comitter:
- escalion
- Date:
- Mon Sep 24 10:13:13 2012 +0000
- Parent:
- 2:270e2d0bb85a
- Commit message:
- Initial Twitter Implementation
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Aug 30 15:42:06 2012 +0000
+++ b/main.cpp Mon Sep 24 10:13:13 2012 +0000
@@ -1,37 +1,34 @@
+/*----------------------------------------------------------------
+- -
+- Simple twitter demo application -
+- http://mbedtweet.appspot.com/ -
+- Written by Escalion, based on ArduinoTweetLib by NeoCat -
+- -
+----------------------------------------------------------------*/
#include "mbed.h"
#include "EthernetInterface.h"
#include "HTTPClient.h"
+Serial pc(USBTX, USBRX); // tx, rx
EthernetInterface eth;
HTTPClient http;
char str[512];
+char ret;
+const char *DATA = "Test Tweet From Mbed!";
+const char *TOKEN = ""; //get this from http://mbedtweet.appspot.com/
int main()
{
eth.init(); //Use DHCP
eth.connect();
-
- //GET data
- printf("\nTrying to fetch page...\n");
- int ret = http.get("http://mbed.org/media/uploads/donatien/hello.txt", str, 128);
- if (!ret)
- {
- printf("Page fetched successfully - read %d characters\n", strlen(str));
- printf("Result: %s\n", str);
- }
- else
- {
- printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
- }
-
//POST data
HTTPMap map;
HTTPText inText(str, 512);
- map.put("Hello", "World");
- map.put("test", "1234");
- printf("\nTrying to post data...\n");
- ret = http.post("http://httpbin.org/post", map, &inText);
+ map.put("token", TOKEN);
+ map.put("status", DATA);
+ printf("\nSending server tweet...\n");
+ ret = http.post("http://mbedtweet.appspot.com/update", map, &inText);
if (!ret)
{
printf("Executed POST successfully - read %d characters\n", strlen(str));
@@ -39,37 +36,7 @@
}
else
{
- printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
- }
-
- //PUT data
- strcpy(str, "This is a PUT test!");
- HTTPText outText(str);
- //HTTPText inText(str, 512);
- printf("\nTrying to put resource...\n");
- ret = http.put("http://httpbin.org/put", outText, &inText);
- if (!ret)
- {
- printf("Executed PUT successfully - read %d characters\n", strlen(str));
- printf("Result: %s\n", str);
- }
- else
- {
- printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
- }
-
- //DELETE data
- //HTTPText inText(str, 512);
- printf("\nTrying to delete resource...\n");
- ret = http.del("http://httpbin.org/delete", &inText);
- if (!ret)
- {
- printf("Executed DELETE successfully - read %d characters\n", strlen(str));
- printf("Result: %s\n", str);
- }
- else
- {
- printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
+ printf("Error - ret = %d - HTTP return code = %d\n", str, http.getHTTPResponseCode());
}
eth.disconnect();
