ESP32 as stanalone Webserver
ESP32 as stanalone Webserver
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.
be shown, regardless which IP Address or name. Just like the start page of a hotspot.
Re: ESP32 as stanalone Webserver
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
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
Re: ESP32 as stanalone Webserver
There are several examples of captive portal on esp8266 which may be useful to reference
Re: ESP32 as stanalone Webserver
@ 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
@ Wifive . I will go and search for it on ESP8266
I will come back, and hopefully with good news
Re: ESP32 as stanalone Webserver
+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?
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?
Re: ESP32 as stanalone Webserver
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
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
Re: ESP32 as stanalone Webserver
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.
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
Re: ESP32 as stanalone Webserver
Cornelis, any chance you can share the complete example code? github?
Re: ESP32 as stanalone Webserver
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??
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: No registered users and 108 guests