I have an control agent that is listening on the message bus to the BACnet proxy/actuator publish of all of the devices/campus/building/somedevice/all
scraping of all of the BACnet data. Code looks like this below, where I can just filter for zone temperature sensor readings:
def _create_subscriptions(self, topics):
"""
Unsubscribe from all pub/sub topics and create a subscription to a topic in the configuration which triggers
the _handle_publish callback
"""
self.vip.pubsub.unsubscribe("pubsub", None, None)
for topic in topics:
_log.debug(f'*** [Roller Agent INFO] *** - _create_subscriptions {topic}')
self.vip.pubsub.subscribe(peer='pubsub',
prefix=topic,
callback=self._handle_publish)
def _handle_publish(self, peer, sender, bus, topic, headers, message):
"""
When we recieve an update from our all publish subscription, log something so we can see that we are
successfully scraping CSV points with the Platform Driver
:param peer: unused
:param sender: unused
:param bus: unused
:param topic: unused
:param headers: unused
:param message: "All" messaged published by the Platform Driver for the CSV Driver containing values for all
registers on the device
"""
topic = topic.strip('/all')
_log.debug(f"*** [Handle Pub Sub INFO] *** topic_formatted {topic}")
for point,sensor_reading in message[0].items():
if point == 'ZN-T' or point == 'Space Temperature Local':
_log.debug(f"*** [Handle Pub Sub INFO] *** Found a Zone Temp Published {point} that is {sensor_reading}")
if point == 'Space Temperature Local': # Fix Trane controller data that comes through in Metric
sensor_reading = (9/5) * sensor_reading + 32
self.znt_values[topic] = float(sensor_reading)
_log.debug(f"*** [Handle Pub Sub INFO] *** self.znt_values {self.znt_values}")
Is there any chance I could get a tip on how this agent could listen on the message bus for another agent publishing data? Sorry I bet this is super basic material, still learning :)
I have another agent that checks an API where on the log files/message bus this shows up:
(setteroccvavagent-0.1 922213) __main__ DEBUG: *** [SIG CHECKER Agent INFO] *** - signal_payload from Flask App is 0!
How do I get this info of the setteroccvavagent
signal payload? Would I need to write a separate method and assign a topic to the setteroccvavagent
?
Any tips appreciated what the code would look like.
For what its worth this is the code for my setteroccagent
that calls the API:
AtCore.receiver("onstart")
def onstart(self, sender, **kwargs):
self.core.periodic(60, self.dr_signal_checker)
_log.debug(f'*** [SIG CHECKER Agent INFO] *** - AGENT ONSTART CALLED SUCCESS!')
def dr_signal_checker(self):
try:
requests = (grequests.get(self.url),)
result, = grequests.map(requests)
contents = result.json()
_log.debug(f"Flask App API contents: {contents}")
_log.debug(f"Flask App API SUCCESS")
sig_payload = contents["current_state"]
except Exception as error:
_log.debug(f"*** [SIG CHECKER Agent INFO] *** - Error trying Flask App API {error}")
_log.debug(f"*** [SIG CHECKER Agent INFO] *** - RESORTING TO NO DEMAND RESPONSE EVENT")
sig_payload = 0
_log.debug(f'*** [SIG CHECKER Agent INFO] *** - signal_payload from Flask App is {sig_payload}!')