Skip to content

Commit

Permalink
Added support for new definition of the connection
Browse files Browse the repository at this point in the history
  • Loading branch information
joan-pijpker committed Oct 22, 2024
1 parent 74a9d43 commit d227905
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 21 deletions.
61 changes: 46 additions & 15 deletions configuration/modelling-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ models: # list of models for the energy network
- capacity
- soc_min
scenario_data: 'path/to/file' #path to the scenario data file for the model. This should be optional
method:
type: connect # can be python for local or connect for remote
location: null
connect_ip: 192.168.0.1
connect_port: 5123
connect:
ip: 192.168.0.1
port: 5000
- name: Battery2
type: Battery # models can reuse the same type
inputs:
Expand All @@ -38,11 +36,47 @@ models: # list of models for the energy network
charge_power_max: 100
states:
soc: 0.5 # initial value for the state, optional
method:
type: connect # can be python for local or connect for remote
location: null
connect_ip: 192.168.0.2
connect_port: 5123
connect:
ip: 192.168.0.2
port: 5000
- name: Battery3
type: Battery # models can reuse the same type
inputs:
input1: 0 # input-name: initial value, default value will be used if not defined
outputs:
output1: 0
output2: null
parameters:
charge_power_max: 100
states:
soc: 0.5 # initial value for the state, optional
connect:
port: 5000
- name: Battery4
type: Battery # models can reuse the same type
inputs:
input1: 0 # input-name: initial value, default value will be used if not defined
outputs:
output1: 0
output2: null
parameters:
charge_power_max: 100
states:
soc: 0.5 # initial value for the state, optional
connect:
ip:
port: 5000
- name: Battery5
type: Battery # models can reuse the same type
inputs:
input1: 0 # input-name: initial value, default value will be used if not defined
outputs:
output1: 0
output2: null
parameters:
charge_power_max: 100
states:
soc: 0.5 # initial value for the state, optional
- name: PV1
type: PV
inputs:
Expand All @@ -54,11 +88,8 @@ models: # list of models for the energy network
power_max: 100
states:
initial_soc: 0.5
method:
type: connect # can be python for local or connect for remote
location: null
connect_ip: 192.168.0.3
connect_port: 5123
connect:
ip: 192.168.0.3
connections:
- from: Battery1.output2 # start model, pattern: model_name.output_name/input_name
to: PV1.input1 # end model
Expand Down
21 changes: 15 additions & 6 deletions configuration/parse_yaml.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import yaml

"""
This script reads a yaml file of an illuminator model. It extracts the connection information.
If an IP port is not specified it will default to 5123.
If both IP address and port are known than a line will be prined that can be used in the run.sh file.
The run.sh file is used to start the processes on remote pi's.
"""

# Open and load the YAML file
with open('modelling-example.yaml', 'r') as _file:
data = yaml.safe_load(_file)
Expand All @@ -10,13 +17,15 @@
for model in data['models']:
model_type = model.get('type')

method = model.get('method', {})
method_type = method.get('type')
location = method.get('location')
connect_ip = method.get('connect_ip')
connect_port = method.get('connect_port')
connect = model.get('connect', {})

if connect:
connect_ip = connect.get('ip')
connect_port = connect.get('port')

if not connect_port:
connect_port = 5123

if method_type == 'connect':
if connect_ip and connect_port:
print(f"lxterminal -e ssh illuminator@{connect_ip} '{run_path}run{model_type}.sh {connect_ip} {connect_port} {run_model}'&")

0 comments on commit d227905

Please sign in to comment.