- Added support for limiting concurrent transcoding operations in the media API to prevent resource exhaustion. - Implemented functions to retrieve video duration and bitrate using ffprobe for improved streaming performance. - Enhanced the generate_transcoded_stream function to handle HTTP range requests, allowing for more efficient video playback. - Updated VideoModal component to disable fluid and responsive modes, ensuring proper container boundaries during video playback. - Improved logging throughout the transcoding process for better error tracking and debugging.
10 KiB
Session Summary: MQTT Auto-Recording Debugging & Theme Implementation
Overview
This session focused on debugging MQTT-triggered auto-recording functionality and implementing dark/light theme toggle in the management dashboard. Multiple issues were identified and resolved related to camera recording, MQTT message handling, and UI theming.
Major Tasks Completed
1. Scheduling Module Extraction (Previous Session)
- Extracted the Scheduling module into a separate microfrontend (
scheduling-remote) - Configured Module Federation for the new microfrontend
- Updated
docker-compose.ymlto include the new service
2. Dark/Light Theme Toggle Implementation
- Created
useThemehook (management-dashboard-web-app/src/hooks/useTheme.ts) - Added theme toggle button to
TopNavbar.tsx - Applied dark mode classes across multiple components:
DashboardLayout.tsx- Main content areaLogin.tsx- Login page backgroundDataEntry.tsx- Widgets, text, bordersUserManagement.tsx- Stats cards, tables, formsExperimentPhases.tsx- Phase cards, badgesindex.css- Body backgroundindex.html- Inline script to prevent FOUC (Flash of Unstyled Content)
3. MQTT Auto-Recording Debugging
Issues Identified:
- Manual recording buttons not working - "Record" buttons for cameras couldn't start manual recording
- Automatic recording unavailable - MQTT-triggered auto-recording wasn't functioning
- Camera2 initialization error - Error code 32774 when initializing camera2
- Button visibility issues - "Restart Camera" and "Stop Streaming" buttons appeared transparent
Fixes Applied:
A. Transparent Buttons Fix
File: vision-system-remote/src/components/CameraCard.tsx
- Added inline
styleattributes to "Restart Camera" and "Stop Streaming" buttons - Explicitly set
backgroundColorandcolorto prevent transparency
B. Camera Initialization Error (32774)
File: camera-management-api/usda_vision_system/camera/monitor.py
- Enhanced error handling for camera initialization error code 32774
- Added logic to check if camera is already in use by existing recorder/streamer
- If error 32774 occurs, camera is marked as "available" with warning instead of failing completely
- Provides better diagnostics for cameras that might be in use by another process
C. StandaloneAutoRecorder Integration
File: camera-management-api/usda_vision_system/recording/standalone_auto_recorder.py
- Problem:
StandaloneAutoRecorderwas creating its own MQTT client and camera recorders, causing conflicts - Solution:
- Modified constructor to accept
camera_manager,state_manager, andevent_systeminstances - Removed internal MQTT client setup when using shared instances
- Now subscribes to
EventType.MACHINE_STATE_CHANGEDevents from the event system - Uses
camera_manager.manual_start_recording()andmanual_stop_recording()instead of creating its own recorders - Added comprehensive logging for event reception and recording operations
- Modified constructor to accept
File: camera-management-api/usda_vision_system/main.py
- Updated
USDAVisionSystemconstructor to passcamera_manager,state_manager, andevent_systemtoStandaloneAutoRecorder
D. Missing Constants Import
File: camera-management-api/usda_vision_system/camera/recorder.py
- Error:
NameError: name 'CAMERA_TEST_CAPTURE_TIMEOUT' is not defined - Fix: Added missing imports:
CAMERA_GET_BUFFER_TIMEOUTCAMERA_INIT_TIMEOUTCAMERA_TEST_CAPTURE_TIMEOUTDEFAULT_VIDEO_FPSBRIEF_PAUSE_SLEEP- All imported from
.constants
E. Recording Routes Enhancement
File: camera-management-api/usda_vision_system/api/routes/recording_routes.py
- Made
StartRecordingRequestparameter optional forstart_recordingendpoint - Added logic to create default
StartRecordingRequestifrequestisNone - Added INFO-level logging for recording attempts and success/failure
- Improved error messages for
manual_start_recordingfailures
F. MQTT Logging Improvements
Files:
camera-management-api/usda_vision_system/mqtt/client.pycamera-management-api/usda_vision_system/mqtt/handlers.py
Changes:
- Changed MQTT message logging from
DEBUGtoINFOlevel for visibility in production - Added detailed logging for:
- Message reception:
📡 MQTT MESSAGE RECEIVED - Topic: {topic}, Payload: '{payload}' - Message processing:
📡 Processing MQTT message for machine '{machine_name}': '{payload}' - Payload normalization:
📡 Normalized payload '{payload}' -> '{normalized_payload}' - Event publishing:
📡 Publishing MACHINE_STATE_CHANGED event - Connection status:
🔗 MQTT CONNECTEDwith broker details - Subscription confirmation:
📋 MQTT subscribed to {count} topics
- Message reception:
G. MQTT Test Script
File: camera-management-api/test_mqtt_simple.py (NEW)
- Created standalone MQTT test script to verify connectivity and message reception
- Connects to MQTT broker and subscribes to configured topics
- Displays received messages in real-time with timestamps
- Validates payload format (on/off/true/false/1/0)
- Shows connection statistics
4. Configuration Updates
File: camera-management-api/config.json
- Confirmed
log_levelis set toINFO auto_recording_enabledis set totrue
Key Files Modified
Frontend (React/TypeScript)
management-dashboard-web-app/src/hooks/useTheme.ts- NEWmanagement-dashboard-web-app/src/components/TopNavbar.tsxmanagement-dashboard-web-app/src/components/DashboardLayout.tsxmanagement-dashboard-web-app/src/components/Login.tsxmanagement-dashboard-web-app/src/components/DataEntry.tsxmanagement-dashboard-web-app/src/components/UserManagement.tsxmanagement-dashboard-web-app/src/components/ExperimentPhases.tsxmanagement-dashboard-web-app/src/index.cssmanagement-dashboard-web-app/index.htmlvision-system-remote/src/components/CameraCard.tsx
Backend (Python/FastAPI)
camera-management-api/usda_vision_system/recording/standalone_auto_recorder.pycamera-management-api/usda_vision_system/main.pycamera-management-api/usda_vision_system/camera/recorder.pycamera-management-api/usda_vision_system/camera/monitor.pycamera-management-api/usda_vision_system/api/routes/recording_routes.pycamera-management-api/usda_vision_system/mqtt/client.pycamera-management-api/usda_vision_system/mqtt/handlers.pycamera-management-api/test_mqtt_simple.py- NEW
Current Status
✅ Completed
- Dark/light theme toggle fully implemented
- Transparent buttons fixed
- Camera initialization error handling improved
StandaloneAutoRecorderproperly integrated with shared instances- Missing constants imported
- Recording routes enhanced with better logging
- MQTT logging improved to INFO level
- MQTT test script created
🔄 Testing Needed
- MQTT Auto-Recording: Needs verification that MQTT messages trigger recording
- Test script available:
camera-management-api/test_mqtt_simple.py - Monitor logs for MQTT message flow:
docker compose logs api -f | grep -i "mqtt\|📡" - Check MQTT status:
curl http://localhost:8000/mqtt/status - Check recent events:
curl http://localhost:8000/mqtt/events?limit=10
- Test script available:
📋 Expected MQTT Message Flow
When a machine turns on/off, the following should appear in logs:
📡 MQTT MESSAGE RECEIVED- Message received from broker📡 Processing MQTT message- Message being processed📡 Normalized payload- Payload normalization✅ Published MACHINE_STATE_CHANGED event- Event published to event system📡 AUTO-RECORDER: Received MACHINE_STATE_CHANGED event- Auto-recorder received event✅ Started auto-recording- Recording started
MQTT Configuration
From config.json:
{
"mqtt": {
"broker_host": "192.168.1.110",
"broker_port": 1883,
"username": null,
"password": null,
"topics": {
"vibratory_conveyor": "vision/vibratory_conveyor/state",
"blower_separator": "vision/blower_separator/state"
}
}
}
Machine-to-Camera Mapping (from standalone_auto_recorder.py):
vibratory_conveyor→camera2blower_separator→camera1
Testing Commands
Test MQTT Connectivity
# Option 1: Standalone test script
docker compose exec api python test_mqtt_simple.py
# Option 2: Check MQTT status via API
curl -s http://localhost:8000/mqtt/status | python -m json.tool
# Option 3: Monitor API logs for MQTT messages
docker compose logs api -f | grep -i "mqtt\|📡"
# Option 4: Check recent MQTT events
curl -s http://localhost:8000/mqtt/events?limit=10 | python -m json.tool
Restart API Container
docker compose restart api
Architecture Notes
Event Flow for Auto-Recording
- MQTT Message Received →
MQTTClient._on_message() - Message Processed →
MQTTMessageHandler.handle_message() - State Updated →
StateManager.update_machine_state() - Event Published →
EventSystem.publish(EventType.MACHINE_STATE_CHANGED) - Event Received →
StandaloneAutoRecorder._on_machine_state_changed() - Recording Started/Stopped →
CameraManager.manual_start_recording()/manual_stop_recording()
Key Components
- MQTTClient: Connects to MQTT broker, subscribes to topics, receives messages
- MQTTMessageHandler: Processes MQTT messages, normalizes payloads, updates state
- EventSystem: Publishes/subscribes to internal events
- StandaloneAutoRecorder: Subscribes to
MACHINE_STATE_CHANGEDevents, triggers recording - CameraManager: Manages camera operations including recording
Notes for Future Sessions
-
MQTT Testing: If auto-recording still doesn't work, verify:
- MQTT broker is reachable from API container
- Topics match exactly (case-sensitive)
- Messages are being published to correct topics
- Payload format is recognized (on/off/true/false/1/0)
-
Camera Initialization: Error 32774 typically means camera is in use. The system now handles this gracefully but may need investigation if cameras are not accessible.
-
Theme Persistence: Theme preference is stored in
localStorageand persists across sessions. -
Log Level: Currently set to
INFOinconfig.jsonfor comprehensive event tracking.
Session Date
Session completed with focus on MQTT debugging and enhanced logging for troubleshooting auto-recording functionality.