-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebuggingServer.py
More file actions
executable file
·46 lines (39 loc) · 1.67 KB
/
DebuggingServer.py
File metadata and controls
executable file
·46 lines (39 loc) · 1.67 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
44
45
46
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import print_function
from datetime import datetime
import threading
import time
from flask import Flask, render_template, send_from_directory
from flask_socketio import SocketIO, emit
class DebuggingServer:
def __init__(self, host: str = "0.0.0.0", port: int = 5000):
self.app = Flask(__name__, static_folder="web/static", template_folder="web")
self.socketio = SocketIO(self.app, async_mode='threading', cors_allowed_origins='*')
self._host = host
self._port = port
self.tag_family = None
self._configure_routes()
def _configure_routes(self):
@self.app.route('/')
def index():
return render_template("Dashboard.html", tag_family=self.tag_family or "(unknown)")
def send_tag_data(self, tag_id: int, tag_dist_feet: float, tag_angle_deg: float, camera_id: int, wanted: bool):
data = {
"id": tag_id,
"distance_ft": tag_dist_feet,
"angle_deg": tag_angle_deg,
"camera_id": camera_id,
"timestamp": datetime.now().isoformat(),
"wanted": wanted
}
self.socketio.emit('tag_update', data)
# print(f"[{datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f %Z")}] tag_update = {repr(data)}")
def run(self):
def _run_server():
@self.socketio.on('connect')
def handle_connect():
print("websocket client connected")
self.socketio.run(self.app, host=self._host, port=self._port, debug=False, allow_unsafe_werkzeug=True)
thread = threading.Thread(target=_run_server, daemon=True)
thread.start()