]>
vault307.fbx.one Git - esp32Cam.git/blob - site.py
2 # The MIT License (MIT)
4 # Copyright (c) Sharil Tumin
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 #-----------------------------------------------------------------------------
25 # site.py MVC - This is the model M of MVC
27 from uos
import urandom
as ran
28 from machine
import Pin
29 from html
import pg
, hdr
30 from help import Setting
as cam
33 # Init global variables
35 flash_light
=Pin(04,Pin
.OUT
)
43 alfa
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890'
44 return ''.join('testCam')
46 # These will be set by server script as site.ip and site.camera
59 cs
.write(b
'%s\r\n\r\n%s\r\n' % (hdr
['OK']%ln
, p
))
64 cs
.write(b
'%s\r\n\r\n%s\r\n' % (hdr
['err']%ln
, p
))
69 cs
.write(b
'%s\r\n\r\n%s\r\n' % (hdr
['err']%ln
, p
))
74 cs
.write(b
'%s\r\n\r\n%s\r\n' % (hdr
['none']%ln
, p
))
76 def setting(cs
,w
,ok
,cmd
,v
):
77 #print("setting:", w, ok)
88 cs
.write(b
'%s\r\n\r\n%s\r\n' % (hdr
['OK']%ln
, p
))
104 print(f
'New PWD: {auth.pwd}')
107 @route('/favicon.ico')
111 cs
.write(b
'%s\r\n\r\n%s\r\n' % (hdr
['favicon']%ln
, p
))
116 p
=pg
['foto']%(f
'http://{ip}/live',rot
) # needed by opera, vivaldi, midori..
118 cs
.write(b
'%s\r\n\r\n%s\r\n' % (hdr
['foto']%ln
, p
))
121 def live(cs
,v
): # live stream
122 cs
.write(b
'%s\r\n\r\n' % hdr
['stream'])
129 put(b
'%s\r\n\r\n' % hr
)
131 put(b
'\r\n') # send and flush the send buffer
132 except Exception as e
:
139 p
=pg
['foto']%(f
'http://{ip}/foto',rot
)
141 cs
.write(b
'%s\r\n\r\n%s\r\n' % (hdr
['foto']%ln
, p
))
146 p
=pg
['foto']%(f
'http://{ip}/boto',rot
)
148 cs
.write(b
'%s\r\n\r\n%s\r\n' % (hdr
['foto']%ln
, p
))
151 def foto(cs
,v
): # still photo
152 #buf=camera.capture()
155 cs
.write(b
'%s\r\n\r\n' % hdr
['pic'])
156 cs
.write(camera
.capture())
157 cs
.write(b
'\r\n') # send and flush the send buffer
158 #nc=cs.write(b'%s\r\n\r\n' % (hdr['pix']%ln)+buf)
161 def boto(cs
,v
): # still photo blitz on
162 #buf=camera.capture()
165 cs
.write(b
'%s\r\n\r\n' % hdr
['pic'])
167 cs
.write(camera
.capture())
170 #nc=cs.write(b'%s\r\n\r\n' % (hdr['pix']%ln)+buf)
180 if v
==1: flash_light
.on()
181 else: flash_light
.off()
186 setting(cs
,w
,(w
>=1 and w
<=9),camera
.pixformat
,'pixformat')
190 setting(cs
,w
,(w
>0 and w
<18),camera
.framesize
,'framesize')
194 setting(cs
,w
,(w
>9 and w
<64),camera
.quality
,'quality')
198 setting(cs
,w
,(w
>-3 and w
<3),camera
.contrast
,'contrast')
202 setting(cs
,w
,(w
>-3 and w
<3),camera
.saturation
,'saturation')
206 setting(cs
,w
,(w
>-3 and w
<3),camera
.brightness
,'brightness')
210 setting(cs
,w
,(w
>-3 and w
<3),camera
.aelevels
,'aelevels')
214 setting(cs
,w
,(w
>=0 and w
<=1200),camera
.aecvalue
,'aecvalue')
218 setting(cs
,w
,(w
>=0 and w
<=30),camera
.agcgain
,'agcgain')
222 setting(cs
,w
,(w
>=0 and w
<7),camera
.speffect
,'speffect')
226 setting(cs
,w
,(w
>=0 and w
<5),camera
.whitebalance
,'whitebalance')