mirror of
https://github.com/dptech-corp/Uni-Lab-OS.git
synced 2026-02-07 07:25:15 +00:00
采用http报送resource
This commit is contained in:
@@ -18,10 +18,22 @@ def register_devices_and_resources(mqtt_client, lab_registry):
|
|||||||
mqtt_client.publish_registry(device_info["id"], device_info, False)
|
mqtt_client.publish_registry(device_info["id"], device_info, False)
|
||||||
logger.debug(f"[UniLab Register] 注册设备: {device_info['id']}")
|
logger.debug(f"[UniLab Register] 注册设备: {device_info['id']}")
|
||||||
|
|
||||||
# 注册资源信息
|
# 注册资源信息 - 使用HTTP方式
|
||||||
|
from unilabos.app.web.client import http_client
|
||||||
|
|
||||||
|
resources_to_register = {}
|
||||||
for resource_info in lab_registry.obtain_registry_resource_info():
|
for resource_info in lab_registry.obtain_registry_resource_info():
|
||||||
mqtt_client.publish_registry(resource_info["id"], resource_info, False)
|
resources_to_register[resource_info["id"]] = resource_info
|
||||||
logger.debug(f"[UniLab Register] 注册资源: {resource_info['id']}")
|
logger.debug(f"[UniLab Register] 准备注册资源: {resource_info['id']}")
|
||||||
|
|
||||||
|
if resources_to_register:
|
||||||
|
start_time = time.time()
|
||||||
|
response = http_client.resource_registry(resources_to_register)
|
||||||
|
cost_time = time.time() - start_time
|
||||||
|
if response.status_code in [200, 201]:
|
||||||
|
logger.info(f"[UniLab Register] 成功通过HTTP注册 {len(resources_to_register)} 个资源 {cost_time}ms")
|
||||||
|
else:
|
||||||
|
logger.error(f"[UniLab Register] HTTP注册资源失败: {response.status_code}, {response.text} {cost_time}ms")
|
||||||
|
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
@@ -53,11 +65,9 @@ def main():
|
|||||||
help="是否补全注册表",
|
help="是否补全注册表",
|
||||||
)
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
load_config_from_file(args.config)
|
||||||
# 构建注册表
|
# 构建注册表
|
||||||
build_registry(args.registry, args.complete_registry)
|
build_registry(args.registry, args.complete_registry)
|
||||||
load_config_from_file(args.config)
|
|
||||||
|
|
||||||
from unilabos.app.mq import mqtt_client
|
from unilabos.app.mq import mqtt_client
|
||||||
|
|
||||||
# 连接mqtt
|
# 连接mqtt
|
||||||
@@ -70,4 +80,4 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -40,8 +40,9 @@ class HTTPClient:
|
|||||||
Returns:
|
Returns:
|
||||||
Response: API响应对象
|
Response: API响应对象
|
||||||
"""
|
"""
|
||||||
|
database_param = 1 if database_process_later else 0
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
f"{self.remote_addr}/lab/resource/edge/batch_create/?database_process_later={1 if database_process_later else 0}",
|
f"{self.remote_addr}/lab/resource/edge/batch_create/?database_process_later={database_param}",
|
||||||
json=resources,
|
json=resources,
|
||||||
headers={"Authorization": f"lab {self.auth}"},
|
headers={"Authorization": f"lab {self.auth}"},
|
||||||
timeout=100,
|
timeout=100,
|
||||||
@@ -149,6 +150,26 @@ class HTTPClient:
|
|||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
def resource_registry(self, registry_data: Dict[str, Any]) -> requests.Response:
|
||||||
|
"""
|
||||||
|
注册资源到服务器
|
||||||
|
|
||||||
|
Args:
|
||||||
|
registry_data: 注册表数据,格式为 {resource_id: resource_info}
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Response: API响应对象
|
||||||
|
"""
|
||||||
|
response = requests.post(
|
||||||
|
f"{self.remote_addr}/lab/registry/",
|
||||||
|
json=registry_data,
|
||||||
|
headers={"Authorization": f"lab {self.auth}"},
|
||||||
|
timeout=30,
|
||||||
|
)
|
||||||
|
if response.status_code not in [200, 201]:
|
||||||
|
logger.error(f"注册资源失败: {response.status_code}, {response.text}")
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
# 创建默认客户端实例
|
# 创建默认客户端实例
|
||||||
http_client = HTTPClient()
|
http_client = HTTPClient()
|
||||||
|
|||||||
@@ -4580,6 +4580,7 @@ virtual_solid_dispenser:
|
|||||||
feedback: {}
|
feedback: {}
|
||||||
goal:
|
goal:
|
||||||
properties: {}
|
properties: {}
|
||||||
|
required: []
|
||||||
type: object
|
type: object
|
||||||
result: {}
|
result: {}
|
||||||
required:
|
required:
|
||||||
@@ -4587,6 +4588,30 @@ virtual_solid_dispenser:
|
|||||||
title: cleanup参数
|
title: cleanup参数
|
||||||
type: object
|
type: object
|
||||||
type: UniLabJsonCommandAsync
|
type: UniLabJsonCommandAsync
|
||||||
|
auto-find_solid_reagent_bottle:
|
||||||
|
feedback: {}
|
||||||
|
goal: {}
|
||||||
|
goal_default:
|
||||||
|
reagent_name: null
|
||||||
|
handles: []
|
||||||
|
result: {}
|
||||||
|
schema:
|
||||||
|
description: ''
|
||||||
|
properties:
|
||||||
|
feedback: {}
|
||||||
|
goal:
|
||||||
|
properties:
|
||||||
|
reagent_name:
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- reagent_name
|
||||||
|
type: object
|
||||||
|
result: {}
|
||||||
|
required:
|
||||||
|
- goal
|
||||||
|
title: find_solid_reagent_bottle参数
|
||||||
|
type: object
|
||||||
|
type: UniLabJsonCommand
|
||||||
auto-initialize:
|
auto-initialize:
|
||||||
feedback: {}
|
feedback: {}
|
||||||
goal: {}
|
goal: {}
|
||||||
@@ -4599,6 +4624,7 @@ virtual_solid_dispenser:
|
|||||||
feedback: {}
|
feedback: {}
|
||||||
goal:
|
goal:
|
||||||
properties: {}
|
properties: {}
|
||||||
|
required: []
|
||||||
type: object
|
type: object
|
||||||
result: {}
|
result: {}
|
||||||
required:
|
required:
|
||||||
@@ -4606,9 +4632,58 @@ virtual_solid_dispenser:
|
|||||||
title: initialize参数
|
title: initialize参数
|
||||||
type: object
|
type: object
|
||||||
type: UniLabJsonCommandAsync
|
type: UniLabJsonCommandAsync
|
||||||
|
auto-parse_mass_string:
|
||||||
|
feedback: {}
|
||||||
|
goal: {}
|
||||||
|
goal_default:
|
||||||
|
mass_str: null
|
||||||
|
handles: []
|
||||||
|
result: {}
|
||||||
|
schema:
|
||||||
|
description: ''
|
||||||
|
properties:
|
||||||
|
feedback: {}
|
||||||
|
goal:
|
||||||
|
properties:
|
||||||
|
mass_str:
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- mass_str
|
||||||
|
type: object
|
||||||
|
result: {}
|
||||||
|
required:
|
||||||
|
- goal
|
||||||
|
title: parse_mass_string参数
|
||||||
|
type: object
|
||||||
|
type: UniLabJsonCommand
|
||||||
|
auto-parse_mol_string:
|
||||||
|
feedback: {}
|
||||||
|
goal: {}
|
||||||
|
goal_default:
|
||||||
|
mol_str: null
|
||||||
|
handles: []
|
||||||
|
result: {}
|
||||||
|
schema:
|
||||||
|
description: ''
|
||||||
|
properties:
|
||||||
|
feedback: {}
|
||||||
|
goal:
|
||||||
|
properties:
|
||||||
|
mol_str:
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- mol_str
|
||||||
|
type: object
|
||||||
|
result: {}
|
||||||
|
required:
|
||||||
|
- goal
|
||||||
|
title: parse_mol_string参数
|
||||||
|
type: object
|
||||||
|
type: UniLabJsonCommand
|
||||||
module: unilabos.devices.virtual.virtual_solid_dispenser:VirtualSolidDispenser
|
module: unilabos.devices.virtual.virtual_solid_dispenser:VirtualSolidDispenser
|
||||||
status_types:
|
status_types:
|
||||||
current_reagent: str
|
current_reagent: str
|
||||||
|
device_info: dict
|
||||||
dispensed_amount: float
|
dispensed_amount: float
|
||||||
status: str
|
status: str
|
||||||
total_operations: int
|
total_operations: int
|
||||||
@@ -4641,18 +4716,14 @@ virtual_solid_dispenser:
|
|||||||
type: object
|
type: object
|
||||||
device_id:
|
device_id:
|
||||||
type: string
|
type: string
|
||||||
max_capacity:
|
|
||||||
default: 100.0
|
|
||||||
type: number
|
|
||||||
precision:
|
|
||||||
default: 0.001
|
|
||||||
type: number
|
|
||||||
required: []
|
required: []
|
||||||
type: object
|
type: object
|
||||||
data:
|
data:
|
||||||
properties:
|
properties:
|
||||||
current_reagent:
|
current_reagent:
|
||||||
type: string
|
type: string
|
||||||
|
device_info:
|
||||||
|
type: object
|
||||||
dispensed_amount:
|
dispensed_amount:
|
||||||
type: number
|
type: number
|
||||||
status:
|
status:
|
||||||
@@ -4664,6 +4735,7 @@ virtual_solid_dispenser:
|
|||||||
- current_reagent
|
- current_reagent
|
||||||
- dispensed_amount
|
- dispensed_amount
|
||||||
- total_operations
|
- total_operations
|
||||||
|
- device_info
|
||||||
type: object
|
type: object
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
virtual_stirrer:
|
virtual_stirrer:
|
||||||
|
|||||||
@@ -474,12 +474,12 @@ workstation:
|
|||||||
goal:
|
goal:
|
||||||
ph_value: ph_value
|
ph_value: ph_value
|
||||||
reagent: reagent
|
reagent: reagent
|
||||||
vessel: vessel
|
settling_time: settling_time
|
||||||
volume: volume
|
|
||||||
stir: stir
|
stir: stir
|
||||||
stir_speed: stir_speed
|
stir_speed: stir_speed
|
||||||
stir_time: stir_time
|
stir_time: stir_time
|
||||||
settling_time: settling_time
|
vessel: vessel
|
||||||
|
volume: volume
|
||||||
goal_default:
|
goal_default:
|
||||||
ph_value: 0.0
|
ph_value: 0.0
|
||||||
reagent: ''
|
reagent: ''
|
||||||
@@ -503,11 +503,6 @@ workstation:
|
|||||||
z: 0.0
|
z: 0.0
|
||||||
sample_id: ''
|
sample_id: ''
|
||||||
type: ''
|
type: ''
|
||||||
volume: 0.0
|
|
||||||
stir: false
|
|
||||||
stir_speed: 300.0
|
|
||||||
stir_time: 60.0
|
|
||||||
settling_time: 30.0
|
|
||||||
handles:
|
handles:
|
||||||
input:
|
input:
|
||||||
- data_key: vessel
|
- data_key: vessel
|
||||||
@@ -622,21 +617,6 @@ workstation:
|
|||||||
- data
|
- data
|
||||||
title: Resource
|
title: Resource
|
||||||
type: object
|
type: object
|
||||||
volume:
|
|
||||||
type: number
|
|
||||||
description: 'Volume of the solution to adjust pH'
|
|
||||||
stir:
|
|
||||||
type: boolean
|
|
||||||
description: "是否启用搅拌"
|
|
||||||
stir_speed:
|
|
||||||
type: number
|
|
||||||
description: "搅拌速度(RPM)"
|
|
||||||
stir_time:
|
|
||||||
type: number
|
|
||||||
description: "搅拌时间(秒)"
|
|
||||||
settling_time:
|
|
||||||
type: number
|
|
||||||
description: "pH平衡时间(秒)"
|
|
||||||
required:
|
required:
|
||||||
- vessel
|
- vessel
|
||||||
- ph_value
|
- ph_value
|
||||||
@@ -2248,7 +2228,7 @@ workstation:
|
|||||||
type: number
|
type: number
|
||||||
required:
|
required:
|
||||||
- vessel
|
- vessel
|
||||||
- #filtrate_vessel
|
- filtrate_vessel
|
||||||
- stir
|
- stir
|
||||||
- stir_speed
|
- stir_speed
|
||||||
- temp
|
- temp
|
||||||
|
|||||||
@@ -127,6 +127,8 @@ class Registry:
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
"category": [],
|
||||||
|
"config_info": [],
|
||||||
"icon": "icon_device.webp",
|
"icon": "icon_device.webp",
|
||||||
"registry_type": "device",
|
"registry_type": "device",
|
||||||
"handles": [],
|
"handles": [],
|
||||||
|
|||||||
Reference in New Issue
Block a user