C027_Support library test

Dependencies:   C027_Support

Dependents:   C027_SupportTest_xively_location software_test_v1

Fork of Seeed_GPRS_Library_HelloWorld by wei zou

When running this example make sure you have:

  • edited the SIM PIN, APN, USER and PASSWORD for you network operator
  • have inserted a SIM card with enough credits
  • the antennas connected
  • have good reception (especially for GPS)
  • installed the mbed CDC drivers if you run windows
  • connected a terminal program, such as teraterm

The example will connect the modem to the network and attach it. I will place a post request to download a file from mbed website. It will do a USSD request and finally wait for incoming SMS. It will try to answer your SMS (try asking "where are you").

You should see a similar output in your preferred console program:

C027 Support Example
Device Init
Device Status:
  Device:       SARA-G350
  Power Save:   Active
  SIM:          Ready
  CCID:         xxxxxxxxxxxxxxxxxxxxxxxxxxx
  IMEI:         xxxxxxxxxxxxxxxxxxx
  IMSI:         xxxxxxxxxxxxxxxxxxx
  Manufacturer: u-blox
  Model:        SARA-G350
  Version:      08.49
Network Check
Network Status:
  Registration:       Home
  Signal Strength:    -87 dBm
  Operator:           Swisscom
  Phone Number:       +41xxxxxxxxxxx
Network Join
  IP Address: xx.xx.xx.xx
Socket Create
Socket Connect
Make a Http Post Request
Socket Send
Socket Recving
Socket 0: 337 bytes pending
Socket 0: 145 bytes pending
Socket 0: closed by remote host
Socket Recv "HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Thu, 10 Apr 2014 13:09:02 GMT
Content-Type: text/plain
Connection: close
Last-Modified: Fri, 27 Jul 2012 13:30:34 GMT
Cache-Control: max-age=36000
Expires: Thu, 10 Apr 2014 20:43:53 GMT
Vary: Accept-Encoding
X-Mystery-Header: 260358892
X-be: web0_prod_sjc
Age: 8709

Hello world!
"
Socket Close
Socket Free
Network Disconnect
Send Ussd Command *#134#
Got Ussd Answer: "UNKNOWN APPLICATION"
Checking SMS and GPS
GPS Location: 47.28xxx 8.56xxx
GPS Location: 47.28xxx 8.56xxx
...
GPS Location: 47.28xxx 8.56xxx
GPS Location: 47.28xxx 8.56xxx
Network Status:
  Registration:       Home
  Signal Strength:    -89 dBm
  Operator:           Swisscom
  Phone Number:       +41xxxxxxxxx
GPS Location: 47.28xxx 8.56xxx
GPS Location: 47.28xxx 8.56xxx
...
Revision:
16:43f6de7bc38b
Parent:
15:ea10b6cf8c85
Child:
17:c293780a40ac
--- a/main.cpp	Tue May 13 09:35:14 2014 +0000
+++ b/main.cpp	Wed May 14 05:56:27 2014 +0000
@@ -71,7 +71,7 @@
 int main(void)
 {
     int ret;
-    char buf[512] = "";
+    char buf[2048] = "";
 
     // only trace if the serial is different from our modem port
     if (DOTRACE) {
@@ -138,6 +138,7 @@
             if (socket >= 0)
             {
                 TRACE("Socket Connect\r\n");
+                mdm.socketSetBlocking(socket, 10000);
                 if (mdm.socketConnect(socket, "mbed.org", 80))
                 {
                     TRACE("Make a Http Post Request\r\n");
@@ -162,6 +163,74 @@
                 mdm.socketFree(socket);
             }
             
+            int port = 7;
+            const char* host = "echo.u-blox.com";
+            MDMParser::IP ip = mdm.gethostbyname(host);
+            char data[] = "\r\nxxx Socket Hello World\r\n"
+#if 1
+            "00  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "01  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "02  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "03  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "04  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            
+            "05  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "06  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "07  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "08  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "09  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+
+            "10  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "11  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "12  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "13  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "14  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            
+            "15  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "16  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "17  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "18  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+            "19  0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
+#endif            
+            "End\r\n";
+                
+            TRACE("Testing TCP sockets with ECHO server\r\n");
+            socket = mdm.socketSocket(MDMParser::IPPROTO_TCP);
+            if (socket >= 0)
+            {
+                mdm.socketSetBlocking(socket, 10000);
+                if (mdm.socketConnect(socket, host, port)) {
+                    memcpy(data, "\r\nTCP", 5); 
+                    ret = mdm.socketSend(socket, data, sizeof(data)-1);
+                    if (ret == sizeof(data)-1) {
+                        TRACE("Socket Send %d \"%s\"\r\n", ret, data);
+                    }
+                    ret = mdm.socketRecv(socket, buf, sizeof(buf)-1);
+                    if (ret >= 0) {
+                        TRACE("Socket Recv %d \"%.*s\"\r\n", ret, ret, buf);
+                    }
+                    mdm.socketClose(socket);
+                }
+                mdm.socketFree(socket);
+            }
+
+            TRACE("Testing UDP sockets with ECHO server\r\n");
+            socket = mdm.socketSocket(MDMParser::IPPROTO_UDP, port);
+            if (socket >= 0)
+            {
+                mdm.socketSetBlocking(socket, 10000);
+                memcpy(data, "\r\nUDP", 5); 
+                ret = mdm.socketSendTo(socket, ip, port, data, sizeof(data)-1);
+                if (ret == sizeof(data)-1) {
+                    TRACE("Socket SendTo %s:%d " IPSTR " %d \"%s\"\r\n", host, port, IPNUM(ip), ret, data);
+                }
+                ret = mdm.socketRecvFrom(socket, &ip, &port, buf, sizeof(buf)-1);
+                if (ret >= 0) {
+                    TRACE("Socket RecvFrom " IPSTR ":%d %d \"%.*s\" \r\n", IPNUM(ip),port, ret, ret,buf);
+                }
+                mdm.socketFree(socket);
+            }
+            
             // disconnect  
             TRACE("Network Disconnect\r\n");
             mdm.disconnect();