Integrating the ublox LISA C200 modem
Fork of SprintUSBModemHTTPClientTest by
Diff: main.cpp
- Revision:
- 20:39772b740985
- Parent:
- 19:f1d893c651e5
- Child:
- 21:3f45e53afe4f
--- a/main.cpp Tue Oct 01 17:36:06 2013 -0500 +++ b/main.cpp Mon Oct 07 22:05:31 2013 +0000 @@ -1,106 +1,65 @@ + #include "mbed.h" #include "SprintUSBModem.h" #include "HTTPClient.h" #include "Websocket.h" -char const *msg = "need another reason to merge\n"; -//char const *URL = "http://mbed.org/"; -//char const *URL = "https://www.google.com/"; -char const *URL = "http://httpbin.org/ip"; - -void test(void const*) +void websocketTest(void const*) { SprintUSBModem modem(p18, true, 1); - HTTPClient http; - char str[512]; + char msg[2048]; - Thread::wait(5000); - printf("Switching power on\r\n"); - + // Using C16-C20 make sure to connect mbed p18 to J2 pin 16 modem.power(true); - int ret = modem.connect(); if(ret) { - printf("Could not connect\r\n"); - return; + error("Modem connect failed: %s %d", __PRETTY_FUNCTION__ , __LINE__); } + // See the output on http://sockets.mbed.org/sg_test/viewer Websocket ws("ws://sockets.mbed.org:443/ws/sg_test/rw"); ws.connect(); - char json_str[100]; - for(int i=0; i<100; ++i) + for(int i=0; i<0x7fffffff; ++i) { // create json string with acc/tmp data - sprintf(json_str, "{\"id\":\"test\",\"ax\":%d,\"ay\":%d,\"az\":%d, \"tmp\":%d}", i, i, i, i); - // send str - ws.send(json_str); + sprintf(msg, "Testing mbed Websockets Loop: %d", i); + ws.send(msg); wait(0.5f); - memset(json_str, 0, 100); - if (ws.read(json_str)) + memset(msg, 0, 2048); + + if (ws.read(msg)) { - printf("rcv: %s\r\n", json_str); + printf("rcv: %s\r\n", msg); } - } - ws.close(); - - //GET data - printf("Trying to fetch page...\r\n"); - ret = http.get(URL, str, 128); - if (!ret) - { - printf("Page fetched successfully - read %d characters\r\n", strlen(str)); - printf("Result: %s\r\n", str); - } - else - { - printf("Error - ret = %d - HTTP return code = %d\r\n", ret, http.getHTTPResponseCode()); + else + { + printf("Loop %d ws.read() returns 0\n", i); + } } - //POST data - HTTPMap map; - HTTPText text(str, 512); - map.put("Hello", "World"); - map.put("test", "1234"); - printf("Trying to post data...\r\n"); - ret = http.post("http://httpbin.org/post", map, &text); - if (!ret) - { - printf("Executed POST successfully - read %d characters\r\n", strlen(str)); - printf("Result: %s\r\n", str); - } - else - { - printf("Error - ret = %d - HTTP return code = %d\r\n", ret, http.getHTTPResponseCode()); - } + ws.close(); - printf("Disconnecting\r\n"); - - modem.disconnect(); - - printf("Disconnected\r\n"); - + modem.disconnect(); modem.power(false); - printf("Powered off\r\n"); - - while(1) { - } + puts("Powered off Test Complete"); + 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; + Thread task(websocketTest, NULL, osPriorityNormal, 1024 * 5); +// Thread task(httpTest, NULL, osPriorityNormal, 1024 * 5); + + DigitalOut led(LED1); + + while(1) + { + led = !led; + Thread::wait(1000); + } + + return 0; }