Increasing time for which module remains in PSM.

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

Revision:
4:574b2be59d12
Parent:
3:6debe6b322c4
Child:
6:29f8fd75379d
--- a/main.cpp	Thu Oct 31 07:31:20 2019 +0000
+++ b/main.cpp	Tue Nov 05 16:36:31 2019 +0500
@@ -51,7 +51,6 @@
 #define APN         NULL
 #define USERNAME    NULL
 #define PASSWORD    NULL
-#define TCP_SERVER "os.mbed.com"
 
 // Uncomment the following line to enable Icellular Current measurement.
 // Current drawn by modem is printed on serial every 2 seconds.
@@ -216,13 +215,10 @@
 //    INTERFACE_CLASS *interface = new INTERFACE_CLASS(MDMTXD, MDMRXD,
 //                                                     xxx,
 //                                                     true);
-#ifndef TARGET_UBLOX_C030_N211
-    TCPSocket sockTcp;
-#endif
+
     UDPSocket sockUdp;
     SocketAddress udpServer;
     SocketAddress udpSenderAddress;
-    SocketAddress tcpServer;
     char buf[1024];
     int x;
 #ifdef TARGET_UBLOX_C027
@@ -275,6 +271,7 @@
 
         print_function("please wait up to 180 seconds for network registration to complete...\n");
         //try to re-init modem and perform registration
+        interface->set_credentials(APN, USERNAME, PASSWORD);
         for (x = 0; interface->connect(PIN) != 0; x++) {
             if (x > 0) {
                 bad();
@@ -297,15 +294,12 @@
     }
 #endif
 
-    print_function("\nGetting the IP address of \"" TCP_SERVER "\" and \"2.pool.ntp.org\"...\n");
-    if ((interface->gethostbyname("2.pool.ntp.org", &udpServer) == 0) &&
-        (interface->gethostbyname(TCP_SERVER, &tcpServer) == 0)) {
+    print_function("\nGetting the IP address of \"2.pool.ntp.org\"...\n");
+    if ((interface->gethostbyname("2.pool.ntp.org", &udpServer) == 0)) {
         pulseEvent();
 
         udpServer.set_port(123);
         print_function("\"2.pool.ntp.org\" address: %s on port %d.\n", udpServer.get_ip_address(), udpServer.get_port());
-        print_function("\"" TCP_SERVER "\" address: %s on port %d.\n", tcpServer.get_ip_address(), tcpServer.get_port());
-        tcpServer.set_port(80);
 
         print_function("Performing socket operations in a loop (until the user button is pressed on C030 or forever on C027)...\n");
         while (!buttonPressed) {
@@ -346,39 +340,6 @@
                     pulseEvent();
                     print_function("Socket closed.\n");
                 }
-#ifndef TARGET_UBLOX_C030_N211
-                print_function("Opening a TCP socket...\n");
-                if ((sockTcp.open(interface)) == 0) {
-                    // TCP Sockets
-                    pulseEvent();
-                    print_function("TCP socket open.\n");
-                    sockTcp.set_timeout(10000);
-                    print_function("Connecting socket to %s on port %d...\n", tcpServer.get_ip_address(), tcpServer.get_port());
-                    if (sockTcp.connect(tcpServer) == 0) {
-                        pulseEvent();
-                        print_function("Connected, sending HTTP GET request to \"developer.mbed.org\" over socket...\n");
-                        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()
-                        // in a loop until your entire buffer has been sent.
-                        if (sockTcp.send((void *) buf, strlen(buf)) == (int) strlen(buf)) {
-                            pulseEvent();
-                            print_function("Socket send completed, waiting for response...\n");
-                            x = sockTcp.recv(buf, sizeof (buf));
-                            if (x > 0) {
-                                pulseEvent();
-                                print_function("Received %d byte response from server on TCP socket:\n"
-                                    "----------------------------------------------------\n%.*s"
-                                    "----------------------------------------------------\n",
-                                        x, x, buf);
-                            }
-                        }
-                    }
-                    print_function("Closing socket...\n");
-                    sockTcp.close();
-                    pulseEvent();
-                    print_function("Socket closed.\n");
-                }
 #ifdef TARGET_UBLOX_C030_R412M
                 while(modem_asleep == false) { //modem is awake, let it go to sleep again
                     print_function("Waiting for modem to go to PSM sleep\n");
@@ -386,7 +347,7 @@
                 }
             }
 #endif /* TARGET_UBLOX_C030_R412M */
-#endif /* TARGET_UBLOX_C030_N211 */
+
 
             wait_ms(5000);
 #ifndef TARGET_UBLOX_C027
@@ -401,7 +362,7 @@
         print_function("Stopped.\n");
     } else {
         bad();
-        print_function("Unable to get IP address of \"developer.mbed.org\" or \"2.pool.ntp.org\".\n");
+        print_function("Unable to get IP address of \"2.pool.ntp.org\".\n");
     }
 }