Giter Club home page Giter Club logo

Comments (3)

Llaves avatar Llaves commented on August 16, 2024

The reason your code requires explicit SSID and password parms to the begin() call is that the disconnect() call erases the ssid and password values from flash (if WiFi.persistent() is set to true, which it is by default in most WiFi libraries). You can overcome this:

bool WiFiOff() {
  conn_tries = 0;
  // disconnect will rewrite the configuration to show no SSID or password. If persistent is
  // set to true, this will null the values in flash, so don't do that.
  // However, if set to false, the current values are set to null, so this will
  // have to be accounted for in the WiFiOn function
  WiFi.persistent(false);
  WiFi.disconnect();
  WiFi.persistent(true);
  WiFi.mode(WIFI_OFF);
  WiFi.forceSleepBegin();
  yield();

  // It can take a while for the ESP to disconnect, so we need
  // to give it a couple of seconds before returning a fail.

  while ((WiFi.status() == WL_CONNECTED)
         && (conn_tries++ < WIFI_RETRIES))
  {
    delay(100);
#ifdef DEBUG
    Serial.print(".");
#endif
  }
#ifdef DEBUG
  if (WiFi.status() != WL_CONNECTED)
    return (true);
  else
    return (false);
#endif
}

This doesn't solve the problem completely, however, because begin() uses the current configuration parameters, which were nulled out by the disconnect() call. Here's a WiFiOn() function that takes no parameters and instead uses the ones cached in flash.

struct station_config config;
bool WiFiOn()
{
  // the current config has no SSID or password - these were blown away by the disconnect with
  // persistent = false;
  // We can fetch from EEPROM the parameters that existed before disconnect.

  bool status = wifi_station_get_config_default(&config);
#ifdef DEBUG
  if (!status)
    Serial.println("Failed to fetch config");
  else
    Serial.println("Config fetched");
  Serial.print("Parameters fetched from EEPROM. SSID = ");
  Serial.println((const char *) config.ssid);
#endif

  return WiFiOn((const char *) config.ssid, (const char *) config.password);
}

from esp_power_save.

billbee avatar billbee commented on August 16, 2024

I was using this to help maybe get ESPNOW to work, somewhere I read it works better with wifi off, but alas in my case did not. I guess the ESPNOW uses even less power than WiFi and while that does work, the signal is also very weak in the garage. Darn! But I liked learning what you had, so that was good.

Cheers.

from esp_power_save.

PuceBaboon avatar PuceBaboon commented on August 16, 2024

...maybe get ESPNOW to work, somewhere I read it works better with wifi off, but alas in my case did not.
...and while that does work, the signal is also very weak in the garage.

Hi Billbee,

I'm using ESPNOW in an outdoor project at the moment (as a poor-man's remote control) and, line of sight, it works reasonably well (for the record, initializing WiFi in STA mode and then calling set channel, followed by the esp_now_init). I guess the problem for both of us is that the ESP isn't blasting out power at the same level as an access point with multiple antennas. You might want to try one of the TTGO boards with an external antenna for the module inside the garage (you could even replace the "rubber ducky" with a cantenna if your point-to-point connection is fairly static ...even a kitchen strainer works quite well if you're only trying to localize the signal in one general direction).

Good luck!

          -John-

from esp_power_save.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.