shelly hinzugefügt
This commit is contained in:
BIN
__pycache__/data_base_csv.cpython-312.pyc
Normal file
BIN
__pycache__/data_base_csv.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/data_base_influx.cpython-312.pyc
Normal file
BIN
__pycache__/data_base_influx.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/heat_pump.cpython-312.pyc
Normal file
BIN
__pycache__/heat_pump.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/shelly_pro_3m.cpython-312.pyc
Normal file
BIN
__pycache__/shelly_pro_3m.cpython-312.pyc
Normal file
Binary file not shown.
1
data/.~lock.shelly_pro_3m_registers.xlsx#
Normal file
1
data/.~lock.shelly_pro_3m_registers.xlsx#
Normal file
@@ -0,0 +1 @@
|
|||||||
|
,nils,nils-ThinkPad-P52,26.05.2025 20:45,file:///home/nils/.config/libreoffice/4;
|
||||||
BIN
data/shelly_pro_3m_registers.xlsx
Normal file
BIN
data/shelly_pro_3m_registers.xlsx
Normal file
Binary file not shown.
@@ -10,8 +10,8 @@ class DataBaseInflux:
|
|||||||
self.client = InfluxDBClient(url=self.url, token=self.token, org=self.org)
|
self.client = InfluxDBClient(url=self.url, token=self.token, org=self.org)
|
||||||
self.write_api = self.client.write_api()
|
self.write_api = self.client.write_api()
|
||||||
|
|
||||||
def store_data(self, data: dict):
|
def store_data(self, device_name: str, data: dict):
|
||||||
measurement = "messungen" # Fest auf "messungen" gesetzt
|
measurement = device_name # Fest auf "messungen" gesetzt
|
||||||
|
|
||||||
point = Point(measurement)
|
point = Point(measurement)
|
||||||
|
|
||||||
@@ -25,9 +25,4 @@ class DataBaseInflux:
|
|||||||
# Punkt in InfluxDB schreiben
|
# Punkt in InfluxDB schreiben
|
||||||
self.write_api.write(bucket=self.bucket, org=self.org, record=point)
|
self.write_api.write(bucket=self.bucket, org=self.org, record=point)
|
||||||
|
|
||||||
db = DataBaseInflux(
|
|
||||||
url="http://localhost:8086",
|
|
||||||
token="Cw_naEZyvJ3isiAh1P4Eq3TsjcHmzzDFS7SlbKDsS6ZWL04fMEYixWqtNxGThDdG27S9aW5g7FP9eiq5z1rsGA==",
|
|
||||||
org="allmende",
|
|
||||||
bucket="allmende_db"
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ import pandas as pd
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
class HeatPump:
|
class HeatPump:
|
||||||
def __init__(self, ip_address: str):
|
def __init__(self, device_name: str, ip_address: str):
|
||||||
|
self.device_name = device_name
|
||||||
self.ip = ip_address
|
self.ip = ip_address
|
||||||
self.client = None
|
self.client = None
|
||||||
self.connect_to_modbus()
|
self.connect_to_modbus()
|
||||||
@@ -25,7 +26,7 @@ class HeatPump:
|
|||||||
|
|
||||||
def get_registers(self):
|
def get_registers(self):
|
||||||
# Excel-Datei mit den Input-Registerinformationen
|
# Excel-Datei mit den Input-Registerinformationen
|
||||||
excel_path = "data/ModBus TCPIP 1.17(1).xlsx"
|
excel_path = "data/heat_pump_registers.xlsx"
|
||||||
xls = pd.ExcelFile(excel_path)
|
xls = pd.ExcelFile(excel_path)
|
||||||
df_input_registers = xls.parse('04 Input Register')
|
df_input_registers = xls.parse('04 Input Register')
|
||||||
|
|
||||||
|
|||||||
12
main.py
12
main.py
@@ -3,22 +3,24 @@ from datetime import datetime
|
|||||||
from data_base_csv import DataBaseCsv
|
from data_base_csv import DataBaseCsv
|
||||||
from data_base_influx import DataBaseInflux
|
from data_base_influx import DataBaseInflux
|
||||||
from heat_pump import HeatPump
|
from heat_pump import HeatPump
|
||||||
|
from shelly_pro_3m import ShellyPro3m
|
||||||
|
|
||||||
interval = 10 # z.B. alle 10 Sekunden
|
interval = 10
|
||||||
|
|
||||||
#db = DataBaseCsv('modbus_log.csv')
|
|
||||||
db = DataBaseInflux(
|
db = DataBaseInflux(
|
||||||
url="http://localhost:8086",
|
url="http://localhost:8086",
|
||||||
token="Cw_naEZyvJ3isiAh1P4Eq3TsjcHmzzDFS7SlbKDsS6ZWL04fMEYixWqtNxGThDdG27S9aW5g7FP9eiq5z1rsGA==",
|
token="Cw_naEZyvJ3isiAh1P4Eq3TsjcHmzzDFS7SlbKDsS6ZWL04fMEYixWqtNxGThDdG27S9aW5g7FP9eiq5z1rsGA==",
|
||||||
org="allmende",
|
org="allmende",
|
||||||
bucket="allmende_db"
|
bucket="allmende_db"
|
||||||
)
|
)
|
||||||
hp = HeatPump(ip_address='10.0.0.10')
|
|
||||||
|
hp = HeatPump(device_name='hp_master', ip_address='10.0.0.10')
|
||||||
|
shelly = ShellyPro3m(device_name='wohnung_2_6', ip_address='192.168.1.121')
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
if now.second % interval == 0 and now.microsecond < 100_000:
|
if now.second % interval == 0 and now.microsecond < 100_000:
|
||||||
db.store_data(hp.get_data())
|
db.store_data(hp.device_name, hp.get_data())
|
||||||
|
db.store_data(shelly.device_name, shelly.get_data())
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
|||||||
60
shelly_pro_3m.py
Normal file
60
shelly_pro_3m.py
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
from pymodbus.client import ModbusTcpClient
|
||||||
|
import pandas as pd
|
||||||
|
import time
|
||||||
|
|
||||||
|
class ShellyPro3m:
|
||||||
|
def __init__(self, device_name: str, ip_address: str):
|
||||||
|
self.device_name = device_name
|
||||||
|
self.ip = ip_address
|
||||||
|
self.client = None
|
||||||
|
self.connect_to_modbus()
|
||||||
|
self.registers = None
|
||||||
|
self.get_registers()
|
||||||
|
|
||||||
|
def connect_to_modbus(self):
|
||||||
|
port = 502
|
||||||
|
self.client = ModbusTcpClient(self.ip, port=port)
|
||||||
|
try:
|
||||||
|
if not self.client.connect():
|
||||||
|
print("Verbindung zur Wärmepumpe fehlgeschlagen.")
|
||||||
|
exit(1)
|
||||||
|
print("Verbindung zur Wärmepumpe erfolgreich.")
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("Beendet durch Benutzer (Ctrl+C).")
|
||||||
|
finally:
|
||||||
|
self.client.close()
|
||||||
|
|
||||||
|
def get_registers(self):
|
||||||
|
# Excel-Datei mit den Input-Registerinformationen
|
||||||
|
excel_path = "data/shelly_pro_3m_registers.xlsx"
|
||||||
|
xls = pd.ExcelFile(excel_path)
|
||||||
|
df_input_registers = xls.parse()
|
||||||
|
|
||||||
|
# Relevante Spalten bereinigen
|
||||||
|
df_clean = df_input_registers[['MB Adresse', 'Beschreibung', 'Variabel Typ']].dropna()
|
||||||
|
df_clean['MB Adresse'] = df_clean['MB Adresse'].astype(int)
|
||||||
|
|
||||||
|
# Dictionary aus Excel erzeugen
|
||||||
|
self.registers = {
|
||||||
|
row['MB Adresse']: {
|
||||||
|
'desc': row['Beschreibung'],
|
||||||
|
'type': 'REAL' if row['Variabel Typ'] == 'REAL' else 'INT'
|
||||||
|
}
|
||||||
|
for _, row in df_clean.iterrows()
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_data(self):
|
||||||
|
data = {}
|
||||||
|
data['Zeit'] = time.strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
for address, info in self.registers.items():
|
||||||
|
reg_type = info['type']
|
||||||
|
result = self.client.read_input_registers(address, count=2 if reg_type == 'REAL' else 1)
|
||||||
|
if result.isError():
|
||||||
|
print(f"Fehler beim Lesen von Adresse {address}: {result}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
value = result.registers[0] / 10.0
|
||||||
|
|
||||||
|
print(f"Adresse {address} - {info['desc']}: {value}")
|
||||||
|
data[f"{address} - {info['desc']}"] = value
|
||||||
|
return data
|
||||||
Reference in New Issue
Block a user