Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not serving static files #1

Closed
jasoncoon opened this issue Feb 16, 2018 · 5 comments
Closed

Not serving static files #1

jasoncoon opened this issue Feb 16, 2018 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@jasoncoon
Copy link
Owner

I am not currently able to get the ESP32 web server to serve static files like I was able to with the ESP8266. The browser requests a file fine, and the response from the ESP32 web server has the correct headers, but the response body is empty.

It is able to connect to wifi, and basic HTTP requests work fine, just not serving static files from SPIFFS.

I have tried three different ESP32 web server libraries, with varying degrees of success:

I'm using this Arduino plugin to upload the sketch data directory containing the static files required for the web app:

Arduino ESP32 filesystem uploader

I am able to list the files stored in SPIFFS to the serial monitor:

Listing directory: /
  FILE: /css/styles.css  SIZE: 32
  FILE: /favicon.ico  SIZE: 4286
  FILE: /images/atom196.png  SIZE: 5469
  FILE: /index.htm  SIZE: 10886
  FILE: /js/app.js  SIZE: 13430

Here's a request for /index.htm:

GET /index.htm HTTP/1.1
Host: 192.168.86.44
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
DNT: 1
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9

And the response headers:

HTTP/1.1 200 OK
Content-Type: text/html
Cache-Control: max-age=86400
Content-Length: 10886
Connection: close

The response body is empty.

HTTP REST requests work fine.

Here's the REST request:

GET /all HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: */*
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
DNT: 1
Referer: http://localhost:8080/index.htm
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9

and the response:

HTTP/1.1 200 OK
server: ecstatic-1.4.1
content-type: text/json
content-length: 520
connection: close
Date: Fri, 16 Feb 2018 02:53:27 GMT

[{"name":"power","label":"Power","type":"Boolean","value":1},{"name":"brightness","label":"Brightness","type":"Number","value":32,"min":1,"max":255},{"name":"pattern","label":"Pattern","type":"Select","value":2,"options":["rainbow","rainbowWithGlitter","confetti","sinelon","juggle","bpm"]},{"name":"autoplaySection","label":"Autoplay","type":"Section"},{"name":"autoplay","label":"Autoplay","type":"Boolean","value":1},{"name":"autoplayDuration","label":"Autoplay Duration","type":"Number","value":2,"min":0,"max":255}]

index.har.zip

@jasoncoon jasoncoon added the help wanted Extra attention is needed label Feb 16, 2018
@jasoncoon
Copy link
Owner Author

jasoncoon commented Feb 17, 2018

I used a fix from @hpwit here: https://github.com/hpwit/lib
from this conversation: https://plus.google.com/+JasonCoon1/posts/UV9YQzXN6a4

Copy libspiffs.a to the ESP32 tools directory:
\Documents\Arduino\hardware\espressif\esp32\tools\sdk\lib\libspiffs.a

And copy esp32fs.jar to the Arduino tools directory:
\Documents\Arduino\tools\ESP32FS\tool\esp32fs.jar

@marcmerlin
Copy link

Do you know if this fix ever made it upstream? Copying around a precompiled file from somewhere with no history, no indication of whether tip of tree is better/more recent and so forth, is not super inspiring :)
@hpwit do you know by any chance?

@jasoncoon
Copy link
Owner Author

Good question. I haven't tried the standard one included in the esp32 sdk in a while. I would hope it's been fixed.

@rorosaurus
Copy link

rorosaurus commented Nov 9, 2019

Hmm, I wasn't able to get it to work - with or without the fix applied. My browser just seems to sit loading a white page. Maybe I have some strange network settings.
In Chrome console, I see GET http://192.168.1.203/ net::ERR_CONTENT_LENGTH_MISMATCH 200 (OK)

Then again, I wasn't able to find the appropriate folders mentioned for the first file in the fix. I ended up copying that to \AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.3\tools\sdk\lib instead. I assume the difference is due to Windows :)

@FryAllenEthan
Copy link

I've also tried both versions, fix and no fix, and get the same length mismatch error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants