example-ublox-cellular-psm

Dependencies:   ublox-cellular-base-SARA-R5 ublox-at-cellular-interface INA219

Files at this revision

API Documentation at this revision

Comitter:
fahimalavi
Date:
Wed Feb 12 15:13:30 2020 +0500
Parent:
13:eb3632730c09
Child:
15:3bfebe746083
Commit message:
Working version of PSM/LPM with C030

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Feb 10 10:20:26 2020 +0500
+++ b/main.cpp	Wed Feb 12 15:13:30 2020 +0500
@@ -48,7 +48,7 @@
 // username and password NULL), or you may leave all three as NULL and then
 // a lookup will be attempted for a small number of known networks
 // (see APN_db.h in mbed-os/features/netsocket/cellular/utils).
-#define APN         NULL
+#define APN         "default"
 #define USERNAME    NULL
 #define PASSWORD    NULL
 
@@ -172,7 +172,7 @@
 {
     while(1) {
         Thread::signal_wait(0x01);
-        print_function("%f, %d\r\n", ina219.read_current_mA(), ina219.read_current_raw());
+        print_function("Current draw: %f mA\r\n", ina219.read_current_mA());
     }
 }
 
@@ -290,8 +290,8 @@
     pc.attach(&pc_recv, Serial::RxIrq);
     dev.attach(&dev_recv, Serial::RxIrq);
 
-    print_function("sleeping 30 seconds \n");
-    wait_us(30000000);
+    //print_function("sleeping 30 seconds \n");
+    //wait_us(30000000);
 
 
 #ifdef TARGET_UBLOX_C030_R412M
@@ -311,14 +311,14 @@
 //        }
 //    }
 
-    print_function("Enabling PSM...\n");
-    if (interface->set_power_saving_mode(30, 30)) { //enable PSM
+    print_function("Enable PSM in 10...\n");
+    if (1){//interface->set_power_saving_mode(0, 0)) { //enable PSM
         print_function("PSM enabled. Attaching CB function and rebooting the module\n");
         interface->attach_cb_psm_going_in(&psm_going_in_cb, NULL); //register callback
 
         //reset modem so that PSM settings can take effect
-        interface->reboot_modem();
-        wait_us(5000000); //give modem a little time
+        //interface->reboot_modem();
+        //wait_us(5000000); //give modem a little time
 
         print_function("please wait up to 180 seconds for network registration to complete...\n");
         //try to re-init modem and perform registration
@@ -336,6 +336,12 @@
         pulseEvent();
     }
 
+    wait_us(60000000);
+
+    interface->set_idle_mode(true);
+
+    wait_us(90000000); //give modem a little time
+
     //sometimes modem goes in to PSM before we can do any UDP/TCP transfers
     if (modem_asleep == true) {
         print_function("Modem is in PSM, waking up and initializing it\n");