@@ -39,14 +39,42 @@ void setup() {
39
39
// pressing the button
40
40
pinConfigure (SW0, PIN_DIR_INPUT | PIN_INT_FALL);
41
41
42
- // Configure the power save configuration, start the LTE modem and wait
43
- // until we are connected to the operator
42
+ // Now we configure the power save configuration. Note that this has to be
43
+ // done before calling Lte.begin().
44
44
//
45
- // Here we say that we want to sleep for 30 seconds * 2 = 60 seconds each
46
- // time we invoke sleep
47
- LowPower.begin (SleepMultiplier::THIRTY_SECONDS, 2 , SleepMode::REGULAR);
45
+ // This mode for LowPower is somewhat more complex than a plain power down,
46
+ // which cuts the power to the LTE modem and puts the AVR CPU in sleep for
47
+ // as long as we want.
48
+ //
49
+ // Let's break this mode down:
50
+ //
51
+ // 1. We first configure the LTE modem with this power save configuration.
52
+ // That tells the LTE modem that it will be active for some time period
53
+ // sending data and syncing up with the operator, then it can go to sleep
54
+ // for the remaining time of this time period. That means that the LTE modem
55
+ // will not be sleeping for the whole time period, but most of it. This
56
+ // repeats as long as we want.
57
+ //
58
+ // Here we say that we want to have a power save period of 30 seconds * 2 =
59
+ // 60 seconds.
60
+ //
61
+ // 2. This happens periodically as long as we tell it that it's okay for it
62
+ // to go into power save, which we do with LowPower.powerSave(). Note that
63
+ // the LTE modem is the one responsible for knowing where we are in this
64
+ // time period, thus, if we call LowPower.powerSave() in the middle of the
65
+ // time period, it will only sleep for half the time before being woken up
66
+ // again. This is totally fine, and can for example happen if we do some
67
+ // operations on the CPU which takes a lot of time.
68
+ //
69
+ // In powerSave(), after the LTE modem is sleeping, we also put the
70
+ // CPU to sleep. When the time period is over, the CPU is woken at the same
71
+ // time as the LTE modem is woken up.
72
+ LowPower.configurePeriodicPowerSave (
73
+ PowerSaveModePeriodMultiplier::THIRTY_SECONDS, 2 );
74
+
48
75
Lte.begin ();
49
76
Log.infof (" Connecting to operator" );
77
+
50
78
while (!Lte.isConnected ()) {
51
79
Log.raw (" ." );
52
80
delay (1000 );
@@ -60,28 +88,10 @@ void loop() {
60
88
Log.raw (" \r\n " );
61
89
Log.info (" Going to sleep..." );
62
90
delay (100 );
63
- WakeUpReason wakeup_reason = LowPower.sleep ();
64
-
65
- switch (wakeup_reason) {
66
- case WakeUpReason::OK:
67
- Log.info (" Finished sleep" );
68
- break ;
69
- case WakeUpReason::EXTERNAL_INTERRUPT:
70
- Log.info (" Got woken up by external interrupt" );
71
- break ;
72
- case WakeUpReason::AWOKEN_BY_MODEM_PREMATURELY:
73
- Log.info (" Got woken up by modem prematurely" );
74
- break ;
75
- case WakeUpReason::MODEM_TIMEOUT:
76
- Log.info (" Took too long to put modem in sleep, no time left for "
77
- " sleeping. You might have to increase the sleep time." );
78
- break ;
79
- case WakeUpReason::INVALID_SLEEP_TIME:
80
- Log.info (" Got invalid sleep time from operator" );
81
- break ;
82
- }
91
+
92
+ LowPower.powerSave ();
83
93
84
94
// Do work ...
85
95
Log.info (" Doing work..." );
86
- delay (10000 );
96
+ delay (5000 );
87
97
}
0 commit comments