WiFi Manager For Blynk Local server

Yes during

This was modified and compiles ok ! But doesn’t connect to the server !!

I uploaded the same code i have posted(modified) compiles ok
commented out //SPIFFS.format();

but doesn’t connect to the sever !!

serial monitor

mounting FS...
mounted file system
reading config file
opened config file
{"server":"192.168.0.xxx","port":"8080","auth":"53a4dea60299432cb0axxxxxxxxx"}
parsed json
*WM: Adding parameter
*WM: server
*WM: Adding parameter
*WM: port
*WM: Adding parameter
*WM: blynk
*WM: 
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Using last saved values, should be faster
*WM: Connection result: 
*WM: 0
*WM: SET AP
*WM: 
*WM: Configuring access point... 
*WM: Wifi_Manager
*WM: password
*WM: AP IP address: 
*WM: 192.168.4.1
*WM: HTTP server started
*WM: Request redirected to captive portal

I wasn’t suggesting hard-coding it as a variable, which you’ve already done, I meant like this:

Blynk.config(auth, server, 8080);

Pete.

Hurray !!! This worked !!

Serial monitor :point_down:

mounting FS...
mounted file system
reading config file
opened config file
{"server":"192.168.0.xxx","port":"8080","auth":"e9d0aec900f24eee98f96xxxxxxxxx"}
parsed json
*WM: Adding parameter
*WM: server
*WM: Adding parameter
*WM: port
*WM: Adding parameter
*WM: blynk
*WM: 
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Using last saved values, should be faster
*WM: Connection result: 
*WM: 3
*WM: IP Address:
*WM: 192.168.0.107
connected...yeey :)
BLYNK Connected

@PeteKnight You are just GENIUS !!
@Toro_Blanco Thank you for the example code and support !!
I am HIGHLY THANK FULL TO YOU GUYS !!!

2 Likes

Hello !
I am not sure whether i can post here or not ! As i have changed the status to SOLVED !!
But this time i will ask my doubt\Problem here

The problem is when the wifi router is down and then when the device tries to connect to it !! It cannot connect to the network and it will start hosting like it is a new device and needs to setup with the wifi credentials and auth token. But when the router is available it works normally !!

Is there a way that i can stop the device from running into hotspot mode and instead try reconnecting to the blynk server ??

By skipping the rest of the wifi manager stuff ??

Configuration Portal Timeout

If you need to set a timeout so the ESP doesn’t hang waiting to be configured, for instance after a power failure, you can add

wifiManager.setConfigPortalTimeout(180);
which will wait 3 minutes (180 seconds). When the time passes, the autoConnect function will return, no matter the outcome. Check for connection and if it’s still not established do whatever is needed (on some modules I restart them to retry, on others I enter deep sleep)

Pete.

@PeteKnight

WiFiManager wifiManager;
wifiManager.setConfigPortalTimeout(60);

