I am running MicroPython 1.8.7 in ESP12-F. Trying to add images in web pages that are hosted by the "ESP Micropython Server".
I got a little bit success, but still, it's buggy. Whenever the socket connection is closed, image loads no more and inspect elements shows "net::ERR_CONNECTION_RESET" error.
I have stored an image named alogo.gif in the file system of micropython and trying to send it when a client (browser) requests it. If I don't close socket in code, the image loads but loading bar in browser keeps on rotating forever. If stopped by clicking on "cross" (X), image vanishes. Below is my code.:
[CODE]
import machine
html = """<!DOCTYPE html>
<html>
<body>
<h2>Arduino Logo</h2>
<img src="alogo.gif" alt="Arduino">
</body>
</html>
"""
imOpen = open('alogo.gif')
image=imOpen.read()
imOpen.close()
import socket
addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
s = socket.socket()
s.bind(addr)
s.listen(1)
print('listening on', addr)
while True:
cl, addr = s.accept()
#print('client connected from', addr)
cl_file = cl
while True:
line = cl_file.readline()
line2=str(line)
print(line2)
if not line or line == b'\r\n':
cl.write(html)
#cl.close() commented, so that image can load
break
if line == b'GET /alogo.gif HTTP/1.1\r\n':
cl.write(image)
# cl.close() commented, so that image can load
break
[/CODE]
I've been trying for more than 2 months. This time got a little bit success but need your help to find a proper solution. Thank you all.
How to send image (.jpg, .gif etc) from esp8266 webserver
-
- Posts: 4
- Joined: Sun May 21, 2017 11:23 am
Re: How to send image (.jpg, .gif etc) from esp8266 webserver
Did you ever resolve the problem you were having serving images?
I'd like to create a simple web server on an ESP32 and I'm trying to gather advice.
I'd like to create a simple web server on an ESP32 and I'm trying to gather advice.
-
- Posts: 4
- Joined: Sun May 21, 2017 11:23 am
Re: How to send image (.jpg, .gif etc) from esp8266 webserver
Yes, I solved it and made a great web server code that can even handle gzip compressed files. If you need it, ping me.
Re: How to send image (.jpg, .gif etc) from esp8266 webserver
would you mind sharing the code? github repo, perhaps
Re: How to send image (.jpg, .gif etc) from esp8266 webserver
I'd also like to see the code. Tried to send you a message on the forum but it looks like it's stuck in my outbox.
Do you have a repo?
Do you have a repo?
-
- Posts: 4
- Joined: Sun May 21, 2017 11:23 am
Re: How to send image (.jpg, .gif etc) from esp8266 webserver
I have not uploaded the code to GitHub yet. I'm bit busy now for a rocket launch program. My email ID abhra0897@gmail.com. Please email me after 3-4 days and I'll send you the code/GitHub link.
Re: How to send image (.jpg, .gif etc) from esp8266 webserver
There are likely many solutions out there already. Feel free to try, for example,
https://github.com/fadushin/esp8266/tre ... hon/uhttpd
It is designed more for REST-ful web applications, but it does have a file server module.
https://github.com/fadushin/esp8266/tre ... hon/uhttpd
It is designed more for REST-ful web applications, but it does have a file server module.
-
- Posts: 4
- Joined: Sun May 21, 2017 11:23 am
Re: How to send image (.jpg, .gif etc) from esp8266 webserver
That's great! Thanks for sharing.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: How to send image (.jpg, .gif etc) from esp8266 webserver
@fdushin The HTTP daemon looks really useful. Excellent docs too
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.