Example program to demonstrate the use of the modem providing CAT-M1, NB1 and 2G support. It may be used on the C030-R412M boards.

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

Files at this revision

API Documentation at this revision

Comitter:
wajahat.abbas@u-blox.com
Date:
Wed Jun 12 15:51:35 2019 +0500
Parent:
0:2a2cf217d00f
Child:
2:9a617f1fedb4
Commit message:
Removed MNO code

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Jun 12 14:15:16 2019 +0500
+++ b/main.cpp	Wed Jun 12 15:51:35 2019 +0500
@@ -137,83 +137,64 @@
     pulseEvent();
 }
 
-/* This changes the modem RAT and MNO profile to default values.
- * MBED_CONF_APP_CHANGE_RAT_MNO_TO_DEFAULT macro is set to 0 in mbed_app.json
- * to avoid accidently changing RAT and MNO. Not all modems support +URAT and +UMNOPROF commands.
- */
-#if (INTERFACE_USED == UBLOX_AT_CELLULAR_INTERFACE) && !defined(TARGET_UBLOX_C027) && !defined(TARGET_UBLOX_C030_N211)
+#if (INTERFACE_USED == UBLOX_AT_CELLULAR_INTERFACE) && defined(TARGET_UBLOX_C030_R412M)
 
-#ifndef MBED_CONF_APP_CHANGE_RAT_MNO_TO_DEFAULT
-#define MBED_CONF_APP_CHANGE_RAT_MNO_TO_DEFAULT 0
-#endif
-bool change_rat_mno_flag = MBED_CONF_APP_CHANGE_RAT_MNO_TO_DEFAULT;
-
-void change_rat_mno(UbloxATCellularInterface* interface)
-{
-#ifdef TARGET_UBLOX_C030_R41XM
-    int current_profile;
+#ifndef MBED_CONF_APP_RAT_TYPE
+#define MBED_CONF_APP_RAT_TYPE "2G"
 #endif
 
-#if defined(TARGET_UBLOX_C030_U201) || defined(TARGET_UBLOX_C030_R412M)
+/* This changes the modem RAT to user specified technology (M1, NB1, 2G).
+ * MBED_CONF_APP_RAT_TYPE macro is by default set to 2G
+ */
+void set_rat(UbloxATCellularInterface* interface)
+{
     int selected, preferred, second_preferred;
-#endif
 
-    if (change_rat_mno_flag == true) {
-        printf("\nSetting URAT and MNO profile to default values...\n");
-        change_rat_mno_flag = false; //do the following just once as to demonstrate the usage
-        //perform deregistration and set URAT and MNO profile to default values
-        if ( (interface->is_registered_csd() || interface->is_registered_psd() || interface->is_registered_eps()) ) {
-            printf("De-registering...\n\n");
-            interface->nwk_deregistration();
-            pulseEvent();
-        }
+    printf("Setting modem RAT to " MBED_CONF_APP_RAT_TYPE "...\n");
+    if ( (interface->is_registered_csd() || interface->is_registered_psd() || interface->is_registered_eps()) ) {
+        printf("De-registering...\n\n");
+        interface->nwk_deregistration();
+        pulseEvent();
+    }
 
-#ifdef TARGET_UBLOX_C030_R41XM
-
-#ifdef TARGET_UBLOX_C030_R412M //+URAT is not supported by R410M
-        printf("Setting modem RAT to CATM1 and NB1...\n");
-        if (interface->set_modem_rat(UbloxATCellularInterface::LTE_CATM1, UbloxATCellularInterface::LTE_CATNB1)) {
+    if (strcmp(MBED_CONF_APP_RAT_TYPE, "2G") == 0) {
+        if (interface->set_modem_rat(UbloxATCellularInterface::GPRS_EGPRS)) {
             printf("RAT configured\n");
             pulseEvent();
         }
-        if (interface->get_modem_rat(&selected, &preferred, &second_preferred)) {
-            printf("selected RAT: %d\npreferred RAT: %d\nsecond_preferred RAT: %d\n", selected, preferred, second_preferred);
-        }
-#endif
-        printf("Setting MNO profile to 0 (default)...\n");
-        if (interface->set_mno_profile()) {
-            printf("MNO profile configured\n");
+    } else if (strcmp(MBED_CONF_APP_RAT_TYPE, "M1") == 0) {
+        if (interface->set_modem_rat(UbloxATCellularInterface::LTE_CATM1)) {
+            printf("RAT configured\n");
             pulseEvent();
         }
-        if (interface->get_mno_profile(&current_profile)) {
-            printf("current_profile is: %d\n", (int)current_profile);
-        }
-
-#elif defined TARGET_UBLOX_C030_U201
-        printf("Setting modem RAT to GSM/UMTS and GSM_GPRS_EGPRS...\n");
-        if (interface->set_modem_rat(UbloxATCellularInterface::GSM_UMTS, UbloxATCellularInterface::GSM_GPRS_EGPRS)) {
+    } else if (strcmp(MBED_CONF_APP_RAT_TYPE, "NB1") == 0) {
+        if (interface->set_modem_rat(UbloxATCellularInterface::LTE_CATNB1)) {
             printf("RAT configured\n");
             pulseEvent();
         }
-        if (interface->get_modem_rat(&selected, &preferred, &second_preferred)) {
-            printf("selected RAT: %d\npreferred RAT: %d\nsecond_preferred RAT: %d\n", selected, preferred, second_preferred);
-        }
-#endif //TARGET_UBLOX_C030_R41XM
-        printf("\nRebooting modem for settings to take effect...\n");
-        if (interface->reboot_modem()) {
-            printf("Reboot successful\n");
-            pulseEvent();
-        }
-
-        printf("Performing registration, please wait...\n");
-        for (int x = 0; interface->connect(PIN) != 0; x++) {
-            if (x > 0) {
-                bad();
-                printf("Retrying (have you checked that an antenna is plugged in and your APN is correct?)...\n");
-            }
-        }
+    } else {
+        printf("Please select correct RAT!\n");
         pulseEvent();
     }
+
+    if (interface->get_modem_rat(&selected, &preferred, &second_preferred)) {
+        printf("selected RAT: %d\npreferred RAT: %d\nsecond_preferred RAT: %d\n", selected, preferred, second_preferred);
+    }
+
+    printf("\nRebooting modem for settings to take effect...\n");
+    if (interface->reboot_modem()) {
+        printf("Reboot successful\n");
+        pulseEvent();
+    }
+
+    printf("Performing registration, please wait...\n");
+    for (int x = 0; interface->connect(PIN) != 0; x++) {
+        if (x > 0) {
+            bad();
+            printf("Retrying (have you checked that an antenna is plugged in and your APN is correct?)...\n");
+        }
+    }
+    pulseEvent();
 }
 #endif
 
@@ -261,12 +242,17 @@
     good();
     printf("Starting up, please wait up to 180 seconds for network registration to complete...\n");
     interface->set_credentials(APN, USERNAME, PASSWORD);
+#if (INTERFACE_USED == UBLOX_AT_CELLULAR_INTERFACE) && defined(TARGET_UBLOX_C030_R412M)
+    interface->init(PIN); //Power up and initialize the modem
+    set_rat(interface); //set RAT to user specified value and perform network registration
+#else
     for (x = 0; interface->connect(PIN) != 0; x++) {
         if (x > 0) {
             bad();
             printf("Retrying (have you checked that an antenna is plugged in and your APN is correct?)...\n");
         }
     }
+#endif
     pulseEvent();
 
     printf("\nGetting the IP address of \"developer.mbed.org\" and \"2.pool.ntp.org\"...\n");
@@ -344,9 +330,6 @@
                 pulseEvent();
                 printf("Socket closed.\n");
             }
-#if (INTERFACE_USED == UBLOX_AT_CELLULAR_INTERFACE) && !defined(TARGET_UBLOX_C027)
-            change_rat_mno(interface);
-#endif //(INTERFACE_USED == UBLOX_AT_CELLULAR_INTERFACE)
 #endif //TARGET_UBLOX_C030_N211
             wait_ms(5000);
 #ifndef TARGET_UBLOX_C027
--- a/mbed_app.json	Wed Jun 12 14:15:16 2019 +0500
+++ b/mbed_app.json	Wed Jun 12 15:51:35 2019 +0500
@@ -1,6 +1,9 @@
 {
     "config": {
-        "change-rat-mno-to-default": 0
+        "rat-type":{
+            "help":"PossibleValuesAre:M1,NB1,2G",
+            "value":"\"2G\""
+        }
     },
     "target_overrides": {
         "*": {