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

Only connect to Wifi if there is NO connection #169

Merged
merged 1 commit into from
Dec 14, 2020

Conversation

espwx
Copy link
Contributor

@espwx espwx commented Nov 22, 2020

I have notice an issue when calling IOTAppStory::begin() when wifi is already configured on an ESP32. The connection is disconnected and IAS attempts to connect using its own internal routines. This can be annoying and interfere with the authors intent, By only calling when there is no connection, this can be avoided, without and greater impact to the library functionality.

##TLDR
Only connect if not already connected from some action before the IOTAppStory::begin() call. This helps avoids wifi managers interfering with each other - it's a quick hack but seems to work just fine.

I have notice an issue when calling IOTAppStory::begin() when wifi is already configured on an ESP32. The connection is disconnected and IAS attempts to connect using its own internal routines. This can be annoying and interfere with the authors intent, By only calling when there is no connection, this can be avoided, without and greater impact to the library functionality.

##TLDR
Only connect if not *already* connected from some action before the IOTAppStory::begin() call. This helps avoids wifi managers interfering with each other - it's a quick hack but *seems* to work just fine.
@Onno-Dirkzwager
Copy link
Collaborator

Onno-Dirkzwager commented Dec 14, 2020

Hi @espwx,

Thankyou for your pullrequest. I was already working on something very similar for different reasons:

Added a preset so you can decide to setup wifi on boot or not
IAS.preSetConnWifiOnBoot(false or true);
This sets our private bool _automaticWifiConnectOnBoot

Changed var from private to public
this->connected instead of this->_connected
So now you can do if(IAS.connected).....etc in your sketch

Added / made public our connect and disconnect functions
So now you can do IAS.WiFiDisconnect(); & IAS.WiFiConnect(); in your sketch.

And then in the same line as you suggested to change
if((_automaticWifiConnectOnBoot || this->boardMode == 'C') && !this->connected){

So this would let you do the same as you intended with your changes and lets others use our connect and disconnect functions when and if they want to.

You would do:
IAS.preSetConnWifiOnBoot(false);
and set
IAS.connected = true; in your code when connected
To let the library know you are connected and can callhome for updates.

Questions

  • I am curious how you would have updated the this->_connected used in your if statement using your own wifi solutions before the IAS.begin()?
  • are you using the configmode at all? If not how do you update certificates?
  • Second do you agree that my code shown above would give you the "powers" you are looking for? Because after merging your pullrequest if will be overritten with my changes.

@Onno-Dirkzwager
Copy link
Collaborator

@espwx some extra info for the future:
After 2.1.0 and some minor following updates the library will splitt into multiple libraries used in the IAS wrapper.

This lets basic users use the library as it is right now. And let the more advanced users decide which parts / libraries they want to use. So in your case you could choose to use other wifi managers or only use the OTA update stuff.

@espwx
Copy link
Contributor Author

espwx commented Dec 14, 2020

Hi @Onno-Dirkzwager

Thanks for looking into this!

You would do:
IAS.preSetConnWifiOnBoot(false);
and set
IAS.connected = true; in your code when connected
To let the library know you are connected and can callhome for updates.

Yes, this should work.

* I am curious how you would have updated the this->_connected used in your if statement using your own wifi solutions before the IAS.begin()?

A very good question. The WifiMulti library seems to have done that. I did not specifically update that variable, but it did work and skip the this->WiFiSetupAndConnect(); statement, so it can only be the Wifi library?

* are you using the configmode at all? If not how do you update certificates?

I don't use the config mode (yet). I update the certificate by replacing the certificate file directly on the spiffs file system - this is quicker and less interactive.

* Second do you agree that my code shown above would give you the "powers" you are looking for? Because after merging your pullrequest if will be overritten with my changes.

Yes, agreed.

@Onno-Dirkzwager
Copy link
Collaborator

@espwx
Great thanks for your quick reply!

@Onno-Dirkzwager Onno-Dirkzwager merged commit d8bf2c0 into iotappstory:master Dec 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants