This complete feature gives you a production-ready QR rotation system for digital signage with analytics tracking, admin management, and easy integration with any open-source signage platform.
# Rotate based on time to simulate display rotation # In production, track which one is currently showing current_time = datetime.utcnow() seconds_in_day = (current_time - current_time.replace(hour=0, minute=0, second=0)).seconds index = (seconds_in_day // 30) % len(active_qrs) # Rotate every 30 seconds current_qr = active_qrs[index] open source digital signage
return jsonify( 'id': current_qr.id, 'name': current_qr.name, 'url': current_qr.url, 'qr_image': qr_base64, 'description': current_qr.description, 'duration': current_qr.display_duration ) @app.route('/api/track-scan', methods=['POST']) def track_scan(): data = request.json qr_id = data.get('qr_id') This complete feature gives you a production-ready QR
Use the "Web Page" asset type pointing to your display URL Installation & Setup # 1. Clone or create files mkdir qr-signage cd qr-signage 2. Install dependencies pip install -r requirements.txt 3. Initialize database python >>> from qr_signage_api import db, app >>> with app.app_context(): ... db.create_all() >>> exit() 4. Run API server python qr_signage_api.py 5. Access endpoints: - Display: http://localhost:5000/static/qr_display.html - Admin: http://localhost:5000/static/admin_dashboard.html - API: http://localhost:5000/api/current-qr Install dependencies pip install -r requirements
# requirements.txt Flask==2.3.0 flask-cors==4.0.0 flask-sqlalchemy==3.0.5 qrcode==7.4.2 Pillow==10.0.0 For Xibo: Use the HTML package with iframe embedding
with app.app_context(): db.create_all() def generate_qr_base64(url): qr = qrcode.QRCode(version=1, box_size=10, border=4) qr.add_data(url) qr.make(fit=True) img = qr.make_image(fill_color="black", back_color="white") buffered = BytesIO() img.save(buffered, format="PNG") return base64.b64encode(buffered.getvalue()).decode() Get current active QR for display @app.route('/api/current-qr', methods=['GET']) def get_current_qr(): active_qrs = QRContent.query.filter_by(is_active=True).all()
return jsonify( 'total_scans': total_scans, 'scans_last_hour': scans_last_hour, 'qr_performance': ['name': name, 'scans': count for name, count in qr_performance] ) @app.route('/api/qr-content', methods=['POST']) def add_qr_content(): data = request.json qr = QRContent( name=data['name'], url=data['url'], description=data.get('description'), display_duration=data.get('display_duration', 30) ) db.session.add(qr) db.session.commit() return jsonify('id': qr.id, 'message': 'QR content added')