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

Revision:
3:7d9749651663
Parent:
2:72c06f2902d5
--- a/main.cpp	Thu Nov 01 03:00:53 2012 +0000
+++ b/main.cpp	Thu Nov 01 03:45:23 2012 +0000
@@ -1,18 +1,16 @@
 #include "mbed.h"
 #include "SprintUSBModem.h"
 #include "Websocket.h"
-#include "LM75B.h"
+#include "C12832_lcd.h"
 
 void test(void const*)
 {
-    LM75B tmp(p28,p27);
 
     SprintUSBModem modem;
-    // view at http://sockets.mbed.org/demo/viewer
-    Websocket ws("ws://sockets.mbed.org:443/ws/demo/wo");
+    // Send messages at http://sockets.mbed.org/demo/sender
+    Websocket ws("ws://sockets.mbed.org:443/ws/demo/ro");
 
     char recv[128];
-    char msg[32];
 
     modem.power(true);
 
@@ -25,18 +23,19 @@
     bool c = ws.connect();
     printf("Connect result: %s\r\n", c?"OK":"Failed");
 
+    C12832_LCD lcd;
+    lcd.cls();
+
     while (1) {
 
-        sprintf(msg, "Temp = %.1f",tmp.read());
-        int ret = ws.send(msg);
-        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);
+            lcd.cls();
+            lcd.locate(0,3);
+            lcd.printf(recv);
         }
+
         Thread::wait(1000);
-
     }
 
     modem.disconnect();
@@ -47,8 +46,6 @@
 
     printf("Powered off\r\n");
 
-    while(1) {
-    }
 }