Example program demonstrating use of HTTP or HTTPS protocol over a cellular connection with httpbin.org using the MTSAS library. (Demonstrates GET,POST,basic-auth)

Dependencies:   mbed mtsas

Files at this revision

API Documentation at this revision

Comitter:
Vanger
Date:
Thu Aug 07 21:29:51 2014 +0000
Parent:
2:e20a75d47720
Child:
4:09d5f99b94b1
Commit message:
Added for loops to make each step more robust. Added output for "get" request.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Aug 05 14:43:29 2014 +0000
+++ b/main.cpp	Thu Aug 07 21:29:51 2014 +0000
@@ -5,7 +5,8 @@
     //Modify to match your apn if you are using an HSPA radio with a SIM card
     const char APN[] = "";
     
-    /* Sets the log level for INFO level. INFO is a midway log level, available levels are: TRACE, DEBUG, INFO, WARNING, ERROR, FATAL, NONE */
+    //Sets the log level to INFO, higher log levels produce more log output.
+    //Possible levels: NONE, FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
     MTSLog::setLogLevel(MTSLog::INFO_LEVEL);
     
     //Receive buffer
@@ -26,17 +27,13 @@
     
     /** Freescale KL46Z
     * To configure the pins for the Freescale KL46Z board, use configuration B
-    * for the SocketModem. The TX pin should be jumped to pin D2 (JP8), and the
-    * RX pin should be jumped to pin D9 (JP9). 
-    * Uncomment te following line to use the Freescale KL46Z board
+    * Uncomment the following line to use the Freescale KL46Z board
     */
     //MTSSerialFlowControl* io = new MTSSerialFlowControl(D2, D9, D3, D6);
     
-    /** Freescale KL64F
+    /** Freescale K64F
     * To configure the pins for the Freescale KL46Z board, use configuration A
-    * for the SocketModem. The TX pin should be jumped to pin D1 (JP8), and the
-    * RX pin should be jumped to pin D0 (JP9). 
-    * Uncomment te following line to use the Freescale KL46F board
+    * Uncomment the following line to use the Freescale KL46F board
     */
     //MTSSerialFlowControl* io = new MTSSerialFlowControl(D1, D0, D3, D6);
     
@@ -47,19 +44,40 @@
     Cellular* radio = CellularFactory::create(io);
     if( ! radio) {
         logFatal("Radio initialization failed");
+        return 1;
     }
     radio->configureSignals(D4,D7,RESET);
     Transport::setTransport(radio);
     
     //Set up HTTP interface
     HTTPClient* http = new HTTPClient();
-    HTTPText* receive = new HTTPText(rbuf);
+    HTTPText* receive = new HTTPText(rbuf, 4000);
     
-    //Set APN value
-    radio->setApn(APN);
+    //Set radio APN
+    for (int i = 0; i < 10; i++) {
+        if (i >= 10) {
+            logError("Failed to set APN to %s", APN);
+        }
+        if (radio->setApn(APN) == MTS_SUCCESS) {
+            logInfo("Successfully set APN to %s", APN);
+            break;
+        } else {
+            wait(1);
+        }
+    }
     
     //Establish PPP link
-    radio->connect();
+    for (int i = 0; i < 10; i++) {
+        if (i >= 10) {
+            logError("Failed to establish PPP link");
+        }
+        if (radio->connect() == true) {
+            logInfo("Successfully established PPP link");
+            break;
+        } else {
+            wait(1);
+        }
+    }
     
     //Format HTTP Get request
     url = base_url + url_get;
@@ -68,7 +86,7 @@
     for (int i = 0; i < 10; i++) {
         if(http->get(url.c_str(), receive, 5000) == HTTP_OK) {
             http->get(url.c_str(), receive, 5000);
-            logInfo("HTTP get succeeded");
+            logInfo("HTTP get succeeded\n%s",  rbuf);
             break;
         }
         if (i >= 10) {