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")