forked from tsaarni/esp32-micropython-webcam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebcam.py
42 lines (30 loc) · 822 Bytes
/
webcam.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import camera
import picoweb
import machine
import time
import uasyncio as asyncio
led = machine.Pin(4, machine.Pin.OUT)
app = picoweb.WebApp('app')
import ulogging as logging
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('app')
@app.route('/')
def index(req, resp):
# parse query string
req.parse_qs()
flash = req.form.get('flash', 'false')
if flash == 'true':
led.on()
camera.init()
# wait for sensor to start and focus before capturing image
await asyncio.sleep(2)
buf = camera.capture()
led.off()
camera.deinit()
if len(buf) > 0:
yield from picoweb.start_response(resp, "image/jpeg")
yield from resp.awrite(buf)
else:
picoweb.http_error(resp, 503)
def run():
app.run(host='0.0.0.0', port=80, debug=True)