volttron set_multiple_points 执行器代理 rpc 调用

时间:2021-05-03 19:14:45

标签: volttron

我能否获得有关如何使用执行器代理 set_multiple_points 的提示?

actuator agent code中,我可以看到方法:

def set_multiple_points(self, requester_id, topics_values, **kwargs):
    """RPC method
    Set multiple points on multiple devices. Makes a single
    RPC call to the platform driver per device.
    :param requester_id: Ignored, VIP Identity used internally
    :param topics_values: List of (topic, value) tuples
    :param \*\*kwargs: Any driver specific parameters
    :returns: Dictionary of points to exceptions raised.
              If all points were set successfully an empty
              dictionary will be returned.
    .. warning:: calling without previously scheduling *all* devices
                 and not within the time allotted will raise a LockError
    """

在我正在试验的 CSV 代理驱动程序中,我在 init 中定义了 4 个 devices,以及一个在所有设备上都相同的 point_topic,以及一个 {{1} } 应用于所有设备。

change_setpoint

我能否获得有关 def __init__(self, csv_topic="", **kwargs): # Configure the base agent super(Csvdriveragent, self).__init__(**kwargs) _log.debug("vip_identity: " + self.core.identity) # This agent is for testing purposes, so we'll default our ID self.agent_id = "csv_actuation_agent" # Get the topic that the Driver will publish to from the configuration file devices = {device1:'201201', device2:'201202', device3:'201203', device4:'201204' } self.point_topic = self.topic + "/" + "RmTmpSpt" # This value will be used to send requests to the Driver to set a point on the device with an alternating value self.change_setpoint = 85 rpc 调用的提示?

我知道字典格式的评论状态,这是否在下面关于如何将 rpc 调用放在一起?

set_multiple_points

任何有关如何 revert_multiple 点返回的提示也非常感谢。例如,如果计时器到期 (result = self.vip.rpc.call( 'platform.actuator', 'set_multiple_points', devices, point_topic, self.change_setpoint).get( timeout=4) ),我将如何将所有点恢复到先前的值?

1 个答案:

答案 0 :(得分:1)

# id #name sample_8765 sample_8901 sample_9084 # F1234 6.430 0.000 0.000 # F4657 0.000 6.780 6.780 # X1234 3.440 0.000 9.110 # X1345 4.265 5.330 4.350 RPC 调用需要一个 label 字符串和一个元组列表,这些元组定义主题对到值到集合的组合 (set_multiple_points)。

对执行器的 RPC 调用的基本形式如下:

requester_id

因为我们正在使用设备,所以我们需要知道我们对哪些设备感兴趣,以及它们的主题是什么。

topic_values

在设置一个或多个点之前,要求请求者建立一个发送控制信号的调度周期 - 这是通过创建调度数据结构并将其与一些其他元数据一起发送到执行器来完成的。

# use the agent's VIP connection to make an RPC call to the actuator agent 
result = self.vip.rpc.call('platform.actuator', <RPC exported function>, <args>).get(timeout=<seconds>)

现在我们可以在预定时间段内发送我们的 device_map = { 'device1': '201201', 'device2': '201202', 'device3': '201203', 'device4': '201204', } building_topic = 'campus/building' 请求 - 在接下来的 10 秒内。

schedule_request = []

# create start and end timestamps
_now = get_aware_utc_now()
str_start = format_timestamp(_now)
_end = _now + td(seconds=10)
str_end = format_timestamp(_end)

# wrap the topic and timestamps up in a list and add it to the schedules list
for device in device_map.values():
    topic = '/'.join([building_topic, device])
    schedule_request.append([topic, str_start, str_end])

# send the request to the actuator
result = self.vip.rpc.call('platform.actuator', 'request_new_schedule', self.core.identity, 'my_schedule', 'LOW', schedule_request).get(timeout=3)

要还原一个点,请按照上述示例为该点创建一个计划,但针对单个点,然后向 Actuator 发送 RPC 请求以使用“revert_point”方法。这要求您在驱动程序的注册表配置中设置默认值。

set_multiple_points