Websocket example

Dependencies:   C027 UbloxUSBModem WebSocketClient mbed

Fork of VodafoneUSBModemWebsocketTest by Donatien Garnier

Revision:
7:745fa95221ba
Parent:
4:0f0cd888156b
Child:
8:05a5c32037c2
--- a/main.cpp	Tue Oct 30 10:26:24 2012 +0000
+++ b/main.cpp	Mon Oct 21 15:41:42 2013 +0000
@@ -1,44 +1,43 @@
 #include "mbed.h"
-#include "VodafoneUSBModem.h"
+#include "C027.h"
+#include "UbloxUSBGSMModem.h"
+#include "UbloxUSBCDMAModem.h"
+
 #include "Websocket.h"
 
-void test(void const*) 
+void test(void const*)
 {
-    VodafoneUSBModem modem;
+    UbloxUSBGSMModem modem; // for LISA-C use the UbloxUSBCDMAModem instead
     Websocket ws("ws://sockets.mbed.org:443/ws/demo/rw");
     char recv[128];
-    
-    int ret = modem.connect("pp.vodafone.co.uk");
-    if(ret)
-    {
-      printf("Could not connect\n");
-      return;
+
+    int ret = modem.connect("internet"); // eventaully set another apn here
+    if(ret) {
+        printf("Could not connect\n");
+        return;
     }
-    
+
     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++) {
+        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");
+            }
         }
-        
+
         if (ws.read(recv)) {
             printf("rcv: %s\r\n", recv);
         }
 
     }
-    
-    modem.disconnect();  
+
+    modem.disconnect();
 
     while(1) {
     }
@@ -47,13 +46,12 @@
 
 int main()
 {
-  Thread testTask(test, NULL, osPriorityNormal, 1024 * 4);
-  DigitalOut led(LED1);
-  while(1)
-  {
-    led=!led;
-    Thread::wait(1000);  
-  }
+    Thread testTask(test, NULL, osPriorityNormal, 1024 * 4);
+    DigitalOut led(A0);
+    while(1) {
+        led=!led;
+        Thread::wait(1000);
+    }
 
-  return 0;
+    return 0;
 }