]>
vault307.fbx.one Git - esp32Cam.git/blob - webcam.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 # webcam.py MVC - This is the controller C of MVC
27 from machine
import reset
28 from time
import sleep
35 from help import Setting
as cam_setting
38 gc
.enable() # Enable automatic garbage collection
44 cs
.close() # flash buffer and close socket
55 elif rl
==2: # '/', '/a'
57 else: # '/a/v' '/a/v/w/....'
67 print('Not an integer value', rqp
[2])
69 #print(pth, site.app[pth])
79 ss
=soc
.socket(soc
.AF_INET
, soc
.SOCK_STREAM
)
80 ss
.setsockopt(soc
.SOL_SOCKET
, soc
.SO_REUSEADDR
, 1)
83 ss
.listen(1) # serve 1 client at a time
84 print("Start server", p
)
86 print(f
"Try - http://{site.server}/login/{auth.pwd}")
88 print(f
"Try - http://{site.server}")
99 except Exception as e
:
105 except Exception as e
:
106 print(f
"RQ:{ms} EX:{e}")
111 rv
,ph
=rq
[:2] # GET /path
115 elif auth
.ip
==ca
[0]: # authenticated client
118 elif ph
.find('login/')>=0: # do login
123 # Unauthorized otherwise
127 # set camera configuration
128 K
.configure(camera
, K
.ai_thinker
) # AI-Thinker PINs map - no need (default)
129 #camera.conf(K.XCLK_MHZ, 16) # 16Mhz xclk rate
130 camera
.conf(K
.XCLK_MHZ
, 14) # 14Mhz xclk rate
131 #camera.conf(K.XCLK_MHZ, 13) # 14Mhz xclk rate
132 #camera.conf(K.XCLK_MHZ, 12) # 12Mhz xclk rate - to reduce "cam_hal: EV-EOF-OVF"
134 # wait for camera ready
137 print("Camera ready?: ", cam
)
145 print("Camera ready")
146 # wait for wifi ready
151 if w
.wlan
.isconnected(): break
152 else: print("WIFI not ready. Wait...");sleep(2)
154 print("WIFI not ready. Can't continue!")
159 #auth.on=False # False: no authentication needed
164 print(f
'PWD: {auth.pwd}')
166 # set preffered camera setting
167 camera
.framesize(10) # frame size 800X600 (1.33 espect ratio)
168 #camera.framesize(11)
169 #camera.framesize(12)
173 camera
.contrast(2) # increase contrast
175 camera
.speffect(2) # jpeg grayscale
177 cam_setting
['framesize']=10
178 cam_setting
['quality']=5
179 cam_setting
['contrast']=0
180 cam_setting
['speffect']=2
181 cam_setting
['brightness']=3
183 site
.ip
=w
.wlan
.ifconfig()[0]
186 server((80,)) # port 80