Initial Setup via AP

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
Posts: 7
Joined: Thu Jun 09, 2016 1:37 pm

Initial Setup via AP

Post by hansamann » Thu Jun 09, 2016 1:42 pm

I would like to create a script using MicroPython that initially, when the esp8266 is not yet configured, starts in AP mode and opens a configuration web page for choosing a wifi access point and managing the password. Also when it is configured and cannot connect, it should fall back into this AP mode so it can be re-setup.

Once this step is done, the esp8266 should reset and execute the script.

I know there are some some examples for web server in the current examples, but it's just showing how to render single very simple page. I am sure that multiple routes, html pages stored in flash, templating are possible. Has anyone already started work on thsi or is there even an example project out there?

Posts: 2
Joined: Wed Jun 08, 2016 1:46 pm

Re: Initial Setup via AP

Post by amwales » Thu Jun 09, 2016 2:15 pm

I am planning on doing something very similar.
You want to get the esp8266 to act as a captive portal.
Basically setup the esp8266 in AP mode and intercept DNS requests such that the address returned for any query is the address of the esp8266 device.

The esp8266 needs to be running as a webserver listening on that address at the same time as serving these DNS requests.
It can then serve a webpage listing all the WIFI networks it can find allowing the user to select one and asking for a paswword as appropriate.

I have found some code that will do the DNS part. ... ns-server/

Fix the print statements so they work with python v3.
The socket connections need to be non blocking, a callback like interface would be appropriate here.
Whether something can be done with the setsockopt to provide a callback on data being available is a good question to ask.
But lets see the direction things may take when asyncio gets added.

There's a lot of information about captive portals and how different OSes handle them.
It looks like vendors have noticed that people don't understand that they need to access webpages to fillout forms behind such walled gardens and help by automatically popping up webbrowers at the point a captive portal is found, that's nice. You dont have to tell the user anything other than select the esp8266 as an access point on their android/ios device and they will be given a popup :)

Good luck with your efforts,
I'll start it soon but have a long list of other unfinished projects.

User avatar
Posts: 1382
Joined: Thu May 28, 2015 5:54 pm

Re: Initial Setup via AP

Post by deshipu » Thu Jun 09, 2016 2:18 pm

I think it is still much too early for this to exist, but I'm sure that it will surely come. In the mean time, you can start on your own, and maybe be the first person who gets it working and whose solution will be then used everywhere?

Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Initial Setup via AP

Post by pfalcon » Thu Jun 09, 2016 2:56 pm

It's Python, a magic language. If a simple thing doesn't exist (and a web server is a simple thing for Python), in 10 minutes you can have some initial crude prototype, in 30 minute something less crude, and in an hour something almost working - for you. It however takes much more effort to make something which works for *everyone*. That's why it's still in the queue for maintainers, but again, you don't need to wait to solve your own problems. HTTP server sample exist, see e.g. examples/ dir in MicroPython source tree.
Awesome MicroPython list
Pycopy - A better MicroPython
MicroPython standard library for all ports and forks -
More up to date docs -

Posts: 7
Joined: Wed Sep 14, 2016 11:51 am

Re: Initial Setup via AP

Post by soapdog » Wed Sep 14, 2016 11:59 am

Hey Friends,

First post here. I just built a captive portal for MicroPython and the ESP8266. Basically it has a hijacking DNS server and a Web server in the same loop so that it can trigger the Web interface. In this demo, I have an RGB LED attached to ports 5,4,0 and the Web interface allows you to change its color.

I am sorry if my python is not idiomatic, I am new to Python too. This has been tested on a NodeMCU device during "View Source 2016" with about 160 clients connecting to it during the day (not at the same time, phew) ... ive-portal

also a video demo at:

Posts: 84
Joined: Sat Aug 22, 2015 6:42 am

Re: Initial Setup via AP

Post by mianos » Thu Sep 15, 2016 3:07 am

With the old firmware I just used the smartconfig and the android app app to configure the IP. It uses some crafted wifi messages to communicate with the board before the wifi is associated: ... rtconfig.c

Posts: 134
Joined: Thu Sep 15, 2016 4:09 pm
Location: Spring, Texas

Re: Initial Setup via AP

Post by bitninja » Fri Sep 15, 2017 9:50 pm

Here is a related topic...


Although the captive portal solution by soapdog is a good bit of code as well.

User avatar
Posts: 32
Joined: Thu Jul 21, 2016 5:38 pm

Re: Initial Setup via AP

Post by fdushin » Mon Sep 25, 2017 11:09 am

This was part of the motivation for the web-console [1] prototype I used to drive the implementation of uhttpd.

The problem I ran into was that due to some issues I have yet to resolve with uhttpd, I was unable to load the set of HTML, CSS, and Javascript files in parallel (modern web browsers will load resources from web sites in parallel, if they have the opportunity to), as they would need to be hosted on the device in AP mode. I chose backbone.js as an MVC framework and W3.CSS as a stylesheet, but I am sure you could write something much more austere and make it work. It is just for bootstrapping, after all. Or we could try to fix my horrible use of uasyncio and get parallel loading to work :) ... eb-console

Posts: 134
Joined: Thu Sep 15, 2016 4:09 pm
Location: Spring, Texas

Re: Initial Setup via AP

Post by bitninja » Mon Sep 25, 2017 2:37 pm

The most successful attempt I have made was to use pfalcon's picoweb...

Using a basic application to serve content...


It does take the ESP8266 some time to deliver some of the larger files (Bootstrap, JQuery, etc...) but it does seem to manage it.

Post Reply