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
...

Files at this revision

API Documentation at this revision

Comitter:
mazgch
Date:
Tue Apr 08 12:16:23 2014 +0000
Parent:
1:46f9e36be3fa
Child:
3:7fd34a81739a
Commit message:
first release of example

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
GPRSInterface.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.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	Tue Apr 08 12:16:23 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/ublox/code/C027/#3ce62caf4518
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C027_Support.lib	Tue Apr 08 12:16:23 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/ublox/code/C027_Support/#4045d02e44f1
--- a/GPRSInterface.lib	Thu Feb 27 07:39:06 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/lawliet/code/GPRSInterface/#1142bdd07989
--- a/main.cpp	Thu Feb 27 07:39:06 2014 +0000
+++ b/main.cpp	Tue Apr 08 12:16:23 2014 +0000
@@ -20,54 +20,149 @@
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
-#include "GPRSInterface.h"
 #include "mbed.h"
+#include "C027.h"
+#include "GPS.h"
+#include "MDM.h"
 
-#if defined(TARGET_LPC11U24)//SEEEDUINO_ARCH
-#define PIN_TX        P1_22
-#define PIN_RX        P1_21
-#elif defined(TARGET_LPC1768)//SEEEDUINO_ARCH_PRO
-#define PIN_TX        P0_0
-#define PIN_RX        P0_1
-#else //please redefine the following pins
-#define PIN_TX
-#define PIN_RX
-#endif
+C027 c027;
 