I have added ```wifiManager.setConfigPortalTimeout(60);
and after 60 Sec it will reset and again search for wifi router by that time the router should have booted up after a power failure !! Then if connects to the router and the device connects to Blynk…

Usually Blynk alone hardly takes 2 or 3 sec to join the server without the wifi manager stuff running ! So it would be good if wifi manager stuff runs only once per device [during its first setup ever] ! And later on it will always run into Blynk.config and works fast as a regular device without wifi manager !!

I tried setting a flag to the wifi manager !! But failed :expressionless:

Is there any other way to get around wifi manager to avid the delay !!!

I’m not sure that i understand your issue.

Pete.

1 Like

WiFiManager does only run once at bootup, well if you put it in void setup() anyway.

@PeteKnight @JustBertC
I will try to explain now in a better way (sorry for my bad English).

For the First time when the device boots up it should ask us to config the device with the credentials !! And after this !! It never ever ask us to config the device due to lack of router to connect and work !! Because we already have reconnect enabled on Blynk end.

This is the serial Monitor output as of now

Initializing the Credential's File
Mounting the Credential's
Reading config file
Opened config file
{"server":"192.168.0.103","port":"8080","auth":"f1750966c7c94490b3e7xxxxxxxxxx"}
parsed json
*WM: Adding parameter
*WM: server
*WM: Adding parameter
*WM: port
*WM: Adding parameter
*WM: blynk
*WM: 
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Using last saved values, should be faster
*WM: Connection result: 
*WM: 1
*WM: SET AP
*WM: 
*WM: Configuring access point... 
*WM: AP
*WM: 12344321
*WM: AP IP address: 
*WM: 192.168.4.1
*WM: HTTP server started
failed to connect and hit timeout

 ets Jan  8 2013,rst cause:1, boot mode:(3,7)

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v614f7c32
~ld

Initializing the Credential's File
Mounting the Credential's
Reading config file
Opened config file
{"server":"192.168.0.103","port":"8080","auth":"f1750966c7c94490b3e7xxxxxxxx"}
parsed json
*WM: Adding parameter
*WM: server
*WM: Adding parameter
*WM: port
*WM: Adding parameter
*WM: blynk
*WM: 
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Using last saved values, should be faster
*WM: Connection result: 
*WM: 1
*WM: SET AP
*WM: 
*WM: Configuring access point... 
*WM: AP
*WM: 12344321
*WM: AP IP address: 
*WM: 192.168.4.1
*WM: HTTP server started
failed to connect and hit timeout

 ets Jan  8 2013,rst cause:1, boot mode:(3,7)

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v614f7c32
~ld

Initializing the Credential's File
Mounting the Credential's
Reading config file
Opened config file
{"server":"192.168.0.103","port":"8080","auth":"f1750966c7c94490b3e788f4b3b95f5c"}
parsed json
*WM: Adding parameter
*WM: server
*WM: Adding parameter
*WM: port
*WM: Adding parameter
*WM: blynk
*WM: 
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Using last saved values, should be faster
*WM: Connection result: 
*WM: 3
*WM: IP Address:
*WM: 192.168.0.106
Connection Successfull
Connected
Blynk Successfully Connected

(WHILE TESTING)
Twice it tries to connect if the router is not available then [i had turned off the router] it will go into config mode. By the third time reset i had the router turned on then it connects normally !!

My idea is to block the wifi manager stuff after first ever config !! And it should never show up again no matter what happens !! So that it directly let Blynk.config to run and if no router found then i have the reconnect coded in the loop this will take care of the rest !!

By doing this at least our hardware buttons(using sync physical example code) will work. Or else the wifi manager stuff will keep blocking until it has a router to connect !!

That kind of begs the question, why use WiFiManager in the first place?

Pete.

Just for the First Ever Config of the device !!

Why not hard-code the credentials then?

Pete.

For the ease and flexibility !! I know wifi manager is good and is handy ! But my idea is to get rid of it once the credentials have been saved !! Why do we need it again ?

How did you do the flag to check for first every bootup? EEPROM or JSON I guess?

Or did you try to just use a bool?

WiFiManager is primarily intended to be used in an environment where you either want to:

a) ship a device to someone and allow them to connect it to their Wifi system without the need for them to get their hands dirty flashing code

b) use the same device in multiple locations without the need to re-flash the code each time.

You seem to be using it for neither of these purposes.

I’m sure there is a way to use it in the way you want to, but I for one don’t want to waste any time exploring that avenue, as its of no interest to me. It’s not a Blynk related issue either, so probably not something that many Blynk community, members will have an answer for.

Pete.

i created a function of wifi manager and later set a flag later…

Yes,
Definitely its not a Blynk related issue…
I will look into it if something can be done…
Thank you for the help…

Can you show us how?

I think you need to be either using eeprom or a json file so that at bootup it can check whether or not it needs to run WiFiManager. Because currently at every reset it will re-run it.

Edit - or you could look into using an input pin to trigger the wifimanager.

He’s using SPIFFS at the moment.
I think the issue is that if the router/internet is down then it’ll launch captive portal and he doesn’t want that to happen.

Pete.

Yes for the storing of ssid, pass and auth.
I was thinking he could use a similar approach to save a variable as to whether the wifimanager has launched for the very first time.

Seems like this would be the most sensible solution though, just use an input pin to trigger the setup process.

OnDemandPortal:

1 Like