Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
102 lines (79 loc) · 2.95 KB
/
Copy pathapp.py
File metadata and controls
102 lines (79 loc) · 2.95 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""
BirdsOS - Main Application Entry Point
"""
from flask import Flask, render_template, jsonify
from routes.main_routes import main_bp
from routes.api_routes import api_bp
from routes.system_routes import system_bp
from features.gpio.routes import gpio_bp, sock as gpio_sock
from features.camera.routes import camera_bp
from features.camera.ws_routes import ws_bp, sock as camera_sock
from features.birdcontrol.birdcontrol import BirdControl
import os
import logging
from config.logging import setup_logging
def verify_logging():
"""Verify that all major components have logging configured"""
test_loggers = [
'app',
'features.camera',
'features.gpio',
'features.storage',
'routes.main_routes',
'routes.api_routes',
'routes.system_routes'
]
for logger_name in test_loggers:
logger = logging.getLogger(logger_name)
logger.info(f"Logging verification for {logger_name}")
# Set up logging configuration
setup_logging()
logger = logging.getLogger(__name__)
# Verify logging is working across all components
verify_logging()
def initialize_birdcontrol():
"""Initialize the bird control components"""
# Initialize MotorController
BirdControl()
logger.info("BirdControl initialized")
def create_app():
"""Create and configure the Flask application"""
app:Flask = Flask(__name__)
# Configure app
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'dev-key-please-change')
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB max file size
logger.info("Initializing BirdsOS application")
# Initialize BirdControl
# Initialize WebSocket
gpio_sock.init_app(app, ) # type: ignore
#camera_sock.init_app(app)
initialize_birdcontrol()
# Register blueprints
app.register_blueprint(main_bp)
app.register_blueprint(api_bp, url_prefix='/api/v1')
app.register_blueprint(ws_bp, url_prefix='/ws')
app.register_blueprint(gpio_bp)
app.register_blueprint(camera_bp)
app.register_blueprint(system_bp)
logger.info("All blueprints registered successfully")
# Register error handlers
@app.errorhandler(404)
def page_not_found(e: Exception):
logger.warning(f"404 error: {str(e)}")
return render_template('404.html'), 404
@app.route('/health')
# TODO: Add more comprehensive health checks
def health_check():
"""Simple health check endpoint for setup verification."""
logger.debug("Health check requested")
return jsonify({"status": "healthy"}), 200
return app
# Create the application instance
app = create_app()
if __name__ == '__main__':
# Create necessary directories if they don't exist
os.makedirs('logs', exist_ok=True)
os.makedirs('recordings', exist_ok=True)
logger.info("Starting BirdsOS in development mode")
# Run the application
app.run(host='0.0.0.0', port=5000, debug=True)