example-ublox-cellular-interface_rat_mno
Dependencies: ublox-at-cellular-interface ublox-cellular-base ublox-cellular-base-n2xx ublox-at-cellular-interface-n2xx
Revision 37:e384b01c738a, committed 2019-04-17
- Comitter:
- wajahat.abbas@u-blox.com
- Date:
- Wed Apr 17 15:31:36 2019 +0500
- Parent:
- 36:f24c264ad2cd
- Commit message:
- Updated example to show usage of set/get RAT and MNO profile
Changed in this revision
--- a/main.cpp Wed Feb 13 10:55:51 2019 +0500
+++ b/main.cpp Wed Apr 17 15:31:36 2019 +0500
@@ -18,28 +18,42 @@
#include "OnboardCellularInterface.h"
#include "UbloxATCellularInterfaceN2xx.h"
+#define UBLOX_AT_CELLULAR_INTERFACE 1
+#define ONBOARD_CELLULAR_INTERFACE 2
+#define UBLOX_AT_CELLULAR_INTERFACE_N2XX 3
+
// You must select the correct interface library for your board, by
// uncommenting the correct line below. Supported combinations are
// indicated with a "Y" in the table below.
//
-// C030_U201 C030_N211 C027
-// UbloxATCellularInterface Y - Y
-// OnboardCellularInterface Y - Y
-// UbloxATCellularInterfaceN2xx - Y -
+// C030_U201 C030_N211 C027
+// UBLOX_AT_CELLULAR_INTERFACE Y - Y
+// ONBOARD_CELLULAR_INTERFACE Y - Y
+// UBLOX_AT_CELLULAR_INTERFACE_N2XX - Y -
// Note: the N211 module supports only UDP, not TCP
-// OnboardCellularInterface uses LWIP and the PPP cellular interface
-// on the mbed MCU, while using UbloxATCellularInterface and
-// UbloxATCellularInterfaceN2xx uses an IP stack on the cellular
+// ONBOARD_CELLULAR_INTERFACE uses LWIP and the PPP cellular interface
+// on the mbed MCU, while using UBLOX_AT_CELLULAR_INTERFACE and
+// UBLOX_AT_CELLULAR_INTERFACE_N2XX uses an IP stack on the cellular
// module and hence uses less RAM (significant on C027). This also
// allows other AT command operations (e.g. sending an SMS) to happen
// during a data transfer (for which you should replace the
-// UbloxATCellularInterface library with the UbloxATCellularInterfaceExt
+// UBLOX_AT_CELLULAR_INTERFACE library with the UbloxATCellularInterfaceExt
// library). However, it is slower than using the LWIP/PPP on the mbed
// MCU interface since more string parsing is required.
+#define INTERFACE_USED UBLOX_AT_CELLULAR_INTERFACE
+//#define INTERFACE_USED ONBOARD_CELLULAR_INTERFACE
+//#define INTERFACE_USED UBLOX_AT_CELLULAR_INTERFACE_N2XX
+
+#if (INTERFACE_USED == UBLOX_AT_CELLULAR_INTERFACE)
#define INTERFACE_CLASS UbloxATCellularInterface
-//#define INTERFACE_CLASS OnboardCellularInterface
-//#define INTERFACE_CLASS UbloxATCellularInterfaceN2xx
+#elif (INTERFACE_USED == ONBOARD_CELLULAR_INTERFACE)
+#define INTERFACE_CLASS OnboardCellularInterface
+#elif (INTERFACE_USED == UBLOX_AT_CELLULAR_INTERFACE_N2XX)
+#define INTERFACE_CLASS UbloxATCellularInterfaceN2xx
+#else
+#error please define an interface class to use
+#endif
// The credentials of the SIM in the board. If PIN checking is enabled
// for your SIM card you must set this to the required PIN.
@@ -123,6 +137,86 @@
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)
+
+#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;
+#endif
+
+#if defined(TARGET_UBLOX_C030_U201) || defined(TARGET_UBLOX_C030_R412M)
+ 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();
+ }
+
+#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)) {
+ 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");
+ pulseEvent();
+ }
+ if (interface->get_mno_profile(¤t_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)) {
+ 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");
+ }
+ }
+ pulseEvent();
+ }
+}
+#endif
+
/* This example program for the u-blox C030 and C027 boards instantiates
* the UbloxATCellularInterface or OnboardCellularInterface and uses it
* to make a simple sockets connection to a server, using 2.pool.ntp.org
@@ -160,13 +254,14 @@
#else
InterruptIn userButton(SW0);
#endif
-
+
// Attach a function to the user button
userButton.rise(&cbButton);
-
+
good();
printf("Starting up, please wait up to 180 seconds for network registration to complete...\n");
interface->set_credentials(APN, USERNAME, PASSWORD);
+
for (x = 0; interface->connect(PIN) != 0; x++) {
if (x > 0) {
bad();
@@ -175,7 +270,7 @@
}
pulseEvent();
- printf("Getting the IP address of \"developer.mbed.org\" and \"2.pool.ntp.org\"...\n");
+ printf("\nGetting the IP address of \"developer.mbed.org\" and \"2.pool.ntp.org\"...\n");
if ((interface->gethostbyname("2.pool.ntp.org", &udpServer) == 0) &&
(interface->gethostbyname(TCP_SERVER, &tcpServer) == 0)) {
pulseEvent();
@@ -185,7 +280,7 @@
printf("\"2.pool.ntp.org\" address: %s on port %d.\n", udpServer.get_ip_address(), udpServer.get_port());
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");
+ printf("\nPerforming socket operations in a loop (until the user button is pressed on C030 or forever on C027)...\n");
while (!buttonPressed) {
// UDP Sockets
printf("=== UDP ===\n");
@@ -250,7 +345,10 @@
pulseEvent();
printf("Socket closed.\n");
}
-#endif
+#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
printf("[Checking if user button has been pressed]\n");
--- a/mbed_app.json Wed Feb 13 10:55:51 2019 +0500
+++ b/mbed_app.json Wed Apr 17 15:31:36 2019 +0500
@@ -1,4 +1,7 @@
{
+ "config": {
+ "change-rat-mno-to-default": 0
+ },
"target_overrides": {
"*": {
"lwip.ppp-enabled": true,
--- a/ublox-cellular-base.lib Wed Feb 13 10:55:51 2019 +0500 +++ b/ublox-cellular-base.lib Wed Apr 17 15:31:36 2019 +0500 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ublox/code/ublox-cellular-base/#15f31e074d67 +https://developer.mbed.org/teams/ublox/code/ublox-cellular-base/#779971811c46