Skip to content

Conversation

@X9X0
Copy link
Owner

@X9X0 X9X0 commented Nov 28, 2025

Problem

Equipment IDs were being generated using random UUIDs (uuid.uuid4()), causing them to change every time a device reconnected or the server restarted. This resulted in 404 errors when clients tried to access equipment endpoints (like /api/equipment/{equipment_id}/readings) using stale IDs from before the reconnection.

Example scenario:

  1. Device connects → assigned ID ps_61ee82b9
  2. Client stores this ID and makes requests
  3. Device disconnects/reconnects → assigned NEW ID ps_a1b2c3d4
  4. Client requests to /api/equipment/ps_61ee82b9/readings404 Not Found

Solution

Implemented deterministic equipment ID generation using SHA256 hashing of the VISA resource string:

  • Added generate_equipment_id() helper function in server/equipment/base.py
  • Uses SHA256 hash of resource string to create stable, deterministic IDs
  • Updated all equipment classes to use the new helper:
    • BK Precision power supplies
    • Rigol oscilloscopes (MSO2072A, DS1104, DS1102D)
    • Rigol electronic loads (DL3021A)
    • All mock equipment classes

Result: Equipment with resource string ASRL/dev/ttyUSB0::INSTR will always get ID ps_56fdd3df, regardless of reconnections or server restarts.

Changes

  • server/equipment/base.py: Added generate_equipment_id() function
  • server/equipment/bk_power_supply.py: Use deterministic IDs
  • server/equipment/rigol_scope.py: Use deterministic IDs (all 3 scope classes)
  • server/equipment/rigol_electronic_load.py: Use deterministic IDs
  • server/equipment/mock/*.py: Use deterministic IDs for all mock equipment

Testing

Verified that equipment IDs remain stable:

# Connect device
→ {"equipment_id":"ps_56fdd3df","status":"connected"}

# Disconnect and reconnect
→ {"equipment_id":"ps_56fdd3df","status":"connected"}  # SAME ID ✓

…connection

Equipment IDs were being generated using random UUIDs, causing them to change
every time a device reconnected. This resulted in 404 errors when clients tried
to access endpoints like /api/equipment/{equipment_id}/readings with stale IDs.

Changes:
- Added generate_equipment_id() helper function in base.py that creates
  deterministic IDs using SHA256 hash of the resource string
- Updated all equipment classes to use the new helper:
  * BK power supply
  * Rigol scopes (MSO2072A, DS1104, DS1102D)
  * Rigol electronic load (DL3021A)
  * All mock equipment classes
- Equipment IDs now remain stable across reconnections as long as the
  resource string (e.g., TCPIP address or USB identifier) stays the same

This resolves the 404 Client Error when accessing equipment readings after
a device reconnects or the server restarts.

Fixes issue with equipment ID ps_61ee82b9 not found after reconnection.
@X9X0 X9X0 merged commit f482bc7 into main Nov 28, 2025
25 checks passed
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.

3 participants