Example program that uses the mbed UbloxATCellularInterface or OnboardCellularInterface classes to perform simple sockets operations. This program can be used on the C027 and C030 boards, including the C030 N2xx version with a little editing.

Dependencies:   ublox-at-cellular-interface ublox-cellular-base ublox-cellular-base-n2xx ublox-at-cellular-interface-n2xx

Revision:
35:8e65f2bee044
Parent:
33:48101a4c3f14
Child:
37:98338956aaba
--- a/main.cpp	Wed Feb 28 15:13:03 2018 +0000
+++ b/main.cpp	Tue Feb 12 19:28:22 2019 +0500
@@ -13,7 +13,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 #include "mbed.h"
 #include "UbloxATCellularInterface.h"
 #include "OnboardCellularInterface.h"
@@ -56,6 +55,7 @@
 #define APN         NULL
 #define USERNAME    NULL
 #define PASSWORD    NULL
+#define TCP_SERVER "os.mbed.com"
 
 // LEDs
 DigitalOut ledRed(LED1, 1);
@@ -177,13 +177,13 @@
     
     printf("Getting the IP address of \"developer.mbed.org\" and \"2.pool.ntp.org\"...\n");
     if ((interface->gethostbyname("2.pool.ntp.org", &udpServer) == 0) &&
-        (interface->gethostbyname("developer.mbed.org", &tcpServer) == 0)) {
+        (interface->gethostbyname(TCP_SERVER, &tcpServer) == 0)) {
         pulseEvent();
 
         udpServer.set_port(123);
+        tcpServer.set_port(80);
         printf("\"2.pool.ntp.org\" address: %s on port %d.\n", udpServer.get_ip_address(), udpServer.get_port());
-        printf("\"developer.mbed.org\" address: %s on port %d.\n", tcpServer.get_ip_address(), tcpServer.get_port());
-        tcpServer.set_port(80);
+        printf("\"os.mbed.com\" address: %s on port %d.\n", tcpServer.get_ip_address(), tcpServer.get_port());
 
         printf("Performing socket operations in a loop (until the user button is pressed on C030 or forever on C027)...\n");
         while (!buttonPressed) {
@@ -227,7 +227,7 @@
                 printf("Connecting socket to %s on port %d...\n", tcpServer.get_ip_address(), tcpServer.get_port());
                 if (sockTcp.connect(tcpServer) == 0) {
                     pulseEvent();
-                    printf("Connected, sending HTTP GET request to \"developer.mbed.org\" over socket...\n");
+                    printf("Connected, sending HTTP GET request to %s over socket...\n", TCP_SERVER);
                     strcpy (buf, "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\r\n\r\n");
                     // Note: since this is a short string we can send it in one go as it will
                     // fit within the default buffer sizes.  Normally you should call sock.send()
@@ -267,5 +267,4 @@
         printf("Unable to get IP address of \"developer.mbed.org\" or \"2.pool.ntp.org\".\n");
     }
 }
-
 // End Of File