loading

Hello everyone!

In this instructable I'm going to talk about how you can avoid hard-coding your WiFi credentials into your Arduino sketches using a really awesome library called WiFiManager. It will only take a couple of minutes to go through these steps.

Check out the video or continue reading here to find out how to add it and how it works.

Step 1: Why Is This Important?

If you have hard-coded values in your sketch, if you change your WiFi router or want to bring your device to somewhere else, you are going to need to re-program your esp8266, which isn't ideal!

It also makes your sketches less sharable, as you probably will want to replace your SSID and Password with placeholders before uploading to somewhere public like GitHub and anyone who is using your code is going to have to update the code before they can use it on their network.

<p>This is useful info on a library I certainly didn't know about. Thanks for sharing. I've got a bunch of 8266s running around, all hard coded. Can't wait to try it out. </p><p>Much appreciated. </p>
<p>Yeah I like to use the library for any project that &quot;goes to production&quot; so to speak (becomes a thing in my house), unfortunately I don't really have that many at the moment but hoping to change that soon! <br><br>Thanks for your comment</p>
The truth is that it is surprising that there was nothing done before. It's something that worried me a lot about the comments you've said yourself, regarding changing the router or data connection wifi. Thank you very much.
<p>You are welcome! Apparently this library has been around for a while but I guess not everyone knows about it yet.</p>
<p>Really cool!! Thank you so much for sharing!!</p>
<p>You are more than welcome! Thanks for commenting!</p>
<p>Cool! Is this library on Github written by you?</p>
<p>No, I'm not the author of this library. Funnily enough before I found it I had a similar idea and went checking to make sure something didn't exist. Glad I did because they have done a really great job with this library!</p>
Now what we need, is a way to store multiple WiFi settings so we can use it in the car etc....
<p>Yeah that would be pretty cool! I think it would be worth opening a Github issue on the library requesting that functionality.</p>
What happens if the WiFi is down and my esp starts, later the WiFi goes up again? Will the esp connect or will it just stay in config mode?
<p>It will stay in configuration mode, but will rememeber the last credentials that worked until you actually connect and reconfigure it. So you can restart ESP8266 and it'll reconnect to your access point if it's up.</p><p>Personally I find it inconvenient as in case of power outage, the microcontroller restarts much faster than wifi router starts the network. This means you'll have to go and restart all your micro devices if you happen to have several of them, which is common for home automation.</p><p>To tackle this, it's better to have some timeout for configuration, such as in this example - https://github.com/tzapu/WiFiManager/blob/master/examples/AutoConnectWithTimeout/AutoConnectWithTimeout.ino</p>
<p>Thanks for answering as I wasnt sure!</p>
Thanks for sharing this library, very useful !<br>Would something like this also exist for the MKR1000 from Arduino ?<br>
<p>Sorry I have never used a MKR1000 so I'm not sure.</p>
Thank you witnessmenew - you've just made my 2017
<p>You are welcome! Glad I could help!</p>
<p>Brilliant! Thank you!</p>
<p>Your welcome! Thanks for the comment</p>
Thanks a lot ! Exactly what i was looking for !
<p>Your welcome! Yeah its a super useful library! I've added a new instructable on how you can use it for other configurations as well.<br><br>https://www.instructables.com/id/Managing-Configurations-on-Your-ESP8266-Using-WiFi/</p>
<p>Thank you, this is cool,</p><p>would it work with Blynk?</p>
<p>Yes! I don't use Blynk myself but if check out the github page for the library their examples have Blynk settings in them</p>
<p>Very useful.<br>Sometimes I need a static IP address.<br>Could it be possible to set a static IP address (and netmask and default gateway) when we are setting the WiFi Credentials ?</p>
La verdad es que es sorprendente que no hubiera nada hecho antes. Es algo que me preocupaba mucho por los comentarios que has Dicho tu mismo, respecto a cambiar el router o datos de la conexion wifi. Muchas gracias.
<p>Tthat looks really useful. The only problem now is I'm going to have to reprogram a dozen ESP's!</p>
<p>Thanks,useful</p>
Your welcome!
This is great! Thx for pointing out this lib.
Your welcome, glad you found it useful!
<p>I was just looking for a solution for this as recently as yesterday, and then I found this! Thanks for posting!</p>
Your welcome! Yeah it's really useful OK was happy to share it others cause I find it great too
<p>Thank you</p><p>Very helpful</p>
No problem, thanks for commenting
thank u very much. I will follow u ..
Your very welcome! Thanks alot

About This Instructable

24,164views

310favorites

License:

Bio: Hey everyone! My name is Brian and thanks for checking my Instructables. I'm a software developer by trade but I've recently gotten into ... More »
More by witnessmenow:Managing Configurations on Your ESP8266 Using WiFiManager Avoid Hard-Coding WiFi Credentials on Your ESP8266 Using the WiFiManager Library Arduino Traffic Display Using Google Maps API 
Add instructable to: