-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·43 lines (37 loc) · 1.26 KB
/
Copy pathmain.py
File metadata and controls
executable file
·43 lines (37 loc) · 1.26 KB
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
43
import logging
from json import loads as load_json, dumps as dump_json
from pathlib import Path
import picamera
from create_logger import create_logger
from picam import NetworkPiCam
logger = create_logger(name=__name__, level=logging.DEBUG)
SETTINGS_PATH = Path.cwd() / "settings.json"
defaults = {
"camera": {
"name": "picam",
"port": 7896
},
"pan_tilt": {
"enable": True
}
}
logger.debug(f"Loading settings from {SETTINGS_PATH}")
if not SETTINGS_PATH.exists():
logger.warning("Settings file does not exist, creating!")
SETTINGS_PATH.write_text(dump_json(defaults, indent=4))
settings = {**defaults, **load_json(SETTINGS_PATH.read_text())}
try:
with picamera.PiCamera() as camera:
camera.resolution = (720, 480)
cam = NetworkPiCam(camera, settings["camera"]["name"],
settings["camera"]["port"],
settings["pan_tilt"]["enable"])
logger.debug("Attempting to connect")
while not cam.connect(timeout=3):
pass
logger.info("Streaming images")
while cam.is_connected:
cam.send_image()
cam.service_settings()
finally:
logger.warning("Disconnecting")