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

[wiring] Network: introduce isOn() and isOff() APIs to enquiry the modem power state #2205

Merged
merged 9 commits into from
Dec 22, 2020

Conversation

XuGuohui
Copy link
Member

@XuGuohui XuGuohui commented Sep 29, 2020

As the title describes.

Example App

#include "Particle.h"

SYSTEM_MODE(MANUAL);
SYSTEM_THREAD(ENABLED);

SerialLogHandler log(115200, LOG_LEVEL_ALL);

void onNetworkStatusUpdated(system_event_t event, int param) {
    if (event == network_status) {
        switch (param) {
            case network_status_on: {
                Log.info("network_status_on");
                break;
            }
            case network_status_off: {
                Log.info("network_status_off");
                break;
            }
            case network_status_connected: {
                Log.info("network_status_connected");
                break;
            }
        }
    }
}

void setup() {
    System.on(network_status, onNetworkStatusUpdated);

    while (!Serial.isConnected());
    delay(1000);

    Log.info("Application started.");

    if (Cellular.isOn()) {
        Log.info("Modem is on.");
    } else if (Cellular.isOff()) {
        Log.info("Modem is off.");
    } else {
        Log.info("Modem is in an unknown state.");
    }

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

    while (Cellular.isOff()) {
        Log.info("modem is off.");
    }
    while (!Cellular.isOn()) {
        Log.info("powering on...");
        delay(500);
    }
    Log.info("Modem is turned on.");

    delay(3s);

    Log.info("Turning off the modem...");
    Cellular.off();

    while (Cellular.isOn()) {
        Log.info("modem is on.");
    }
    while (!Cellular.isOff()) {
        Log.info("powering off...");
        delay(500);
    }
    Log.info("Modem is turned off.");
}

void loop() {
}

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)

@XuGuohui XuGuohui added this to the 2.0.0 milestone Sep 29, 2020
@avtolstoy avtolstoy modified the milestones: 2.0.0, 3.0.0 Oct 2, 2020
@technobly technobly self-requested a review October 15, 2020 03:20
Copy link
Member

@technobly technobly left a comment

Choose a reason for hiding this comment

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

Looking forward to having these essential APIs! Would be nice to see how they can be used with the Future API and waitFor/waitUntil, perhaps in some tests? :D

user/tests/wiring/api/wifi.cpp Show resolved Hide resolved
system/src/system_network_internal.h Outdated Show resolved Hide resolved
system/src/system_network_internal.h Outdated Show resolved Hide resolved
system/src/system_network_manager.cpp Show resolved Hide resolved
system/src/system_network_internal.h Outdated Show resolved Hide resolved
system/src/system_network_internal.h Outdated Show resolved Hide resolved
system/src/system_network_manager.cpp Show resolved Hide resolved
@XuGuohui XuGuohui force-pushed the enhancement/network_modem_power_enquiry/ch42245 branch from 804745f to 94940f5 Compare November 26, 2020 07:57
@XuGuohui
Copy link
Member Author

XuGuohui commented Dec 4, 2020

@technobly @avtolstoy I just revised the PR. Looking forward to your review and any comments.

system/src/system_network_manager.cpp Show resolved Hide resolved
system/src/system_network_internal.h Outdated Show resolved Hide resolved
@avtolstoy avtolstoy mentioned this pull request Dec 9, 2020
6 tasks
hal/network/api/ifapi.h Show resolved Hide resolved
wiring/inc/spark_wiring_cellular.h Outdated Show resolved Hide resolved
system/src/system_network_manager.cpp Show resolved Hide resolved
system/src/system_network_manager.cpp Outdated Show resolved Hide resolved
system/src/system_network_manager_api.cpp Outdated Show resolved Hide resolved
@avtolstoy
Copy link
Member

@XuGuohui We can do this in a separate PR, but let's also make sure that isOff() on Electron will actually report true on boot if the modem is indeed off, as we talked about it. This should be possible by calling into the modem layer, querying the RI pin state and caching the state, so that the future isOff() calls do not have to suffer a 1s delay.

// It's tricky to detect the modem power state.
// We assume that every time the device being powered up, the module is powered on.
// The the power state then be tracked by the on_now() and off_now() APIs.
bool powered = true;
Copy link
Member

Choose a reason for hiding this comment

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

I think we previously figured out that on boot BCM43362 is powered off, so we should be able to safely set this to false by default?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's on by default: #2205 (comment)

@XuGuohui XuGuohui force-pushed the enhancement/network_modem_power_enquiry/ch42245 branch from 850d796 to 07e398a Compare December 22, 2020 07:33
@XuGuohui XuGuohui merged commit 5ad2a80 into develop Dec 22, 2020
@XuGuohui XuGuohui deleted the enhancement/network_modem_power_enquiry/ch42245 branch December 22, 2020 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants