fix: Generate deterministic equipment IDs to prevent 404 errors on reconnection #99
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
ps_61ee82b9ps_a1b2c3d4/api/equipment/ps_61ee82b9/readings→ 404 Not FoundSolution
Implemented deterministic equipment ID generation using SHA256 hashing of the VISA resource string:
generate_equipment_id()helper function inserver/equipment/base.pyResult: Equipment with resource string
ASRL/dev/ttyUSB0::INSTRwill always get IDps_56fdd3df, regardless of reconnections or server restarts.Changes
server/equipment/base.py: Addedgenerate_equipment_id()functionserver/equipment/bk_power_supply.py: Use deterministic IDsserver/equipment/rigol_scope.py: Use deterministic IDs (all 3 scope classes)server/equipment/rigol_electronic_load.py: Use deterministic IDsserver/equipment/mock/*.py: Use deterministic IDs for all mock equipmentTesting
Verified that equipment IDs remain stable: