mirror of
https://github.com/alexhopeoconnor/SunGather.git
synced 2026-10-23 11:02:10 +10:00
Added HTTP export, massive README update, improved error checking, added commandline options
This commit is contained in:
+1
-3
@@ -1,7 +1,5 @@
|
|||||||
FROM python:3
|
FROM python:3
|
||||||
|
|
||||||
ENV IS_DOCKER True
|
|
||||||
|
|
||||||
WORKDIR /usr/src/sungather
|
WORKDIR /usr/src/sungather
|
||||||
|
|
||||||
COPY requirements.txt ./
|
COPY requirements.txt ./
|
||||||
@@ -10,4 +8,4 @@ RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
|||||||
COPY SunGather/ .
|
COPY SunGather/ .
|
||||||
RUN touch /config/config.yaml
|
RUN touch /config/config.yaml
|
||||||
|
|
||||||
CMD [ "python", "sungather.py" ]
|
CMD [ "python", "sungather.py -c /config/config.yaml" ]
|
||||||
@@ -20,6 +20,10 @@ exports:
|
|||||||
- name: console # Print Registers to console, good for debugging / troubleshooting
|
- name: console # Print Registers to console, good for debugging / troubleshooting
|
||||||
enabled: False
|
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
|
- name: mqtt # Publish Registers to MQTT / Home Assistant
|
||||||
host: 192.168.1.200
|
host: 192.168.1.200
|
||||||
# port: 1883
|
# port: 1883
|
||||||
|
|||||||
@@ -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 @@
|
|||||||
__version__ = '0.1.0'
|
__version__ = '0.1.1'
|
||||||
+1
-1
@@ -3,4 +3,4 @@ requests>=2.26.0
|
|||||||
paho-mqtt>=1.5.1
|
paho-mqtt>=1.5.1
|
||||||
pymodbus>=2.4.0
|
pymodbus>=2.4.0
|
||||||
SungrowModbusTcpClient>=0.1.5
|
SungrowModbusTcpClient>=0.1.5
|
||||||
SungrowModbusWebClient>=0.2.5
|
SungrowModbusWebClient>=0.2.6
|
||||||
|
|||||||
Reference in New Issue
Block a user