Skip to content

Conversation

@coelacant1
Copy link
Owner

Pull Request

Added

  • On-Demand MQTT Monitoring
    • New endpoint: POST /v1/iot-service/api/user/device/realtime/start - Start 2-minute MQTT monitoring session
    • New endpoint: GET /v1/iot-service/api/user/device/realtime?device_id={id} - Get cached real-time MQTT data
    • New endpoint: GET /admin/mqtt - View active MQTT session status
    • Background cleanup thread automatically disconnects expired sessions
    • Session-based model prevents resource exhaustion
    • Only POST endpoint allowed in strict mode (doesn't modify printer state)

Changed

  • Proxy Server (servers/proxy.py):

    • Changed from automatic monitoring of all devices to on-demand session model
    • Added mqtt_sessions dict to track active monitoring sessions
    • Added configurable session duration (120 seconds) and cleanup interval (30 seconds)
    • Updated /health endpoint to show active MQTT sessions count
    • Modified strict mode check to allow MQTT session start POST endpoint
  • Test Suite (tests/manual/test_proxy_server.py):

    • Updated MQTT tests to use on-demand session workflow
    • Increased MQTT wait time from 3 to 5 seconds for better data retrieval
    • Added detailed status output for MQTT session creation and data retrieval

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Test addition or update

Testing

  • Tested locally
  • Added/updated unit tests
  • All existing tests pass

Test Configuration:

  • Python version: 3.14
  • Operating System: Arch

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

### Added - 2025-10-29
- **On-Demand MQTT Monitoring**
  - New endpoint: `POST /v1/iot-service/api/user/device/realtime/start` - Start 2-minute MQTT monitoring session
  - New endpoint: `GET /v1/iot-service/api/user/device/realtime?device_id={id}` - Get cached real-time MQTT data
  - New endpoint: `GET /admin/mqtt` - View active MQTT session status
  - Background cleanup thread automatically disconnects expired sessions
  - Session-based model prevents resource exhaustion
  - Only POST endpoint allowed in strict mode (doesn't modify printer state)

### Changed
- **Proxy Server (servers/proxy.py)**:
  - Changed from automatic monitoring of all devices to on-demand session model
  - Added `mqtt_sessions` dict to track active monitoring sessions
  - Added configurable session duration (120 seconds) and cleanup interval (30 seconds)
  - Updated `/health` endpoint to show active MQTT sessions count
  - Modified strict mode check to allow MQTT session start POST endpoint

- **Test Suite (tests/manual/test_proxy_server.py)**:
  - Updated MQTT tests to use on-demand session workflow
  - Increased MQTT wait time from 3 to 5 seconds for better data retrieval
  - Added detailed status output for MQTT session creation and data retrieval
@coelacant1 coelacant1 self-assigned this Oct 29, 2025
@coelacant1 coelacant1 linked an issue Oct 29, 2025 that may be closed by this pull request
@coelacant1 coelacant1 merged commit 929b249 into main Oct 29, 2025
5 checks passed
coelacant1 added a commit that referenced this pull request Oct 29, 2025
V1.0.5 - Added MQTT monitoring to proxy server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Add MQTT to Proxy server

2 participants