Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EmonHub.conf configuration editor #3

Open
TrystanLea opened this issue Dec 20, 2018 · 5 comments
Open

EmonHub.conf configuration editor #3

TrystanLea opened this issue Dec 20, 2018 · 5 comments

Comments

@TrystanLea
Copy link
Member

TrystanLea commented Dec 20, 2018

At the moment the emonhub.conf configuration editor is a simple text file editor:

image

It would be really nice to have a web ui version of the editor to make configuration easier to edit.

The configuration format used is python ConfigObj. There is no php parser of the configobj format. Eemoncms could load the config file via a socket request, MQTT or redis key made available by emonhub.

The configuration would be shared as a JSON object and changes transposed back into the original confobj object in emonhub when edits are made.

Basic example of reading from ConfigObj file, changing the apikey and writing the change back to the original file:

from configobj import ConfigObj
settings = ConfigObj("emonhub.conf", file_error=True)
settings["interfacers"]["emoncmsorg"]["runtimesettings"]["apikey"] = "test"
settings.write()

If the settings are transfered to emoncms as a json object, the json changes need to be merged with the original settings in the configobj class, preserving orignal comments, ordering, spacing and indentation:

import json
from configobj import ConfigObj

# 1. Load config object
# settings is more than a dict of the contents, it is an instance of the configobj class
settings = ConfigObj("emonhub.conf", file_error=True)

# 2. Translate configuration into json object and reload back to python dict
# json string could be sent or requested by emoncms at this point
jsonstr = json.dumps(settings)
# json string could be sent back to emonhub at this point
jsonsettings = json.loads(jsonstr)

# 3. Update apikey in dict
jsonsettings["interfacers"]["emoncmsorg"]["runtimesettings"]["apikey"] = "anther"

# 4. Merge dict with original configobj class
settings.merge(jsonsettings)

# 5. Save to conf file
settings.write()
@TrystanLea
Copy link
Member Author

Interfacers concept screen:

image

Nodes concept screen:

image

@TrystanLea
Copy link
Member Author

nodes configuration with node inputs properties arranged horizontally:

image

@TrystanLea
Copy link
Member Author

Initial implementation: https://github.com/emoncms/config/tree/editor

Python loader:

import json
from configobj import ConfigObj
import redis
import time

r = redis.Redis(host="localhost",port=6379,db=0)

# 1. Load config object
# settings is more than a dict of the contents, it is an instance of the configobj class
settings = ConfigObj("emonhub.conf", file_error=True)

# 2. Translate configuration into json object and reload back to python dict
jsonstr = json.dumps(settings)

r.set("get:emonhubconf",jsonstr)

while 1:

    result = r.get("set:emonhubconf")
    if result:
        r.delete("set:emonhubconf");
        jsonsettings = json.loads(result)
        # 4. Merge dict with original configobj class
        settings.merge(jsonsettings)
        # 5. Save to conf file
        settings.write()
        # 6. Resave to redis
        jsonstr = json.dumps(settings)
        r.set("get:emonhubconf",jsonstr)
        print "config set"
        
    time.sleep(1)

@TrystanLea
Copy link
Member Author

Python code above included in emonhub development branch:

https://github.com/openenergymonitor/emonhub/compare/redis_config_interface

@TrystanLea
Copy link
Member Author

Latest included remote emoncms config interface:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant