Search code examples
volttron

How do you load a csv stored in the config store from Volttron agent?


I have a CSV/Raw file with series data in it that I would like my agent to read from the config store when it starts.

Steps I am following:

  1. store the config:

    volttron-ctl config store myagent mycsv.csv -c mycsvfile.csv --csv

  2. I can then get the contents:

    volttron-ctl config get myagent my.csv

  3. In my agent config I specify:

{ "mycsv": "config://myagent/mycsv.csv" }

In my agent I try get the config stored.

def myagent(config_path, **kwargs):
    try:
        config = utils.load_config(config_path)
    except StandardError:
        config = {}

    if not config:
        _log.info("Using Agent defaults for starting configuration.")

    mycsv = config.get('mycsv', '')

mycsv always return the string "config://myagent/mycsv.csv"


Solution

  • One thing you can try is "subscribing" to changes to the config store.

    For example, if you stored your config with:

    volttron-ctl config store myagent data/mydata.csv -c mydata.csv --csv
    

    The you can add a callback hook by:

    def __init__(self, **kwargs):
        ...
        self.vip.config.subscribe(self.read_data, actions=["NEW"], pattern="data/mydata.csv")
    
    def read_data(self, config_path, action, contents):
        # Do stuff
        pass