An example program that establishes a read-only web socket connection, and echos everything it sees to the LCD

Dependencies:   C12832_lcd SprintUSBModem WebSocketClient mbed-rtos mbed

Fork of SprintUSBModemWebsocketTest-Temp by Chris Styles

Files at this revision

API Documentation at this revision

Comitter:
donatien
Date:
Tue Oct 30 10:01:33 2012 +0000
Child:
1:380f5db5d004
Commit message:
Initial commit

Changed in this revision

SprintUSBModem.lib Show annotated file Show diff for this revision Revisions of this file
WebSocketClient.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SprintUSBModem.lib	Tue Oct 30 10:01:33 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/SprintUSBModem/#0fe5bc472b73
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WebSocketClient.lib	Tue Oct 30 10:01:33 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/samux/code/WebSocketClient/#86e89a0369b9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Oct 30 10:01:33 2012 +0000
@@ -0,0 +1,73 @@
+#include "mbed.h"
+#include "SprintUSBModem.h"
+#include "Websocket.h"
+
+void test(void const*) 
+{
+    SprintUSBModem modem(p18);  
+    Websocket ws("ws://sockets.mbed.org:443/ws/demo/rw");
+    char recv[128];
+    
+    Thread::wait(5000);
+    printf("Switching power on\r\n");
+    
+    modem.power(true);
+    
+    int ret = modem.connect();
+    if(ret)
+    {
+      printf("Could not connect\r\n");
+      return;
+    }
+    
+    bool c = ws.connect();
+    printf("Connect result: %s\r\n", c?"OK":"Failed");
+    
+    for(int i = 0; i < 10000; i++)
+    {
+        if(!(i%100))
+        {
+          int ret = ws.send("WebSocket Hello World!");
+          if(ret<0)
+          {
+            printf("Timeout\r\n");
+            ws.close();
+            c = ws.connect();
+            printf("Connect result: %s\r\n", c?"OK":"Failed");
+          }
+        }
+        
+        if (ws.read(recv)) {
+            printf("rcv: %s\r\n", recv);
+        }
+
+    }
+    
+    modem.disconnect();  
+    
+    printf("Disconnected\r\n");
+    
+    modem.power(false); 
+    
+    printf("Powered off\r\n");
+
+    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	Tue Oct 30 10:01:33 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	Tue Oct 30 10:01:33 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ed12d17f06
\ No newline at end of file