Websocket example
Dependencies: C027 UbloxUSBModem WebSocketClient mbed
Fork of VodafoneUSBModemWebsocketTest by
Revision 11:c329ae939cd5, committed 2014-02-03
- Comitter:
- sam_grove
- Date:
- Mon Feb 03 16:03:32 2014 +0000
- Parent:
- 10:495e03a3fc8f
- Commit message:
- Updated for CMDA modem, changed the demo and added the modem boot code
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 495e03a3fc8f -r c329ae939cd5 main.cpp --- a/main.cpp Wed Nov 06 10:48:00 2013 +0000 +++ b/main.cpp Mon Feb 03 16:03:32 2014 +0000 @@ -10,10 +10,18 @@ void test(void const*) { c027.mdmPower(true); - UbloxUSBGSMModem modem; // for LISA-C use the UbloxUSBCDMAModem instead + c027.mdmReset(); + c027.mdmWakeup(); + UbloxUSBCDMAModem modem(NC, true, 1); // for LISA-C use the UbloxUSBCDMAModem instead + modem.power(true); + Thread::wait(1000); + + // See the output on http://sockets.mbed.org/demo/viewer Websocket ws("ws://sockets.mbed.org:443/ws/demo/rw"); - char recv[128]; - + char msg[512] = {0}; + Timer t; + t.start(); + int ret = modem.connect("internet"); // eventaully set another apn here if(ret) { printf("Could not connect\n"); @@ -23,20 +31,25 @@ bool c = ws.connect(); printf("Connect result: %s\n", c?"OK":"Failed"); - for(int i = 0; i < 10000; i++) { - if(!(i%100)) { - int ret = ws.send("WebSocket Hello World over the Vodafone Network!"); - if(ret<0) { - printf("Timeout\n"); - ws.close(); - c = ws.connect(); - printf("Connect result: %s\n", c?"OK":"Failed"); - } + for(int i = 0; i < 10000; i++) + { + ws.connect(); + // create json string with acc/tmp data + sprintf(msg, "Testing mbed Websockets Loop: %d", i); + ws.send(msg); + wait(0.5f); + memset(msg, 0, 512); + + if (ws.read(msg)) + { + printf("rcv: %s\r\n", msg); } - - if (ws.read(recv)) { - printf("rcv: %s\r\n", recv); + else + { + printf("Loop %d ws.read() returns 0\n \t %s, line %d @ %6.2f seconds\n", i, __FILE__, __LINE__, t.read()); + wait(5.0f); } + ws.close(); }