Arduino-esp32: ESP32 webserver

Created on 7 Jun 2017  Â·  26Comments  Â·  Source: espressif/arduino-esp32

Has anyone implemented a decent web server yet like the esp8266 webserver solution.

Most helpful comment

webserver.streamFile in this lib: http://www.fisch.lu/junk/ESP32-WebServer.zip
does not work!! see my last post.
I found another library:
https://github.com/bbx10/WebServer_tng
it works very well!!!!

All 26 comments

ESP8266WebServer works a treat :)

@PhilColbert Translate to English please... :) Is this a vote for the ESP8266WebServer or have you got something that has worked?

Created a PR for this: #430

This SimpleWiFiServer is crazy confusing.

What's kinda gypsy magic is going on there?

    while (client.connected()) {            // loop while the client's connected
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        if (c == '\n') {                    // if the byte is a newline character
        ...
        } else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }

Will there be more adequate implementation of WebServer on EPS32?

For now using @salqadri fork.

I have copied and renamed the library ESP8266WebServer to ESP32WebServer. Only a very view adaptations were needed. So for those who need this right now and can't wait, this might be an easy way to go.

But as mentioned by @me-no-dev in issue #430, it makes non sense to have the same code in two places. I strongly agree on that!

http://www.fisch.lu/junk/ESP32-WebServer.zip

Copy the library to the "libraries" folder of you expressif/esp32 installation folder.

Downloaded the ESP32-WebServer.zip file but the example WebServer examples reference ESP8266 files and won't compile.

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

I believe got the necessary correction needed.

#include <WiFi.h>
#include <WiFiClient.h>
#include <ESP32WebServer.h>
#include <ESPmDNS.h>

const char* ssid = "........";
const char* password = "........";

ESP32WebServer server(80);

Yes, you are right. I forgot yesterday to update the examples ...

This project roadmap may be helpful.

https://github.com/espressif/arduino-esp32/projects/1

@fesch, @bbx10 I added a work item to update the example code into the road map. If you own any of the tasks, please indicate that. If any taske are still missing, feel free to add or I can do it if you tell me what it is.

I've just downladed .zip file posted by fesch

Copied WebServer folder to ~/Arduino/hardware/espressif/esp32/libraries

open arduino ide 1.8

open examples -> Esp32WebServer -> SimpleWebServer

compile, receive multiple errors , as

arduino-1.8.0/libraries/Ethernet/src/Dhcp.h:47:19: error: expected identifier before string constant
#define HOST_NAME "WIZnet"

Arduino/hardware/espressif/esp32/tools/sdk/include/lwip/apps/dhcpserver.h:58:5: note: in expansion of macro 'HOST_NAME'
HOST_NAME = 12,
.
.
.
Arduino/hardware/espressif/esp32/tools/sdk/include/lwip/apps/dhcpserver.h:154:1: error: expected declaration before '}' token
} dhcp_msg_option;

please, any advise ? thanks

@gusantor If you're just looking to use wifi, comment out these lines:

// #include
// ESP32Ethernet ethernet;

and below that, comment out:
// ethernet.begin();

Add these for your network after the includes...
const char* ssid = "ssid";
const char* password = "password";

Add these to setup after Serial.begin();

WiFi.begin(ssid, password);
Serial.println("");

// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to: ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());

Thank you @MarkyAD , it works great

http://www.fisch.lu/junk/ESP32-WebServer.zip link isn't working.

I could see the webserver is still under development, when will it be ready, got projects in pipeline where I would replace ESP8266 with ESP32.

The link should still work ...

@fesch thanks !!!
i tested your lib under: http://www.fisch.lu/junk/ESP32-WebServer.zip
with my example, that runs on the ESP826.


webserver.send(200, "text/html", sHTML); works fine !!


HTTPUpload& upload = webserver.upload(); works fine !!


Download from the SPIFFS does not work very well.
It works, but the downloaded content ist wrong--> it begins with the header.....

File downfile = SPIFFS.open(webserver.arg("filename"),"r");
webserver.sendHeader("Content-Disposition"," attachment; filename=\"" + sendname + "\"");
size_t sent = webserver.streamFile(downfile,"application/octet-stream");


i think the method webserver.streamFile() is the problem.
To stream a .gif or .jpg-file does not work

File pageFile = SPIFFS.open("/logo.gif");
size_t sent = webserver.streamFile(pageFile, "image/gif");

Not even html or simple text file won't work for me (using serveStatic function), since WiFiClient::write(Stream&) is not implemented.

webserver.streamFile in this lib: http://www.fisch.lu/junk/ESP32-WebServer.zip
does not work!! see my last post.
I found another library:
https://github.com/bbx10/WebServer_tng
it works very well!!!!

@kendo55 thank you! The WebServer_tng by @bbx10 was the one I was looking for!

http://www.fisch.lu/junk/ESP32-WebServer.zip not wifi, but for wired ethernet ...

The WebServer_tng streamfile does also not work for me.

root CA upload to SPIFF through HTTPS not successfully.
I try to upload a root CA ( the root CA was from AWS symantec) to SPIFFS through HTTPs, however I can not upload this root CA successful, only root CA can not successful, others private key and public keys are ok to upload through HTTPS. I try to trace the code found the code never reach phase of _currentUpload.status = UPLOAD_FILE_END. it hang at status=UPLOAD_FILE_WRITE.

in WebServer::_parseForm() of parsing.cpp
content of endBuf is always weird that while run till
if (strstr((const char*)endBuf, boundary.c_str()) != NULL) it always can not fulfill this condition.
always can not find boundary in endBuf.
can somebody teach me how to solve ?

debug information as below

Parse Form: Boundary: ----WebKitFormBoundaryx8LmZvvONNsnhaKX Length: 1963
PostArg FileName: /symtec_G5_CA.pem
PostArg Name: data
PostArg Type: application/octet-stream
Start File: /symtec_G5_CA.pem Type: application/octet-stream
handleFileUpload Name: /symtec_G5_CA.pem
Quit FILE START phase
UPLOAD_FILE_WRITE PHASE
total size =1731
content of endBuf=---END CERTIFICATE-----
------WebKitF⸮?L2⸮?d2⸮?

content of boundary=----WebKitFormBoundaryx8LmZvvONNsnhaKX
boundary length=38

aws_symantec

@ sunepedersen

it is essential, that you copy the library (WebServer_tng) in directory:
[Arduino]\hardware\espressif\esp32\libraries

for example: D:\arduino_1_8_5_ESP32\hardware\espressif\esp32\libraries

I actually ran it on Platform.IO, and it compiles just fine! Just not serving any files.

Please update to last code, it's now supporting webserver =)
https://github.com/espressif/arduino-esp32/tree/master/libraries/WebServer

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lonerzzz picture lonerzzz  Â·  3Comments

DrewHoyt picture DrewHoyt  Â·  4Comments

mistergreen picture mistergreen  Â·  4Comments

maxpromer picture maxpromer  Â·  3Comments

Curclamas picture Curclamas  Â·  4Comments