Skip to content

Commit

Permalink
Cleanup from rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
craig8 committed Oct 19, 2023
1 parent d63ebe5 commit 77ff786
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 259 deletions.
32 changes: 13 additions & 19 deletions scripts/pycharm-launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,15 @@
dest="silence",
nargs="?",
help="Silence the help message.")
parser.add_argument(
"-n",
"--no-config",
action="store_true",
help="Don't include the default config in the agent directory.")
parser.add_argument("-n",
"--no-config",
action="store_true",
help="Don't include the default config in the agent directory.")
parsed = parser.parse_args()

mod_name = [os.path.basename(parsed.agent)]
if not os.path.isfile(parsed.agent):
sys.stdout.write("Passed argument must be a python file! {}".format(
parsed.agent))
sys.stdout.write("Passed argument must be a python file! {}".format(parsed.agent))
sys.exit()

abspath = os.path.abspath(os.path.join(parsed.agent, os.pardir))
Expand Down Expand Up @@ -86,9 +84,8 @@ def write_required_statement(out=sys.stderr):
path_found = os.path.join(abspath, cfg)
break
if not path_found:
sys.stderr.write(
'AGENT_CONFIG variable not set. Either set it or '
'put a config file in the root of the agent dir.')
sys.stderr.write('AGENT_CONFIG variable not set. Either set it or '
'put a config file in the root of the agent dir.')
sys.exit()
os.environ['AGENT_CONFIG'] = path_found

Expand Down Expand Up @@ -125,8 +122,7 @@ def write_required_statement(out=sys.stderr):
universal_newlines=True,
stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
sys.stderr.write("Couldn't get key pair for identity: {}\n".format(
agent_identity))
sys.stderr.write("Couldn't get key pair for identity: {}\n".format(agent_identity))
sys.stderr.write("Call was:\n\tvctl auth keypair\n")
sys.stderr.write("Output of command: {}".format(e.output))
sys.stderr.write("Your environment might not be setup correctly!")
Expand All @@ -142,21 +138,19 @@ def write_required_statement(out=sys.stderr):
pubkey = json_obj['public']
try:
params = [
'vctl', 'auth', 'add', '--credentials', "{}".format(pubkey),
'--user_id', agent_identity, '--capabilities',
"edit_config_store", '--comments',
'vctl', 'auth', 'add', '--credentials', "{}".format(pubkey), '--user_id',
agent_identity, '--capabilities', "edit_config_store", '--comments',
"Added from pycharm-launch.py script."
]
print(" ".join(params))
output = subprocess.check_output(params,
env=os.environ.copy(),
universal_newlines=True)
except subprocess.CalledProcessError as e:
sys.stderr.write(str(e))
sys.stderr.write("Command returned following output: {}".format(
e.output))
sys.stderr.write("Command returned following output: {}".format(e.output))
shutil.rmtree(new_dir)
sys.stderr.write(
"Couldn't authenticate agent id: {}\n".format(agent_identity))
sys.stderr.write("Couldn't authenticate agent id: {}\n".format(agent_identity))
sys.stderr.write("Call was: {}\n".format(params))
sys.stderr.write("Your environment might not be setup correctly!")
write_required_statement()
Expand Down
112 changes: 0 additions & 112 deletions services/core/IEEE_2030_5/AGENT_DEMO.md

This file was deleted.

71 changes: 34 additions & 37 deletions services/core/IEEE_2030_5/demo/inverter_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
import pvlib
import yaml
from volttron.platform.agent.utils import format_timestamp, get_aware_utc_now

from volttron.platform.vip.agent import Agent
from volttron.platform.vip.agent.subsystems.rpc import RPC
from volttron.platform.vip.agent.utils import build_agent

_log = logging.getLogger(__name__)


class MyInverterAgent(Agent):

def __init__(self, **kwargs):
Expand All @@ -33,7 +35,7 @@ def set_point(self, point, value):
@RPC.export
def get_point(self, point):
return self._points.get(point)

def get_all_points(self):
return self._points.keys()

