I'm in the process of building an IoT device using ESP8266. The device will eventually contain a couple of motors, and I would like to control these motors using MQTT. I would like to make the device as cheap as possible, so I would like to avoid things like displays and keyboards.

So, when the device is turned it is supposed to connect to the local WiFi, and then to an MQTT broker. But how does it know about the local SSID to connect to, and what about username and password? Since the device has no display or keyboard, there is no way to input these things. And how does the user know if the device was able to connect or not? For troubleshooting, it would be nice if the device at least had some way to indicate what the problem might be.

The solution I have thought of is to have one button and one LED on the device. The button would be marked "config" or similar. When the button is pressed, the device will start operating as a WiFi access point with a predefined SSID. It will have a webserver, so the user can connect with a laptop or phone to this predefined access point and enter the local network settings (SSID, username and password) as well as the address for the MQTT broker. The LED will be used to indicate the mode of operation, and also as error indication. For example, when the LED is glowing steady everything is connected, long flashes means it is in config mode, short flashes means there is an error, or something similar.

My question is, is the solution I have proposed a standard way of doing things when it comes to this problem? I.e. will it feel like a familiar flow to the user, or would some other way be better? After doing a little bit of searching I have found e.g. this, which seems to be a similar user flow. Would still be interested in hearing what experience you have of this, and hear how you would solve it?

If it turns out that this is a good and useful way to solve this problem, and since it is a kind of generic solution, it would be nice to not reinvent the wheel too much. I'm thinking that there could be a library that could do all of this. The library would be configured with the input pin for the button and output pin for the LED, and then take care of the rest. It could be built upon the PubSubClient library and based on the tutorial ESP8266: Connecting to MQTT broker. So is there a library that does this or something similar? If not I'll take a stab and create my own, but would like to hear about what's out there first.



What you describe is actually a quite common (the most common?) way to solve the problem of integrating WiFi IoT devices into your local LAN.

For example, from my experience Amazon Echo Devices are setup this way or a variety of smart switches/smart plugs (e.g. Shelly devices).

Depending on your requirements, you could also get away without the LED and the button.
Here is a solution with technical details that will try to connect to the configured network and if not successful open an access point for configuration.
And here a second implementation using a captive portal in AP mode.

Implementation of the MQTT PubSub part and the button and LED into the respective sketch should be fairly straightforward.

For possible alternatives to the use of AP mode for configuration, please have a look at the techniques of Wi-Fi Protected Setup (WPS) and Device Provisioning Protocol.

  • Thanks for a very good answer! The WifiManager library in your second link seems to be exactly what I'm looking for. I will give it a try and see if I love it. If not, I will use the information in the first link to build my own solution... – Mikael Lindqvist Jul 4 '19 at 5:59
  • 1
    Oh... And here is an addition that adds the MQTT part as well: github.com/dreed47/WifiMQTTManager – Mikael Lindqvist Jul 4 '19 at 6:04

There is also the luftdaten.info project which is a open-source particle sensor with its own firmware. They do a similar thing to what you proposed, only without the config button. They do so, by starting the web server per default, when the device is powered on. After a certain threshold (I think it's somewhere between 3-10 minutes), the internal web server will be shut down - so no more configuration is possible until the next power cycle.

This solution might be too insecure for certain scenarios, but you might want to know about nevertheless.

New contributor
Jens Kohl is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • 2
    Just starting a web server doesn't solve the problem of how to pass the SSID/Password for the wifi network to the device to actually get it on the network. – hardillb Feb 13 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.