ESP32-CAM with picoweb server

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
TRMrNo
Posts: 15
Joined: Fri May 28, 2021 9:24 pm

ESP32-CAM with picoweb server

Post by TRMrNo » Sun Jun 12, 2022 10:34 pm

Hi Folks,

I am able to capture image with ESP32-CAM module and show it on web page. However captured photo is one previous photo. That is, I need to refresh the page twice to get the current photo. What could be the solution to get the current photo ?



Code: Select all

def rdImage():
    q=camera.capture()
    return b'--frame\r\nContent-Type: image/jpeg\r\n\r\n'+q

@app.route("/img")
def index(req, resp):
    yield from picoweb.start_response(resp)
    q="""
    <!DOCTYPE html>
	<html lang=en>
        <head>
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <link rel="stylesheet" href="" integrity="" crossorigin="">
        	<meta charset="UTF-8" />
            <title>ESP32 CAMERA</title>
        </head>
        <body style="background-color:white;">
            <center>
            <h1>ESP32 CAMERA</h1>
            <img src="/image" width="640" height="480"/>
            </center>
        </body>
    </html>
    """
    yield from resp.awrite(q)
    gc.collect()

@app.route("/image")
def index_mjpeg(req, resp):
    LED.on()
    q=rdImage()
    yield from picoweb.start_response(resp, content_type="multipart/x-mixed-replace; boundary=frame")
    yield from resp.awrite(q)
    gc.collect()
    LED.off()

logging.basicConfig(level=logging.INFO)

app.run(debug=True,host='0.0.0.0',port="80")

tepalia02
Posts: 99
Joined: Mon Mar 21, 2022 5:13 am

Re: ESP32-CAM with picoweb server

Post by tepalia02 » Mon Jul 04, 2022 10:58 am

There are tutorials on this subject. Could not find one based on micropython unfortunately. Have you tried to perform this same task using Arduino IDE?

Post Reply