Example program streaming accelerometer data to a websocket server over a Sprint Mobile Broadband connection
Dependencies: MMA7660 SprintUSBModem WebSocketClient mbed-rtos mbed
Revision 0:0389bce1c74d, committed 2012-09-26
- Comitter:
- donatien
- Date:
- Wed Sep 26 07:08:46 2012 +0000
- Child:
- 1:853199f4d5db
- Commit message:
- Initial commit
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HTTPClient.lib Wed Sep 26 07:08:46 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/HTTPClient/#1f743885e7de
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SprintUSBModem_bleedingedge.lib Wed Sep 26 07:08:46 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/SprintUSBModem_bleedingedge/#f4d9c4ea17f9
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Sep 26 07:08:46 2012 +0000
@@ -0,0 +1,76 @@
+#include "mbed.h"
+#include "SprintUSBModem.h"
+#include "HTTPClient.h"
+
+void test(void const*)
+{
+ SprintUSBModem modem(p18);
+ HTTPClient http;
+ char str[512];
+
+ Thread::wait(5000);
+ printf("Switching power on\r\n");
+
+ modem.power(true);
+
+ int ret = modem.connect();
+ if(ret)
+ {
+ printf("Could not connect\n");
+ return;
+ }
+
+ //GET data
+ printf("Trying to fetch page...\n");
+ 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 text(str, 512);
+ map.put("Hello", "World");
+ map.put("test", "1234");
+ printf("Trying to post data...\n");
+ ret = http.post("http://httpbin.org/post", map, &text);
+ if (!ret)
+ {
+ printf("Executed POST 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());
+ }
+
+ modem.disconnect();
+
+ modem.power(false);
+
+ while(1) {
+ }
+}
+
+
+int main()
+{
+ DBG_INIT();
+ DBG_SET_SPEED(115200);
+ DBG_SET_NEWLINE("\r\n");
+ Thread testTask(test, NULL, osPriorityNormal, 1024 * 5);
+ DigitalOut led(LED1);
+ while(1)
+ {
+ led=!led;
+ Thread::wait(1000);
+ }
+
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Wed Sep 26 07:08:46 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#9654a71f5a90
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Sep 26 07:08:46 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/cd19af002ccc \ No newline at end of file