volttron set_multiple_points 执行器代理 rpc 调用

volttron set_multiple_points actuator agent rpc call

我可以得到有关如何使用执行器代理的提示吗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,以及一个 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

我可以得到有关 set_multiple_pointsrpc 调用的提示吗?

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

result = self.vip.rpc.call(
    'platform.actuator', 'set_multiple_points', devices, point_topic, self.change_setpoint).get(
    timeout=4)

关于如何 revert_multiple 点回的任何提示也非常感谢。例如,如果计时器到期 (gevent.sleep()),我如何将所有点恢复到先前的值?

set_multiple_points RPC 调用需要一个 requester_id 字符串和一个元组列表,用于定义主题对值到集的组合 (topic_values)。

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

# 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'      

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

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)

现在我们可以在预定的时间内发送我们的 set_multiple_points 请求 - 在接下来的 10 秒内。

# start by creating our topic_values
topic_values = []

for device in device_map.values();
   topic = '/'.join([building_topic, device])
   # swap get_value_for_device with your logic
   value = self.get_value_for_device(device)
   # create a (topic, value) tuple and add it to our topic values
   topic_values.append((topic, value,))

# now we can send our set_multiple_points request, use the basic form with our additional params
result = self.vip.rpc.call('platform.actuator', 'set_multiple_points', self.core.identity, topic_values).get(timeout=3)

# TODO: handle the response here

要还原一个点,请按照上述示例为点创建一个计划,但对于单个点,然后将 RPC 请求发送到 'revert_point' 方法的执行器。这需要您在驱动程序的注册表配置中设置默认值。

response = self.vip.rpc.call('platform.actuator', 'revert_point', self.core.identity, '/'.join([building_topic, device], point_name).get(timeout=3)