-GPRSInterface gprsInterface(PIN_TX,PIN_RX,19200,"cmnet",NULL,NULL);
 
 int main(void)
 {
-    // use DHCP
-    gprsInterface.init();
+    int ret;
+    char buf[512] = "";
 
-    // attempt DHCP
-    while(false == gprsInterface.connect()) {
-        wait(2);
-    }
+    Serial pc(USBTX,USBRX);
+    pc.baud(115200);
+    
+    printf("Modem Example\n");
+
+    c027.mdmPower(true);
+    wait(2);
 
-    // successful DHCP
-    printf("IP Address is %s\n", gprsInterface.getIPAddress());
+#if 0
+    c027.gpsPower(true);
+    GPSI2C gps; // use GPSI2C or GPSSerial class 
+    while (1)
+    {
+        while ((ret = gps.getMessage(buf, sizeof(buf))) > 0)
+        {
+            int len = LENGTH(ret);
+            //printf("NMEA: %.*s\n", len-2, msg); 
+            if ((PROTOCOL(ret) == NMEA) && (len > 6) && !strncmp("$GPGLL", buf, 6))
+            {
+                double la = 0, lo = 0;
+                char ch;
+                if (gps.getNmeaAngle(1,buf,len,la) && 
+                    gps.getNmeaAngle(3,buf,len,lo) && 
+                    gps.getNmeaItem(6,buf,len,ch) && ch == 'A')
+                {
+                    printf("GPS: %.5f %.5f\n", la, lo); 
+                }
+            }
+        }
+        wait_ms(100);
+    }
+#endif    
 
-    TCPSocketConnection sock;
-    if(false == sock.connect("mbed.org", 80)) {
-        return -1;
-    }
+    MDMSerial mdm(MDMTXD, MDMRXD, MDMBAUD
+#if DEVICE_SERIAL_FC
+                 ,MDMRTS,MDMCTS
+#endif
+                );
+                
+    // initialize the modem 
+    printf("Init\r\n");
+    mdm.init();
+    
+    // wait until we are connected
+    printf("Network Check\r\n");
+    while (!mdm.checkNetStatus())
+        wait_ms(1000);
 
-    char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\r\n\r\n";
-    sock.send_all(http_cmd, sizeof(http_cmd)-1);
-
-    char buffer[512];
-    int ret;
-    while (true) {
-        ret = sock.receive(buffer, sizeof(buffer)-1);
-        if (ret <= 0)
-            break;
-        buffer[ret] = '\0';
-        printf("Recv %d bytes:\n%s\n",ret,buffer);
+    printf("Network Join\r\n");
+    // join the internet connection 
+    if (mdm.join("gprs.swisscom.ch"))
+    {
+        printf("Socket Create\r\n");
+        int socket = mdm.socketSocket(MDMParser::IPPROTO_TCP);
+        if (socket >= 0)
+        {
+            printf("Socket Connect\r\n");
+            if (mdm.socketConnect(socket, "mbed.org", 80))
+            {
+                printf("Make a Http Post Request\r\n");
+                const char http[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\r\n\r\n";
+                printf("Socket Send\r\n");
+                mdm.socketSend(socket, http, sizeof(http)-1);
+            
+                printf("Socket Recving\r\n");
+                while (true) {
+                    ret = mdm.socketReadable(socket);
+                    if (ret > 0)
+                        ret = mdm.socketRecv(socket, buf, sizeof(buf)-1);
+                    if (ret < 0)
+                        break;
+                    else if (ret > 0)
+                        printf("Socket Recv \"%*s\"\r\n", ret, buf);
+                }
+                printf("Socket Close\r\n");
+                mdm.socketClose(socket);
+            }
+            printf("Socket Free\r\n");
+            mdm.socketFree(socket);
+        }
+        
+        // disconnect  
+        printf("Network Disconnect\r\n");
+        mdm.disconnect();
     }
-    sock.close();
-    gprsInterface.disconnect();
-
+    
+    const char* ussd = "*#134#";
+    printf("Send Ussd Command %s\r\n", ussd);
+    ret = mdm.ussdCommand(ussd, buf, sizeof(buf));
+    if (ret > 0) 
+        printf("Got Ussd Answer: \"%*s\"\r\n", ret, buf);
+        
+    printf("Checking SMS\r\n");
+    //int cnt = mdm.smsCount();
+    while (1) {
+        char num[32];
+        for (int ix = 0; ix < 16; ix ++) {
+            if (mdm.smsRead(ix, num, buf, sizeof(buf))) {
+                printf("Got SMS from \"%s\" with text \"%s\"\r\n", num, buf);
+                printf("Delete SMS at index %d\r\n", ix);
+                mdm.smsDelete(ix);
+                const char* reply = "Hello my friend";
+                printf("Send SMS reply \"%s\" to \"%s\"\r\n", reply, num);
+                mdm.smsSend(num, reply);
+            }
+        }
+        MDMParser::Status info;
+        if (mdm.checkNetStatus(&info))
+        {
+            printf("Network Status:\n");
+            const char* txtNet[] = { "Unknown", "Denied", "None", "Home", "Roaming" };
+            if (info.net < sizeof(txtNet)/sizeof(*txtNet) && (info.net != MDMParser::NET_UNKNOWN))
+                printf("  Network:            %s\n", txtNet[info.net]);
+            const char* txtAct[] = { "Unknown", "GSM", "Edge", "3G", "CDMA" };
+            if (info.act < sizeof(txtAct)/sizeof(*txtAct) && (info.act != MDMParser::ACT_UNKNOWN))
+                printf("  Access Technology:  %s\n", txtAct[info.act]);
+            if (info.rssi) 
+                printf("  Signal Strength:    %d dBm\r\n", info.rssi);
+            if (info.opr)  
+                printf("  Operator:           %s\n", info.opr);
+            if (info.num)  
+                printf("  Phone Number:       %s\n", info.num);
+        }
+        wait_ms(10000);
+    }  
+    
+    mdm.powerOff();
+    // now it is safe to switch off
+    c027.mdmPower(false);
+    
     return 0;
 }
+
--- a/mbed.bld	Thu Feb 27 07:39:06 2014 +0000
+++ b/mbed.bld	Tue Apr 08 12:16:23 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/6473597d706e
\ No newline at end of file