Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restores the modem state after device is woken up. #2308

Merged
merged 3 commits into from
Apr 28, 2021

Conversation

XuGuohui
Copy link
Member

Problem

For sleep 2.0 API, if the modem is powered on, but not establishing connection, it won't restore the modem power state after device is woken up.

Solution

Tracks the modem power state and connection state respectively in system sleep.

Steps to Test

Running the example below building against develop branch you won't see the modem is on after device is woken up, but you will if you build it against the current branch.

Example App

#include "Particle.h"

SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);

Serial1LogHandler l(115200, LOG_LEVEL_INFO);

void setup() {
    Log.info("Turning on the modem...");
    Cellular.on();

    waitUntil(Cellular.isOn);
    Log.info("Done");
    delay(2s);

    Log.info("Entering sleep...");
    SystemSleepResult r = System.sleep(SystemSleepConfiguration().mode(SystemSleepMode::STOP).duration(5s));

    if (r.error() == SYSTEM_ERROR_NONE) {
        Log.info("Exited sleep.");
    } else {
        Log.error("Failed to enter sleep.");
    }

    Log.info("Waiting for the modem to be turned on...");
    waitFor(Cellular.isOn, 60000);
    Log.info("Modem is %s", Cellular.isOn() ? "on" : "off");
}

void loop() {
}

References

N/A


Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • Added documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)

Copy link
Member

@avtolstoy avtolstoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rejecting because of status.on logic.

wiring/sleep20 also needs to be updated to have a set of tests to validate this behavior.

network_wait_off(index, 120000/*ms*/, nullptr);
return resume;
if (!network_is_off(index, nullptr)) {
status.on = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if it's being powered off right now (IF_POWER_STATE_POWERING_DOWN on Gen 3)? This might need to have separate implementation for Gen 2 and Gen 3: SPARK_WLAN_XXX for Gen 2 and going into network manager on Gen 3 for pwrState value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Will work around it.

}

static int system_sleep_network_resume(network_interface_index index) {
int system_sleep_network_resume(network_interface_index index, network_status_t& status) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to pass network_status_t by reference here, which semantically means that it may be modified. Either by value (preferred) or at least const reference.

@XuGuohui XuGuohui merged commit 7a319ac into develop Apr 28, 2021
@XuGuohui XuGuohui deleted the fix/sleep_consistency branch April 28, 2021 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants