khoih-prog / WiFiManager_NINA_Lite

Light-Weight WiFi/Credentials Manager for AVR Mega, Teensy, SAM DUE, SAMD, STM32, etc. boards running U-Blox WiFiNINA modules/shields. Powerful-yet-simple-to-use feature to enable adding dynamic custom parameters. Now using WiFiMulti_Generic library
MIT License
35 stars 10 forks source link

Sleep mode works but WiFi-module cannot be restarted using WiFiManager_Generic->begin() method #12

Closed iKK001 closed 3 years ago

iKK001 commented 3 years ago

I am using the Arduino Nano RP2040 Connect board and I succesfully have it running with your example code (i.e. Examples-->WiFiManager_NINA_Lite-->RP2040_WiFiNINA)

In order to save battery, I changed the example code so that the RP2040 goes into some sort of sleep mode:

The sleep-mode consists of a) turning OFF all LED's b) turning OFF the WiFi-module c) turning OFF the RP2040 itself (not sure how to actually achieve this - any library-hint highly appreciated)

As for b) turning OFF the WiFi-module, I get a crash and need some help on this. I have the following sw-setup, observation and question:

SW-Setup:

Inside my go_to_sleep()-method I use the following cmds to make the WiFi module go to sleep:

WiFi.disconnect();
WiFi.end();     

Inside my wakeup()-method I use the same WiFi-startup routines as your example shows. The wakeup()-method works nicely at startup. But it crashes unfortunately wafter the go_to_sleep()-method.

void wakeup() {    

    Serial.print(F("\nStart RP2040_WiFi on ")); Serial.print(BOARD_NAME);
    Serial.print(F(" with ")); Serial.println(SHIELD_TYPE);
    Serial.println(WIFI_MANAGER_GENERIC_LITE_VERSION); 

    WiFiManager_Generic = new WiFiManager_Generic_Lite();

    WiFiManager_Generic->setConfigPortal(secret_AP_SSID, secret_AP_PW);
    WiFiManager_Generic->setConfigPortalIP(IPAddress(192, 168, 63, 43));
    WiFiManager_Generic->setConfigPortalChannel(0);

#if USING_CUSTOMS_STYLE
    WiFiManager_Generic->setCustomsStyle(NewCustomsStyle);
#endif

#if USING_CUSTOMS_HEAD_ELEMENT
    WiFiManager_Generic->setCustomsHeadElement("<style>html{filter: invert(10%);}</style>");
#endif

#if USING_CORS_FEATURE  
    WiFiManager_Generic->setCORSHeader("Your Access-Control-Allow-Origin");
#endif

    // Set customized DHCP HostName
    WiFiManager_Generic->begin(HOST_NAME);
}

Observation:

At the moment of wakeup, the WiFiManager does not startup. It stalls at the WiFiManager_Generic->begin(HOST_NAME); line. The WiFi cannot be restarted once WiFi.disconnect() and WiFi.end() cmds.

Questions:

  1. What can I do to make WiFiManager_Generic->begin(HOST_NAME); work after my go_to_sleep()-method ?
  2. Is there another way to place the WiFi-Module in sleep mode using your library (other than WiFi.disconnect() and WiFi.end()) ?
  3. What cmd could I place in front of WiFiManager_Generic->begin(HOST_NAME); cmd in order to make the WiFi-Module re-initialize after a sleep period ?

Thank you for any help on this.

khoih-prog commented 3 years ago

As RP2040 is a very new board with very new core, DeepSleep Mode is not well-tested as in many other boards (ESP32, ESP8266).

It's not as simple as what you're doing using WiFi.end(), etc. then expect everything simply will return to normal.

I suggest you have a look at these, and use one of those methods correctly, and try with the simplest WiFi Client code to see if it's working or not..

  1. SleepyPico library
  2. hello_sleep.c
  3. hello_dormant.c
  4. sleep.c#L134-L155
void sleep_goto_dormant_until_pin(uint gpio_pin, bool edge, bool high) {
    bool low = !high;
    bool level = !edge;

    // Configure the appropriate IRQ at IO bank 0
    assert(gpio_pin < NUM_BANK0_GPIOS);

    uint32_t event = 0;

    if (level && low) event = IO_BANK0_DORMANT_WAKE_INTE0_GPIO0_LEVEL_LOW_BITS;
    if (level && high) event = IO_BANK0_DORMANT_WAKE_INTE0_GPIO0_LEVEL_HIGH_BITS;
    if (edge && high) event = IO_BANK0_DORMANT_WAKE_INTE0_GPIO0_EDGE_HIGH_BITS;
    if (edge && low) event = IO_BANK0_DORMANT_WAKE_INTE0_GPIO0_EDGE_LOW_BITS;

    gpio_set_dormant_irq_enabled(gpio_pin, event, true);

    _go_dormant();
    // Execution stops here until woken up

    // Clear the irq so we can go back to dormant mode again if we want
    gpio_acknowledge_irq(gpio_pin, event);
}

You can also post question on Arduino or Raspberry Forum to ask for help.

I'd appreciate it if you can share your success here to benefit other users.

As this issue has nothing to do with the library, I'm closing it now.

Good Luck,

khoih-prog commented 3 years ago

For ESP32 and ESP8266 DeepSleep, you can have a look at my outdated SmallProjects library and this sample project code : SmartFarm_DeepSleep

khoih-prog commented 3 years ago

Another library to look and try

PicoSleepDemo