diff --git a/main.py b/main.py index 2e67dc1..5496032 100644 --- a/main.py +++ b/main.py @@ -5,9 +5,12 @@ from flask_socketio import SocketIO from tfluna import TFLuna from bmp180 import BMP180 from mpu6050 import mpu6050 +from picamera2 import Picamera2 +import io +import base64 import random -# Here, we create the neccesary base app. You don't need to worry about this. +# App initalization app = Flask(__name__) socketio = SocketIO(app) @@ -17,6 +20,10 @@ mpu = mpu6050(0x68) tfluna = TFLuna() tfluna.open() tfluna.set_samp_rate(10) +picam2 = Picamera2 +camera_config = picam2.create_preview_configuration(main={"size": (640,480)}) +picam2.configure(camera_config) +picam2.start() # tfl Class to format the getters like the other sensors. class tfl: @@ -70,6 +77,15 @@ def handle_connect(): print('Client connected') socketio.start_background_task(target=background_thread) +@socketio.on('request_image') +def handle_image_request(): + stream = io.BytesIO() + picam2.capture_file(stream, format='jpeg') + stream.seek(0) + b64_image = base64.b64encode(stream.read()).decode('utf-8') + socketio.emit('new_image', {'image_data': b64_image}) + print("Image sent") + # This function is called def main(): # These specific arguments are required to make sure the webserver is hosted in a consistent spot, so don't change them unless you know what you're doing. diff --git a/templates/index.html b/templates/index.html index f283daa..5d60cac 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,25 +5,24 @@
Random Number (lost connection if stopped): Loading...
-Connection Status: Loading...
Barometric Sensor Values
Temperature: Loading...
Pressure: Loading...
Altitude: Loading...
-Accelerometer Sensor Values
Acceleration: Loading...
Gyroscope: Loading...
-Lidar Sensor Values
Distance: Loading...
Strength: Loading...
Temperature: Loading...
+