diff options
Diffstat (limited to 'webui/website')
-rw-r--r-- | webui/website/__init__.py | 7 | ||||
-rw-r--r-- | webui/website/auth.py | 15 | ||||
-rw-r--r-- | webui/website/models.py | 0 | ||||
-rw-r--r-- | webui/website/templates/html.html | 44 | ||||
-rw-r--r-- | webui/website/templates/live.html | 5 | ||||
-rw-r--r-- | webui/website/views.py | 47 |
6 files changed, 52 insertions, 66 deletions
diff --git a/webui/website/__init__.py b/webui/website/__init__.py index 4ca4c4b..2af8e41 100644 --- a/webui/website/__init__.py +++ b/webui/website/__init__.py @@ -4,10 +4,9 @@ def create_app(): app = Flask(__name__) app.config['SECRET_KEY'] = 'fdbcawejhfbwef' - from .views import views - from .auth import auth + from .views import views,streaming app.register_blueprint(views, url_prefix='/') - app.register_blueprint(auth, url_prefix='/') + app.register_blueprint(streaming, url_prefix='/') - return app
\ No newline at end of file + return app diff --git a/webui/website/auth.py b/webui/website/auth.py deleted file mode 100644 index c44b421..0000000 --- a/webui/website/auth.py +++ /dev/null @@ -1,15 +0,0 @@ -from flask import Blueprint, render_template - -auth = Blueprint('auth', __name__) - -@auth.route('/login') -def login(): - return render_template("404.html") - -@auth.route('/logout') -def logout(): - return render_template("404.html") - -@auth.route('/signup') -def signup(): - return render_template("404.html")
\ No newline at end of file diff --git a/webui/website/models.py b/webui/website/models.py deleted file mode 100644 index e69de29..0000000 --- a/webui/website/models.py +++ /dev/null diff --git a/webui/website/templates/html.html b/webui/website/templates/html.html deleted file mode 100644 index 8387ebb..0000000 --- a/webui/website/templates/html.html +++ /dev/null @@ -1,44 +0,0 @@ -<!DOCTYPE html>
-<html lang="en">
-<head>
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <link rel="stylesheet" href="css.css">
-</head>
-<body>
- <div class="nav">
- <input type="checkbox" id="nav-check">
- <div class="nav-header">
- <div class="nav-title">
- MysteryCode
- </div>
- </div>
- <div class="nav-btn">
- <label for="nav-check">
- <span></span>
- <span></span>
- <span></span>
- </label>
- </div>
-
- <div class="nav-links">
- <ul>
- <li><a href="#" target="_blank">Home</a></li>
- <li><a href="#" target="_blank">About</a></li>
- <li><a href="#" target="_blank">Services</a></li>
- <li><a href="#" target="_blank">Portfolio</a></li>
- <li><a href="#" target="_blank">Contact</a></li>
- <a class="icon">
- <i class="fa fa-twitter"></i>
- <i class="fa fa-linkedin"></i>
- <i class="fa fa-youtube"></i>
-
- </a>
- </ul>
- </div>
- </div>
-</body>
-</html>
\ No newline at end of file diff --git a/webui/website/templates/live.html b/webui/website/templates/live.html index 5d7d62f..bd71851 100644 --- a/webui/website/templates/live.html +++ b/webui/website/templates/live.html @@ -3,7 +3,8 @@ {% block content %} <body id="page"> <div id="spotlight" class="animated fadeIn"> - <h1>Hi<h1> + <img src="/stream" width="640" height="480" /> + <h1>Live-Feed</h1> </div> -{% endblock %}
\ No newline at end of file +{% endblock %} diff --git a/webui/website/views.py b/webui/website/views.py index 47a02f5..3523adf 100644 --- a/webui/website/views.py +++ b/webui/website/views.py @@ -1,8 +1,52 @@ -from flask import Blueprint, render_template +from flask import Blueprint, render_template, Response + +import io +import logging +import socketserver +from http import server +from threading import Condition + +from picamera2 import Picamera2 +from picamera2.encoders import JpegEncoder +from picamera2.outputs import FileOutput + views = Blueprint('views', __name__) +streaming = Blueprint('streaming', __name__) + +@streaming.route('/stream') +def stream(): + class StreamingOutput(io.BufferedIOBase): + def __init__(self): + self.frame = None + self.condition = Condition() + + def write(self, buf): + with self.condition: + self.frame = buf + self.condition.notify_all() + + def generate(): + try: + while True: + with output.condition: + output.condition.wait() + frame = output.frame + yield (b'--FRAME\r\n' + b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n') + except Exception as e: + logging.warning('Removed streaming client: %s', str(e)) + + output = StreamingOutput() + picam2 = Picamera2() + picam2.configure(picam2.create_video_configuration(main={"size": (640, 480)})) + picam2.start_recording(JpegEncoder(), FileOutput(output)) + + return Response(generate(), mimetype='multipart/x-mixed-replace; boundary=FRAME') + @views.route('/') +@views.route('/index.html') def home(): return render_template("home.html") @@ -10,3 +54,4 @@ def home(): def live(): return render_template("live.html") +views.register_blueprint(streaming, url_prefix='/stream') |