Skip to content

Commit

Permalink
Added a test for the weatheragent
Browse files Browse the repository at this point in the history
  • Loading branch information
craig8 committed Oct 16, 2015
1 parent 5e58023 commit 4206762
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions services/core/WeatherAgent/weathertest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Example file using the weather agent.
#
# Requirements
# - A VOLTTRON instance must be started
# - A weatheragnet must be running prior to running this code.
#
# Author: Craig Allwardt

from volttron.platform.vip.agent import Agent
import gevent
from gevent.core import callback


def onmessage(peer, sender, bus, topic, headers, message):
print('received: peer=%r, sender=%r, bus=%r, topic=%r, headers=%r, message=%r' % (
peer, sender, bus, topic, headers, message))

a = Agent()
gevent.spawn(a.core.run).join(0)
a.vip.pubsub.subscribe(peer='pubsub',
prefix='weather/response',
callback=onmessage).get(timeout=5)

a.vip.pubsub.publish(peer='pubsub',
topic='weather/request',
headers={'requesterID': 'agent1'},
message={'zipcode': '99336'}).get(timeout=5)

gevent.sleep(5)
a.core.stop()

0 comments on commit 4206762

Please sign in to comment.