ESP32 as stanalone Webserver

Cornelis
Posts: 9
Joined: Wed Feb 08, 2017 7:21 pm

ESP32 as stanalone Webserver

Postby Cornelis » Wed Feb 08, 2017 7:31 pm

I would like to setup a standalone Webserver where, if I am connected and I open my browser my Webpage will
be shown, regardless which IP Address or name. Just like the start page of a hotspot.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: ESP32 as stanalone Webserver

Postby kolban » Wed Feb 08, 2017 10:56 pm

Howdy Cornelis,
I too would be interested in seeing how to achieve this. I believe the technical/jargon name for this is a "captive portal". I am imagining that you want your ESP32 running as a WiFi Access Point to which WiFi stations (PCs, phones, tablets) can connect. Then when a browser is brought up and we try and navigate "anywhere" in the browser, a page is served up by a WebServer inside the ESP32?

I believe the way this is normally done(outside of ESP32 land) is that when the station connects to the access point, the access point says "Hey, station ... here is the gateway address you should send all requests to". That gateway server then "maps" ALL incoming routing requests to the machine hosting the WebServer.

For example ... imagine an Access point with IP 10.0.0.1 which also hosts gateway software. Now imagine a station connects and is given the IP 10.0.0.2 and told that the gateway it should use is 10.0.0.1. Now a user on the station brings up a browser and points to http://www.google.com. This might resolve to the REAL IP address of Google ... and the station now sends an HTTP request to that address ... however ... to reach there, the request is send to the access point (10.0.0.1). The routing software om the gateway then says "Aha ... I am going to deliver this connection to MYSELF as an endpoint" ... and the connection arrives at the Web Server hosted on the access point.

On Linux, commands/systems like "iptables" can be used for this kind of technique. However, on the ESP32, we may be stuck. I haven't seen any evidence that an ESP32 can act as an IP gateway ... and if that is the case ... then we can't supply the ESP32 as the gateway address returned to a connecting WiFi station ... and we might be stuck.

(As always, I reserve the right to be 110% wrong :-)
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ESP32 as stanalone Webserver

Postby WiFive » Thu Feb 09, 2017 12:06 am

There are several examples of captive portal on esp8266 which may be useful to reference

Cornelis
Posts: 9
Joined: Wed Feb 08, 2017 7:21 pm

Re: ESP32 as stanalone Webserver

Postby Cornelis » Thu Feb 09, 2017 3:44 pm

@ kolban . thx , yes, thats exactly what I want.
@ Wifive . I will go and search for it on ESP8266
I will come back, and hopefully with good news ;) ;)

andrew_p
Posts: 30
Joined: Sun Jan 01, 2017 5:37 pm

Re: ESP32 as stanalone Webserver

Postby andrew_p » Thu Feb 09, 2017 11:28 pm

+1
I'm looking for the same example - captive portal on ESP32.

There are some examples for esp8266 with Arduino core, but that may not be compatible with ESP32. There is a great example of OpenSSL web server, but how to set it up so it works as a captive portal? Is that even possible?

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ESP32 as stanalone Webserver

Postby WiFive » Fri Feb 10, 2017 5:27 am


Cornelis
Posts: 9
Joined: Wed Feb 08, 2017 7:21 pm

Re: ESP32 as stanalone Webserver

Postby Cornelis » Sun Feb 12, 2017 4:56 am

I add this to my code, and after sum small changes, due to differences between Esp8266 and Esp32, this code Runs.

After Booting the AP comes up, and the captdns service is started.

Then when I connect to the AP, the Mobil device automatically send a request and
the captdns service tries to response on this.

But it ends with a Stack overflow.

After some debugging , it seems that the problem happens within

ret=recvfrom(sockFd, (u8 *)udp_msg, DNS_LEN, 0,(struct sockaddr *)&from,(socklen_t *)&fromlen);

This is a ESP8266 fuction which also exsist within the latest SDK of Espressif.

Does someone has a idea?

Thanks Cornelis

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: ESP32 as stanalone Webserver

Postby kolban » Sun Feb 12, 2017 5:20 pm

Howdy Cornelis,
I think the clue in your post is the "stack overflow". In an ESP32, we run "tasks" (which in other environments can be thought of as threads). A task is a function that is executed concurrently to other tasks. When we create a task, we allocate to that task the maximum stack size it can have. If that stack size is too small for its needs, we detect and generate a stack overflow error. The solution is to allocate more space for the task when it is created. Look through your code (probably in main somewhere) for statements such as:

xTaskCreate(&myTask, "myTask", 2048, NULL, 5, NULL);

or

xTaskCreatePinnedToCore(&myTask, "myTask", 2048, NULL, 5, NULL, 0);

In these examples, parameter 3 (2048) is the initial stack size. Try bumping it up to 10000 (or more) and try again.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

andrew_p
Posts: 30
Joined: Sun Jan 01, 2017 5:37 pm

Re: ESP32 as stanalone Webserver

Postby andrew_p » Sun Feb 12, 2017 9:59 pm

Cornelis, any chance you can share the complete example code? github?

seopyoon
Posts: 23
Joined: Thu Dec 08, 2016 8:25 am

Re: ESP32 as stanalone Webserver

Postby seopyoon » Mon Feb 13, 2017 2:23 am

I am trying to implement the same for my application, so I can have the user input ssid and password for home network.

How did you go about doing this?? I tried to base my code on a captive portal arduino project, and started to port some libraries, and I have come to a dead end. It is not working.

Could you provide more information, or share the base code??

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 79 guests