http test case changes

Dependencies:   ublox-cellular-driver-gen gnss ublox-cellular-base ublox-at-cellular-interface-ext

Revision:
20:3ca2d75614e6
Parent:
14:f531abed3446
--- a/main.cpp	Mon Mar 26 15:41:36 2018 +0100
+++ b/main.cpp	Mon Jan 28 12:50:16 2019 +0500
@@ -134,7 +134,8 @@
 //                                                                             true);
     UbloxATCellularInterfaceExt::Error *err;
     UbloxATCellularInterfaceExt::CellLocData data;
-    char buf[1024];
+    const int c_size_of_buffer = 2048;
+    char *buf;
     int httpProfile;
     int numRes;
     GnssSerial gnssSerial; // This needed purely to power on the GNSS chip in 
@@ -153,7 +154,10 @@
     gnssSerial.init();
     good();
     printf("Starting up, please wait up to 180 seconds for network registration to complete...\n");
+
     if (interface->init(PIN)) {
+        int bytesRead = 0;
+
         pulseEvent();
         interface->set_credentials(APN, USERNAME, PASSWORD);
         printf("Registered, connecting to the packet network...\n");
@@ -165,6 +169,8 @@
         }
         pulseEvent();
 
+        buf = (char *) malloc(c_size_of_buffer);
+
         // FTP OPERATIONS
         // Reset FTP parameters to default then set things up
         printf("=== FTP ===\n");
@@ -182,56 +188,84 @@
             pulseEvent();
              // Get a directory listing from the server
              if (interface->ftpCommand(UbloxATCellularInterfaceExt::FTP_LS,
-                                      NULL, NULL, buf, sizeof (buf)) == NULL) {
+                                      NULL, NULL, buf, c_size_of_buffer) == NULL) {
                 pulseEvent();
                 printf ("Directory listing of FTP server:\n"
                         "--------------------------------\n%s"
                         "--------------------------------\n", buf);
              }
-             
              // FTP GET a file known to be on test.rebex.net into the module file system,
              // making sure it's not there to begin with
              interface->delFile("readme.txt");
              if (interface->ftpCommand(UbloxATCellularInterfaceExt::FTP_GET_FILE, "readme.txt") == NULL) {
                 pulseEvent();
                 // Read the file from the module file system into buf
-                if (interface->readFile("readme.txt", buf, sizeof (buf))) {
-                    printf("FTP GET of file \"readme.txt\" completed.  The file contained:\n"
-                           "------------------------------------------------------------\n%s"
-                           "------------------------------------------------------------\n", buf);
+                bytesRead = interface->readFile("readme.txt", buf, c_size_of_buffer);
+
+                if (bytesRead) {
+                    if (bytesRead < c_size_of_buffer) {
+                        // Add null terminator
+                        *(buf + bytesRead) = 0;
+
+                        printf("FTP GET of file \"readme.txt\" completed.  The file contained:\n"
+                                "------------------------------------------------------------\n%s"
+                                "------------------------------------------------------------\n", buf);
+                    }
+                    else {
+                        printf("Error: buffer overflow...\n");
+                    }
+
                 }
-             }            
+                else {
+                    printf("Error: data not read from module's FS...\n");
+                }
+             }
         } else {
             bad();
             printf ("Unable to log in, error class %d, error code %d.\n", err->eClass, err->eCode);
         }
-        
+
         // HTTP OPERATIONS
         // Set up HTTP parameters
         printf("=== HTTP ===\n");
-        printf("Performing HTTP GET on \"developer.mbed.org\"...\n");
+        printf("Performing HTTP GET on \"Github\"...\n");
+        // Make sure bytesRead is equal to 0
+        bytesRead = 0;
+
         httpProfile = interface->httpAllocProfile();
         interface->httpSetTimeout(httpProfile, 30000);
-        interface->httpSetPar(httpProfile, UbloxATCellularInterfaceExt::HTTP_SERVER_NAME, "developer.mbed.org");
-        
+        interface->httpSetPar(httpProfile, UbloxATCellularInterfaceExt::HTTP_SECURE, "1");
+        interface->httpSetPar(httpProfile, UbloxATCellularInterfaceExt::HTTP_SERVER_NAME, "raw.githubusercontent.com");
+
         // Do the HTTP command
         err = interface->httpCommand(httpProfile, UbloxATCellularInterfaceExt::HTTP_GET,
-                                    "/media/uploads/mbed_official/hello.txt",
+                                     "/u-blox/mbed-os/master/features/cellular/mbed_lib.json",
                                      NULL, NULL, 0, NULL,
-                                     buf, sizeof (buf));
+                                     buf, c_size_of_buffer, &bytesRead);
+
         if (err == NULL) {
             pulseEvent();
-            printf("HTTP GET of \"/media/uploads/mbed_official/hello.txt\" completed.  The response contained:\n"
-                   "----------------------------------------------------------------------------------------\n%s"
-                   "----------------------------------------------------------------------------------------\n", buf);
+
+            if(bytesRead > 0 && bytesRead < c_size_of_buffer) {
+                //Add null terminator
+                *(buf + bytesRead) = 0;
+
+                printf("HTTP GET of \"/u-blox/mbed-os/master/features/cellular/mbed_lib.json\" completed.  The response contained:\n"
+                       "----------------------------------------------------------------------------------------\n%s"
+                       "----------------------------------------------------------------------------------------\n", buf);
+            }
+            else {
+                printf("Error: Bytes read is zero");
+            }
         } else {
             bad();
-            printf("Unable to get \"/media/uploads/mbed_official/hello.txt\" from \"developer.mbed.org\", "
+            printf("Unable to get \"/u-blox/mbed-os/master/features/cellular/mbed_lib.json\" from github, "
                    "error class %d, error code %d.\n", err->eClass, err->eCode);
         }
-
+#ifndef TARGET_UBLOX_C030_R41XM
         // CELL LOCATE OPERATIONS (in a loop)
         printf("=== Cell Locate ===\n");
+
         printf("Sending Cell Locate requests in a loop (until the user button is pressed on C030 or forever on C027)...\n");
         while (!buttonPressed) {
             interface->cellLocSrvUdp();
@@ -244,7 +278,7 @@
                 for (int x = 0; (numRes == 0) && (x < 10); x++) {
                     numRes = interface->cellLocGetRes();
                 }
-                
+
                 if (numRes > 0) {
                     interface->cellLocGetData(&data);
                     if (data.validData) {
@@ -257,14 +291,29 @@
                 }
             }
             wait_ms(5000);
+
 #ifndef TARGET_UBLOX_C027
             printf("[Checking if user button has been pressed]\n");
 #endif
         }
-        
+
+        free(buf);
+
+#else
+        while(!buttonPressed) {
+            wait_ms(500);
+            // Shift the LED states
+            int carry = ledBlue;
+            ledBlue = ledRed;
+            ledRed = ledGreen;
+            ledGreen = carry;
+        }
+#endif
+
         pulseEvent();
         printf("User button was pressed, stopping...\n");
         gnssSerial.powerOff();
+
         interface->disconnect();
         interface->deinit();
         ledOff();
@@ -275,4 +324,4 @@
     }
 }
 
-// End Of File
\ No newline at end of file
+// End Of File