Websocket client cellular hello world example

Dependencies:   C027_Support WebSocketClient mbed

Fork of Websocket_Ethernet_HelloWorld by Mbed

Files at this revision

API Documentation at this revision

Comitter:
mazgch
Date:
Fri May 09 17:50:56 2014 +0000
Parent:
3:9bd22e5386cd
Child:
5:8cb771c8cb03
Commit message:
first working version

Changed in this revision

C027.lib Show annotated file Show diff for this revision Revisions of this file
C027_Support.lib Show annotated file Show diff for this revision Revisions of this file
EthernetInterface.lib 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/C027.lib	Fri May 09 17:50:56 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/ublox/code/C027/#89c45165ee87
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C027_Support.lib	Fri May 09 17:50:56 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/ublox/code/C027_Support/#8175b2b72d6b
--- a/EthernetInterface.lib	Fri Oct 25 00:07:04 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/EthernetInterface/#cba86db5ab96
--- a/main.cpp	Fri Oct 25 00:07:04 2013 +0000
+++ b/main.cpp	Fri May 09 17:50:56 2014 +0000
@@ -1,47 +1,89 @@
 #include "mbed.h"
-#include "EthernetInterface.h"
+#include "C027.h"
+#include "MDM.h"
 #include "Websocket.h"
 
+//----------------------------------------------------------------------
+// You may need to configure these parameters
+
+/** Set your secret SIM pin here "1234"
+*/
+#define SIMPIN      NULL
+
+/** The APN of your network operator, sometimes it is "internet" 
+    check your contract with the network operator
+*/
+#define APN         "gprs.swisscom.ch"
+
+/** Set the user name for your APN, or NULL if not needed
+*/
+#define USERNAME    NULL
+
+/** Set the password for your APN, or NULL if not needed
+*/
+#define PASSWORD    NULL 
+
 Ticker flash;
 DigitalOut led(LED1);
 void flashLED(void){led = !led;}
- 
- 
+C027 c027;
+    
 int main() 
 {
     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
+    MDMSerial mdm;
     
-    EthernetInterface ethernet;
-    ethernet.init();    // connect with DHCP
-    int ret_val = ethernet.connect();
-
-    if (0 == ret_val) {
-        printf("IP Address: %s\n", ethernet.getIPAddress());
-    } else {
-        error("ethernet failed to connect: %d.\n", ret_val);
-    }
-
-    // view @ http://sockets.mbed.org/demo/viewer
-    Websocket ws("ws://sockets.mbed.org:443/ws/demo/rw");
-    ws.connect();
-    char str[100];
+    // 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);
     
-    for(int i=0; i<0x7fffffff; ++i) {
-        // string with a message
-        sprintf(str, "%d WebSocket Hello World over Ethernet", 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);
+        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();
         }
     }
-    ws.close();
-    ethernet.disconnect();
+    mdm.powerOff();
+    c027.mdmPower(false);
     
     while(true);
 }
\ No newline at end of file
--- a/mbed-rtos.lib	Fri Oct 25 00:07:04 2013 +0000
+++ b/mbed-rtos.lib	Fri May 09 17:50:56 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#ee87e782d34f
+http://mbed.org/users/mbed_official/code/mbed-rtos/#5dfe422a963d
--- a/mbed.bld	Fri Oct 25 00:07:04 2013 +0000
+++ b/mbed.bld	Fri May 09 17:50:56 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/10b9abbe79a6
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/8a40adfe8776
\ No newline at end of file