Expand Down Expand Up @@ -84,21 +86,22 @@ def run_inverter(timesteps=50, pf=0.99, latitude=32, longitude=-111.0) -> Genera
# print(
# f"p_ac = {p_ac}, s_ac = {s_ac}, q_ac= {q_ac}, PF = {PF}, v_ac = {v_ac}, i_ac = {i_ac}"
# )
results = dict(PF=PF,
INV_REAL_PWR=p_ac,
INV_REAC_PWR=q_ac,
#v_mp=dc['v_mp'],
#p_mp=dc['p_mp'],
#i_x=dc['i_x'],
#i_xx=dc['i_xx'],
#v_oc=dc['v_oc'],
#i_sc=dc['i_sc'],
s_ac=p_ac,
#v_ac=v_ac,
BAT_SOC=int(v_ac/p_ac),
#i_ac=i_ac,
target_p=p_ac,
INV_OP_STATUS_MODE=3)
results = dict(
PF=PF,
INV_REAL_PWR=p_ac,
INV_REAC_PWR=q_ac,
#v_mp=dc['v_mp'],
#p_mp=dc['p_mp'],
#i_x=dc['i_x'],
#i_xx=dc['i_xx'],
#v_oc=dc['v_oc'],
#i_sc=dc['i_sc'],
s_ac=p_ac,
#v_ac=v_ac,
BAT_SOC=int(v_ac / p_ac),
#i_ac=i_ac,
target_p=p_ac,
INV_OP_STATUS_MODE=3)
yield results
# single phase circuit calculation

Expand Down Expand Up @@ -186,14 +189,12 @@ def run_inverter(timesteps=50) -> Generator:
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()

parser.add_argument("output_file", help="File to write to when data arrives on the bus")
opts = parser.parse_args()

logging.basicConfig(level=logging.DEBUG,
force=True
)


# parser.add_argument("output_file", help="File to write to when data arrives on the bus")
# opts = parser.parse_args()

logging.basicConfig(level=logging.DEBUG, force=True)

logging.getLogger('volttron.platform.vip.agent.core').setLevel(logging.WARNING)
logging.getLogger('volttron.platform.vip.agent.core').setLevel(logging.WARNING)

Expand All @@ -206,7 +207,7 @@ def run_inverter(timesteps=50) -> Generator:
control_path = Path('inverter.ctl')

from volttron.platform.messaging import headers as t_header

while True:

gen = run_inverter()
Expand All @@ -218,13 +219,13 @@ def run_inverter(timesteps=50) -> Generator:
points = AllPoints()

agent_points = agent.get_all_points()

for k in agent_points:
if k in inv:
points.add(k, inv[k])
else:
points.add(k, agent.get_point(k))

# Loop over points adding them to the allpoints dataclass if
# they are specified. If they have been set on the agent itself
# then use that value instead of the one from the generator.
Expand All @@ -234,22 +235,18 @@ def run_inverter(timesteps=50) -> Generator:
points.add(k, pt_set)
else:
points.add(k, v)

ts = format_timestamp(get_aware_utc_now())
headers = {
t_header.SYNC_TIMESTAMP: ts,
t_header.TIMESTAMP: ts
}


headers = {t_header.SYNC_TIMESTAMP: ts, t_header.TIMESTAMP: ts}

_log.info(f"Publishing {points.points}")
# publish
agent.vip.pubsub.publish(peer="pubsub",
topic=f"{topic_to_publish}",
headers=headers,
message=points.forbus())
with open(Path(opts.output_file), '+a') as fp:
fp.write(json.dumps(dict(headers=headers, message=points.forbus()))+"\n")
# with open(Path(opts.output_file), '+a') as fp:
# fp.write(json.dumps(dict(headers=headers, message=points.forbus())) + "\n")
gevent.sleep(10)

agent.core.stop()
2 changes: 1 addition & 1 deletion services/core/IEEE_2030_5/example.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pin: 12345
log_req_resp: true

# SSL defaults to 443
server_ssl_port: 7443
server_ssl_port: 8443
# http port defaults to none
#server_http_port: 8080
# Number of seconds to poll for new default der settings.
Expand Down
18 changes: 9 additions & 9 deletions services/core/IEEE_2030_5/ieee_2030_5/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from typing import Any, Dict, List

import ieee_2030_5.models as m
from ieee_2030_5 import AllPoints
from ieee_2030_5.client import IEEE2030_5_Client
from . import AllPoints
from .client import IEEE2030_5_Client

try: # for modular
from volttron import utils
Expand Down Expand Up @@ -163,13 +163,13 @@ def __init__(self, config_path: str, **kwargs):
}
self._server_usage_points: m.UsagePointList

self._client = IEEE_2030_5_Client(cafile=self._cacertfile,
server_hostname=self._server_hostname,
keyfile=self._keyfile,
certfile=self._certfile,
server_ssl_port=self._server_ssl_port,
pin=self._pin,
log_req_resp=self._log_req_resp)
self._client = IEEE2030_5_Client(cafile=self._cacertfile,
server_hostname=self._server_hostname,
keyfile=self._keyfile,
certfile=self._certfile,
server_ssl_port=self._server_ssl_port,
pin=self._pin,
log_req_resp=self._log_req_resp)

# Hook events up to the client so that we can send the correct information on to
# the platform driver.
Expand Down
Loading

0 comments on commit 77ff786

Please sign in to comment.