diff --git a/Dockerfile b/Dockerfile index 7831368..98a63f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,5 @@ FROM python:3 -ENV IS_DOCKER True - WORKDIR /usr/src/sungather COPY requirements.txt ./ @@ -10,4 +8,4 @@ RUN pip install --no-cache-dir --upgrade -r requirements.txt COPY SunGather/ . RUN touch /config/config.yaml -CMD [ "python", "sungather.py" ] \ No newline at end of file +CMD [ "python", "sungather.py -c /config/config.yaml" ] \ No newline at end of file diff --git a/SunGather/config-example.yaml b/SunGather/config-example.yaml index cdcac9c..cfc74ac 100644 --- a/SunGather/config-example.yaml +++ b/SunGather/config-example.yaml @@ -20,6 +20,10 @@ exports: - name: console # Print Registers to console, good for debugging / troubleshooting enabled: False + - name: http + enabled: True # Access at http://localhost:8080 or http://[serverip]:8080 + # port: 8080 # Default port is 8080 + - name: mqtt # Publish Registers to MQTT / Home Assistant host: 192.168.1.200 # port: 1883 diff --git a/SunGather/exports/http.py b/SunGather/exports/http.py new file mode 100644 index 0000000..1991646 --- /dev/null +++ b/SunGather/exports/http.py @@ -0,0 +1,40 @@ +from http.server import BaseHTTPRequestHandler, HTTPServer +from socketserver import ThreadingMixIn +from threading import Thread + +import logging + +class export_http(object): + html_body = "Pending Data retrieval" + def __init__(self): + return + + # Configure HTTP + def configure(self, config): + self.webServer = HTTPServer(('localhost', config.get('port',8080)), MyServer) + t = Thread(target=self.webServer.serve_forever) + t.start() + logging.info("Configured Simple HTTP Server") + + def publish(self, inverter): + #global html_body + + body = "
| Register | Value | " + for register in inverter: + body = body + f"
|---|---|
| {register} | {inverter.get(register)} |
Total {len(inverter)} registers" + print("Publish HTTP") + return + +class MyServer(BaseHTTPRequestHandler): + def do_GET(self): + self.send_response(200) + self.send_header("Content-type", "text/html") + self.end_headers() + self.wfile.write(bytes("