Giter VIP home page Giter VIP logo

Comments (12)

tablatronix avatar tablatronix commented on August 16, 2024 1

Are you confusing mdns hostname and ssid, they are not the same thing.

I suppose there could be a global for setting apname, shrug seems trivial

from wifimanager.

tablatronix avatar tablatronix commented on August 16, 2024 1

The ondemand part is non blocking but not autoconnect is not in that example, // wm.setConfigPortalBlocking(false);

I see the millis rollover issue, thanks

Looks like you figured the rest out. I suggest you read the .h file the super example and the wiki https://github.com/tzapu/WiFiManager/wiki/Methods

The actual readme still needs work as do general docs

from wifimanager.

tablatronix avatar tablatronix commented on August 16, 2024 1

#1669

from wifimanager.

tablatronix avatar tablatronix commented on August 16, 2024

Its the first argument in the function.. what do you mean?

startConfigPortal(ssid,..

from wifimanager.

rtek1000 avatar rtek1000 commented on August 16, 2024

The initial post about the 686 line was with ESP32.

It also occurs with the ESP8266, in the line 388

  // not connected start configportal
  bool res = startConfigPortal(apName, apPassword);

At the beginning of Main there is wm.setHostname("MDNSEXAMPLE"), line 37, onDemandNonBlocking.ino.

Shouldn't the library have used this same "MDNSEXAMPLE" as the SSID?

from wifimanager.

rtek1000 avatar rtek1000 commented on August 16, 2024

It appears there is a way to read the SSID, but there is no way to Set it

/**
 * get config portal AP SSID
 * @since 0.0.1
 * @access public
 * @return String the configportal ap name
 */
String WiFiManager::getConfigPortalSSID() {
  return _apName;
}

from wifimanager.

rtek1000 avatar rtek1000 commented on August 16, 2024

I managed to solve it, I was missing using:

autoConnect(apName, apPassword)

startConfigPortal(apName, apPassword)

char const * portal_SSID = {"DEVICE1"};
char const * portal_PASSWORD = {"12345678"}; // Need >= 8 chars

wm.autoConnect(portal_SSID, portal_PASSWORD);
wm.startConfigPortal(portal_SSID, portal_PASSWORD);

wm.autoConnect(portal_SSID, portal_PASSWORD);

wm.startConfigPortal(portal_SSID, portal_PASSWORD);

Maybe it would be easier if there was a function to set this, instead of the user declaring the SSID and password on each line they use when the portal starts.

Thank you.

from wifimanager.

rtek1000 avatar rtek1000 commented on August 16, 2024

Should the onDemandNonBlocking.ino example always be non-blocking?

If the ESP is not connected, how long will the portal wait to go to the loop() routine?

When I comment out the wm.autoConnect() line, then the led blinks, but if I leave the line, the portal is activated and remains active indefinitely.

I used wm.setConfigPortalTimeout(timeout), but it still takes the timeout time to go to loop().

from wifimanager.

rtek1000 avatar rtek1000 commented on August 16, 2024

Should the onDemandNonBlocking.ino example always be non-blocking?

If the ESP is not connected, how long will the portal wait to go to the loop() routine?

When I comment out the wm.autoConnect() line, then the led blinks, but if I leave the line, the portal is activated and remains active indefinitely.

I used wm.setConfigPortalTimeout(timeout), but it still takes the timeout time to go to loop().

The line needed to be uncommented:

// wm.setConfigPortalBlocking(false);

from wifimanager.

rtek1000 avatar rtek1000 commented on August 16, 2024

Should the onDemandNonBlocking.ino example always be non-blocking?
If the ESP is not connected, how long will the portal wait to go to the loop() routine?
When I comment out the wm.autoConnect() line, then the led blinks, but if I leave the line, the portal is activated and remains active indefinitely.
I used wm.setConfigPortalTimeout(timeout), but it still takes the timeout time to go to loop().

The line needed to be uncommented:

// wm.setConfigPortalBlocking(false);

If I use the portal Timeout, how can I know if the portal has already been stopped?

Note: On line 599, a form of time control that is not recommended appears to be being implemented, in the case of recycling the variable returned to millis().

    // handle timed out
    if(millis() > _configPortalStart + _configPortalTimeout){
      #ifdef WM_DEBUG_LEVEL
      DEBUG_WM(F("config portal has timed out"));
      #endif
      return true; // timeout bail, else do debug logging
    } 

But on line 607, A recommended form of time control is being implemented

      // log timeout time remaining every 30s
      if((millis() - timer) > logintvl){
        timer = millis();
        #ifdef WM_DEBUG_LEVEL
        DEBUG_WM(WM_DEBUG_VERBOSE,F("Portal Timeout In"),(String)((_configPortalStart + _configPortalTimeout-millis())/1000) + (String)F(" seconds"));
        #endif
      }

from wifimanager.

rtek1000 avatar rtek1000 commented on August 16, 2024

If I use the portal Timeout, how can I know if the portal has already been stopped?

I found this: getConfigPortalActive()

My sketch now (ESP8266):

  • It works like a WiFi router, the user have to press the button for 15 seconds
    • The settings are reset.
    • Wait for user to release button.
    • LED goes out (on NodeMCU off: HIGH)
  • The portal is only active for the timeout period, to avoid unnecessary exposure of the portal.
  • The LED flashes differently when the portal is active

Sketch:

#include <Arduino.h>

/**
 * OnDemandNonBlocking.ino
 * example of running the webportal or configportal manually and non blocking
 * trigger pin will start a webportal for 120 seconds then turn it off.
 * startAP = true will start both the configportal AP and webportal
 */
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager

// include MDNS
#ifdef ESP8266
#include <ESP8266mDNS.h>
#elif defined(ESP32)
#include <ESPmDNS.h>
#endif

// select which pin will trigger the configuration portal when set to LOW
#define TRIGGER_PIN 0 // ESP8266 GPIO0 (NodeMCU D3)

#define LED_BUILTIN_D4 2 // ESP8266 GPIO2 (NodeMCU D4)

char const *portal_SSID = {"DEVICE1"};
char const *portal_PASSWORD = {"12345678"}; // Need >= 8 chars

WiFiManager wm;

unsigned int timeout = 120; // seconds to run for
unsigned int startTime = millis();
//bool portalRunning = false;
bool startAP = true; // start AP and webserver if true, else start only webserver

uint32_t millis1 = 0;
uint32_t millis2 = 0;

void doWiFiManager();

void setup()
{
  WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
  // put your setup code here, to run once
  Serial.begin(115200);
  Serial.setDebugOutput(true);
  delay(1000);
  Serial.println("\n Starting");

  pinMode(TRIGGER_PIN, INPUT_PULLUP);
  pinMode(LED_BUILTIN_D4, OUTPUT);
  digitalWrite(LED_BUILTIN_D4, HIGH);

  wm.setConfigPortalTimeout(timeout);

  // wm.resetSettings();
  wm.setHostname("MDNSEXAMPLE");
  // wm.setEnableConfigPortal(false);
  wm.setConfigPortalBlocking(false);
  // wm.autoConnect();

  wm.autoConnect(portal_SSID, portal_PASSWORD);
}

void loop()
{
#ifdef ESP8266
  MDNS.update();
#endif
  doWiFiManager();
  // put your main code here, to run repeatedly:

  if (wm.getConfigPortalActive() == true)
  {
    if ((millis() - millis2) > 500)
    {
      millis2 = millis();

      digitalWrite(LED_BUILTIN_D4, !digitalRead(LED_BUILTIN_D4));
    }
  } else {
    if ((millis() - millis2) > 5000)
    {
      millis2 = millis();
    }

    if (((millis() - millis2) < 500))
    {
      digitalWrite(LED_BUILTIN_D4, LOW);
    } else if (((millis() - millis2) > 500) && ((millis() - millis2) < 1000))
    {
      digitalWrite(LED_BUILTIN_D4, HIGH);
    }
  }
}

void doWiFiManager()
{
  // is auto timeout portal running
  if (wm.getConfigPortalActive()) //portalRunning
  {
    wm.process(); // do processing

    // check for timeout
    if ((millis() - startTime) > (timeout * 1000))
    {
      Serial.println("portaltimeout");
      //portalRunning = false;
      if (startAP)
      {
        wm.stopConfigPortal();
      }
      else
      {
        wm.stopWebPortal();
      }
    }
  }

  // is configuration portal requested?
  if (digitalRead(TRIGGER_PIN) == LOW && (!wm.getConfigPortalActive())) // !portalRunning
  {
    // Minimum button press time to activate the portal
    if ((millis() - millis1) > 15000)
    {
      digitalWrite(LED_BUILTIN_D4, HIGH);

      // Wait for user to release button
      while(digitalRead(TRIGGER_PIN) == LOW) {
        yield();
      }

      if (startAP)
      {
        Serial.println("Button Pressed, Starting Config Portal");
        wm.resetSettings();
        wm.setConfigPortalBlocking(false);
        wm.startConfigPortal(portal_SSID, portal_PASSWORD);
      }
      else
      {
        Serial.println("Button Pressed, Starting Web Portal");
        wm.startWebPortal();
      }
      //portalRunning = true;
      startTime = millis();
    }
    else
    {
      digitalWrite(LED_BUILTIN_D4, LOW);
    }
  }
  else
  {
    millis1 = millis();
  }
}

(Now I think I can go to the part "auto update via email")

Thank you.

from wifimanager.

rtek1000 avatar rtek1000 commented on August 16, 2024

Hello, I would like to suggest that an example be made available (if possible) with a login to access the portal, it is the standard for almost all routers I have seen, I found a project that has this, perhaps it could serve as an example of how to implement it :

https://github.com/rtek1000/esp32-asyncwebserver-fileupload-example/tree/master/example-02

Login to access the portal:
page_login

Additional page that a commercial router shows if the user is unable to log in:
page_login2

info.zip

from wifimanager.

Related Issues (20)

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.