emoncms / config

Configure emonhub.conf and view emonhub.log from within emoncms
GNU Affero General Public License v3.0
0 stars 10 forks source link

EmonHub.conf configuration editor #3

Open TrystanLea opened 5 years ago

TrystanLea commented 5 years ago

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 commented 5 years ago

Interfacers concept screen:

image

Nodes concept screen:

image

TrystanLea commented 5 years ago

nodes configuration with node inputs properties arranged horizontally:

image

TrystanLea commented 5 years ago

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 commented 5 years ago

Python code above included in emonhub development branch:

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

TrystanLea commented 5 years ago

Latest included remote emoncms config interface: image