Websocket client cellular hello world example
Dependencies: C027_Support WebSocketClient mbed
Fork of Websocket_Ethernet_HelloWorld by
Diff: main.cpp
- Revision:
- 6:828d29dc5562
- Parent:
- 4:b33c0bce17dc
- Child:
- 7:6468bb94de0c
--- a/main.cpp Fri May 09 19:36:29 2014 +0000 +++ b/main.cpp Mon May 12 14:01:26 2014 +0000 @@ -1,7 +1,7 @@ #include "mbed.h" +#include "Websocket.h" #include "C027.h" #include "MDM.h" -#include "Websocket.h" //---------------------------------------------------------------------- // You may need to configure these parameters @@ -33,57 +33,39 @@ flash.attach(&flashLED, 1.0f); // turn on the supplies of the Modem and the GPS c027.mdmPower(true); - c027.gpsPower(true); - wait(2); - // Create the modem object + printf("Modem Initialize\r\n"); MDMSerial mdm; + if (!mdm.connect(SIMPIN, APN,USERNAME,PASSWORD, true)) + return -1; - // initialize the modem - printf("Device Init\r\n"); - MDMParser::DevStatus devStatus; - MDMParser::NetStatus netStatus; - bool mdmOk = mdm.init(SIMPIN, &devStatus); - if (mdmOk) - { - // wait until we are connected - printf("Network Check\r\n"); - while (!mdm.checkNetStatus(&netStatus)) - wait_ms(1000); + // view @ http://sockets.mbed.org/demo/viewer + Websocket ws("ws://sockets.mbed.org:443/ws/demo/rw"); + + printf("Websocket\n"); + ws.connect(); + char str[100]; + printf("Websocket connected\n"); - printf("Network Join\r\n"); - // join the internet connection - MDMParser::IP ip = mdm.join(APN,USERNAME,PASSWORD); - if (ip != NOIP) - { - printf(" IP Address: " IPSTR "\r\n", IPNUM(ip)); - // view @ http://sockets.mbed.org/demo/viewer - Websocket ws("ws://sockets.mbed.org:443/ws/demo/rw"); - - printf("Websocket\n"); - ws.connect(); - char str[100]; - printf("Websocket connected\n"); - - for(int i=0; i<0x7fffffff; ++i) { - // string with a message - sprintf(str, "%d WebSocket Hello World over Cellular", i); - ws.send(str); - - // clear the buffer and wait a sec... - memset(str, 0, 100); - wait(0.5f); - - // websocket server should echo whatever we sent it - if (ws.read(str)) { - printf("rcv'd: %s\n", str); - } - } - ws.close(); - mdm.disconnect(); + for(int i=0; i<0x7fffffff; ++i) { + // string with a message + sprintf(str, "%d WebSocket Hello World over Cellular", i); + ws.send(str); + + // clear the buffer and wait a sec... + memset(str, 0, 100); + wait(0.5f); + + // websocket server should echo whatever we sent it + if (ws.read(str)) { + printf("rcv'd: %s\n", str); } } + ws.close(); + + mdm.disconnect(); mdm.powerOff(); c027.mdmPower(false); + printf("Done\n"); while(true); } \ No newline at end of file