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.
Fork of SprintUSBModemHTTPClientTest by
Revision 21:3f45e53afe4f, committed 2013-10-08
- Comitter:
- sam_grove
- Date:
- Tue Oct 08 00:08:22 2013 +0000
- Parent:
- 20:39772b740985
- Commit message:
- Added http client test. Return from post seems to be a bit wonky but haven't looked closely at this
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Oct 07 22:05:31 2013 +0000 +++ b/main.cpp Tue Oct 08 00:08:22 2013 +0000 @@ -7,14 +7,14 @@ void websocketTest(void const*) { SprintUSBModem modem(p18, true, 1); - char msg[2048]; + char msg[2048] = {0}; // Using C16-C20 make sure to connect mbed p18 to J2 pin 16 modem.power(true); int ret = modem.connect(); if(ret) { - error("Modem connect failed: %s %d", __PRETTY_FUNCTION__ , __LINE__); + error("Modem connect failed: %s line %d", __PRETTY_FUNCTION__ , __LINE__); } // See the output on http://sockets.mbed.org/sg_test/viewer @@ -47,11 +47,70 @@ while(1); } +void httpTest(void const*) +{ + SprintUSBModem modem(p18, true, 1); + char const *URL_GET = "http://mbed.org/media/uploads/donatien/hello.txt"; + char const *URL_POST = "http://httpbin.org/post"; + char msg[2048] = {0}; + char buf[32] = {0}; + + // Using C16-C20 make sure to connect mbed p18 to J2 pin 16 + modem.power(true); + int ret = modem.connect(); + if(ret) + { + error("Modem connect failed: %s %d", __PRETTY_FUNCTION__ , __LINE__); + } + + HTTPClient http; + HTTPMap map; + HTTPText text(msg, 512); + + for(int i=0; i<0x7fffffff; ++i) + { + //GET data + ret = http.get(URL_GET, msg, 2048); + if (!ret) + { + printf("%s\n", msg); + } + else + { + printf("%s\n", msg); + error("http.get() = %d \t HTTP return code = %d \t %s, line %d\n", ret, http.getHTTPResponseCode(), __PRETTY_FUNCTION__, __LINE__); + } + + sprintf(buf, "%d", i); + map.put("Loop count", buf); + map.put("mbed", "connect"); + + //POST data + ret = http.post(URL_POST, map, &text); + if (0 == ret) + { + printf("%s\n", msg); + } + else + { + error("http.post() = %d \t HTTP return code = %d \t %s, line %d\n", ret, http.getHTTPResponseCode(), __PRETTY_FUNCTION__, __LINE__); + } + map.clear(); + memset(msg, 0, 2048); + } + + modem.disconnect(); + modem.power(false); + + puts("Powered off Test Complete"); + while(1); +} + int main() { - Thread task(websocketTest, NULL, osPriorityNormal, 1024 * 5); -// Thread task(httpTest, NULL, osPriorityNormal, 1024 * 5); +// Thread task(websocketTest, NULL, osPriorityNormal, 1024 * 5); + Thread task(httpTest, NULL, osPriorityNormal, 1024 * 5); DigitalOut led(LED1);