ESP8266 with Arduino Newbie Problems

I had a very long day yesterday trying to set up my ESP8266 and Arduino to access my router and then the Blynk server. What I was trying to do was have a switch connected to GPIO4 on the ESP8266 and if the pin was high it would run a webserver and request SSID and password for the router, if the pin wasn’t high it already had the router SSID etc and connected to Blynk server.

Obviously this is something many other people have already considered as there are various utilities to do this. When I checked the Community this morning it seems to be littered with posts in the last 24 on the same theme including posts by the author of WiFiManager @tzapulica

This is the code I ‘flashed’ to the ESP:

#include <ESP8266WiFi.h>          //

//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>         //

void setup() {
    // put your setup code here, to run once:

    //read gpio 4 state on startup
    pinMode(4, INPUT);
    int pinState = digitalRead(4);
    //Local intialization. Once its business is done, there is no need to keep it around
    WiFiManager wifiManager;
    //if gpio 4 is high clear stored router access details i.e connected to 5V
    if (pinState == HIGH) {
      //reset saved settings
      //set custom ip for portal
      wifiManager.setAPConfig(IPAddress(192,168,4,1), IPAddress(192,168,4,1), IPAddress(255,255,255,0));
      //fetches ssid and pass from eeprom and tries to connect
      //if it does not connect it starts an access point with the specified name
      //here  "AutoConnectAP"
      //and goes into a blocking loop awaiting configuration
      //or use this for auto generated name ESP + ChipID


    //if you get here you have connected to the WiFi
    Serial.println(" Connected to your router :)");

void loop() {
    // put your main code here, to run repeatedly:

It seems to work ok but I think I might have had some pin bounce as sometimes it ignored the pin4 status on resetting the ESP. Generally though it was ok.

I then went back to my original Arduino sketch that was working before I flashed @tzapulica WiFi Manager and it no longer connects.

So the questions are:

  1. Should I have added the WiFi Manager code to my Blynk code on the Arduino rather than flashing the WiFi manager to the ESP?

  2. How do I clear WiFi Manager from the ESP if my assumption in 1) is correct? Can I just flash an ‘empty’ Arduino sketch to the ESP or does the ESP expect to have a certain base sketch?


to remove WiFiManager, just remove the includes and the code referencing wifiManager. if the sketch has no reference of WiFiManager, then it doesn’t influence it in the slightest.

to remove the saved settings do WiFi.disconnect(); this should clear the saved ssid/pass.

in the mean time, that example has been updated, so it works while pressing a push button after boot. that way it works with esp-01 's as well and it should take care of the debouncing problem as well. speaking of debouncing, you would probably need a pullup or something on gpio4 for it to have a defined state. i haven noticed it working weirdly when left floating.

if you don t specifically need to use a button to enter config, i’d suggest using one of the autoConnect sketches. they are simpler and have worked perfectly for my needs at least.

btw, i may have misunderstood, do you have both an arduino and an ESP?
are you using the ESP just to provide WiFi to the arduino?

in that case, you need to burn the AT firmware back on the ESP, as that’s what gives you WiFi access…

WiFiManager is made to work for standalone ESP8266 instalation, where you use solely the ESP chip for both arduino code and WiFi

Yes the ESP gives WiFi to the Arduino, I’m not running it standalone (yet).
Could you direct me to the AT firmware so I can reflash the ESP?
Thanks for your help @tzapulica

never done it myself, see here
he seems to be doing just that…

Thanks I’ll take a look at the instructable.
Once I am back to square one can I add your libraries to the standard Blynk sketches (not standalone) to have WiFi manager features? If not how are Blynk users covering this issue? this is also a very comprehensive guide to flashing your ESP. I made a little print to attach to my serial convertor so I can do the automatic flash, that is something I’d recommend doing if you plan on using these guys frequently :slight_smile:

I don’t think you can use the WiFi manager with the ESP attached as shield to Tx/Rx. From what I can tell it has to be attached directly, but @tzapulica can probably confirm or deny this.

Thanks @Lichtsignaal do you think I can simply flash the Blink (not Blynk) sketch to the ESP to recover the regular AT commands? The reason I ask is I’m not sure which bin files I would need to do a ‘real’ flash.

No, you need to flash the AT firmware on there. If you programmed it with the Arduino IDE the AT firmware is gone.

-edit, try this:

That always worked for me.

I found that bin a few minutes ago. I’ll give it a shot.

Which flashing tool do users recommend?

Depends a bit, I use the python script, but for windows you could probably do with this:

We are on the same page, just about to try with the Xess stuff and the 2 bin files.

Just the one bin required and the Xess looks to work fine. AT back up and running. Will now check my basic Blynk sketch. Still interested to know how users are getting the ‘WiFi Manager’ features without using the ESP in standalone mode. As well as SSID and password there is also the auth token to take care of.

Basically, the procedure will be the same, just not on the ESP platform, but it can be saved to Arduino EEPROM I guess. It’s just a bunch of vars being filled with some logic? Doesn’t sound overly complicated to me :slight_smile:

@Costas WiFiManager does not work for your scenario, only for standalone esp8266 deployments with arduino ide.

I have not run into any solution for the AT firmware yet, sorry.

@tzapulica I was just confirming I’m a newbie by not understanding the aspect of standalone. Not sure quite what you mean about a solution for AT firmware.

@Lichtsignaal yes it should be easy enough to read and write the auth in Arduino EEPROM but it needs a full solution like @tzapulica made for the ESP standalone i.e. a basic web interface to collect the 3 variables (SSID, pwd and auth).

That is very true. I’m not very far (haven’t started even yet) with building Arduino Libraries, but I may built something soon. I can see some possibilities in conjunction with my remote Lego Train stuff and some standalone server.

solution = similar library that does everything in a web interface

i have not seen any yet, not to say that it s not there

the only project i ve seen that has both a webserver and AT command set, is this

maybe you can modify it to your needs

Here is another tutorial you can try.

It is more specific to what you’re trying to do