prampec / IotWebConf

ESP8266/ESP32 non-blocking WiFi/AP web configuration Arduino library
MIT License
534 stars 140 forks source link

IotWebConf on demand as configuration tool #223

Open ClemensGruber opened 3 years ago

ClemensGruber commented 3 years ago

My use case is a bit different than the scenarios descibed at https://github.com/prampec/IotWebConf#use-cases so perhaps someone can say if it is possible with IotWebConf or give some hints how to reach it. I had a look at different examples and the documentation but I have not a deep understanding till now.

We have an open souce bee hive project with different hard- and software setups at hiveeyes . For an implementaton with TTGO's T-Call I'd like to use IotWebConf for configuration. Till now it is done in the Arduino sketch but this is not so usable, especally for people / in this case non-technical beekeeper. :-)

So the story is:

For configuration -- and only for this task -- we need the IotWebConf mechanism with active Wifi and UI.

This should be on demand. That means

At the moment I have planed to call IotWebConf UI triggered by reset causes, so in case someone pressed reset the webconfig sould be called.

My idea right now is to move iotWebConf.doLoop(); out of loop() to a function that is only called after the reset cause "poweron reset" / or a button press or an other trigger for the web UI.

In this function configuration is done and after submitting the config parameter it returns from this function to loop with the other staff above and Wifi should be deactivated to save power.

Is this doable with iotWebConf or should I spent time for other things? ;-)

ClemensGruber commented 3 years ago

In the GitHub issues and library examples I found forceApMode(), that will be helpful for the described scenaro. So I can omit joinig a Wifi network that's not there because we are using GSM/GPRS/LTE for the internet connection.

Switching off Wifi can be done with iotWebConf.goOffLine(); after configuration, see IotWebConf16OffLineMode.ino.

So remainig is the on demand quesiton. Is there a command to say with this condition only activate Wifi and run the AP? Or do I have ever to activate the AP mode and go immediately in offline mode? This would not be a good solution for battery powered devices.

amotl commented 3 years ago

Dear Clemens,

it looks like @kugelkopf123 has a similar use case, see also #112:

  • To be able to completely do without the AP / STA Autoconnect thing in order to be able to use only the Configportal (not captive portal).
  • The possibility to prevent the automatic connection to the entered access point (STA).
  • Background: In order to save as much energy as possible.

See also #5, #63 and #149. On the latter, @prampec mentioned at https://github.com/prampec/IotWebConf/issues/149#issuecomment-860106838:

I have provided to you an OffLine mode. Please check example IotWebConf16OffLineMode. Solution will be available from v3.1.0.

So, I believe you are on the right path, Clemens.

With kind regards, Andreas.

amotl commented 3 years ago

Or do I have ever to activate the AP mode and go immediately in offline mode?

Maybe the right method to invoke is startupOffLine() directly within setup() instead?

csiki2 commented 3 years ago

Hi,

I do something similar, my solution is in short:

  _webConf.skipApStartup();
  addParameters();

  const char* mode;
  if (tryLoadConfig) {
    if (!_webConf.loadConfig() && ...) return false;
...
    mode = "load config";
  } else {
...
    _webConf.init();
    _webConf.forceApMode(true);
    mode = "access point";
  }

If the load config fails, you can retry instantly without load config (in my code an extra object needs to be created, but that's not improtant here).