Added HTTP export, massive README update, improved error checking, added commandline options

This commit is contained in:
bohdan-s
2021-12-24 10:43:57 +11:00
parent adf9718f4e
commit 2b81d33bc8
5 changed files with 47 additions and 5 deletions
+1 -3
View File
@@ -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" ]
CMD [ "python", "sungather.py -c /config/config.yaml" ]
+4
View File
@@ -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
+40
View File
@@ -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 = "<table><tr><th>Register</th><th>Value</th>"
for register in inverter:
body = body + f"<tr><td>{register}</td><td>{inverter.get(register)}</td></tr>"
export_http.html_body = body + f"</table><p>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("<html><head><title>SunGather</title><meta http-equiv='refresh' content='15'></head>", "utf-8"))
self.wfile.write(bytes("<body>", "utf-8"))
self.wfile.write(bytes(export_http.html_body, "utf-8"))
self.wfile.write(bytes("</table>", "utf-8"))
self.wfile.write(bytes("</body></html>", "utf-8"))
def log_message(self, format, *args):
pass
+1 -1
View File
@@ -1 +1 @@
__version__ = '0.1.0'
__version__ = '0.1.1'
+1 -1
View File
@@ -3,4 +3,4 @@ requests>=2.26.0
paho-mqtt>=1.5.1
pymodbus>=2.4.0
SungrowModbusTcpClient>=0.1.5
SungrowModbusWebClient>=0.2.5
SungrowModbusWebClient>=0.2.6