initial commit
This commit is contained in:
49
main.py
Normal file
49
main.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from pymodbus.client import ModbusTcpClient
|
||||
import struct
|
||||
import time
|
||||
|
||||
# Verbindung zur Wärmepumpe
|
||||
ip = '10.0.0.10'
|
||||
port = 502
|
||||
unit_id = 1
|
||||
|
||||
# Liste von interessanten Holding-Register-Adressen
|
||||
registers = {
|
||||
10: {'desc': 'Modus (0=OFF, 1=AUTO, 2=Sommer, ...)', 'type': 'UINT'},
|
||||
51: {'desc': 'Solltemperatur WP in °C', 'type': 'REAL'},
|
||||
71: {'desc': 'Solltemperatur HK1 in °C', 'type': 'REAL'},
|
||||
91: {'desc': 'Solltemperatur HK2 in °C', 'type': 'REAL'}
|
||||
}
|
||||
|
||||
client = ModbusTcpClient(ip, port=port)
|
||||
|
||||
try:
|
||||
if not client.connect():
|
||||
print("Verbindung zur Wärmepumpe fehlgeschlagen.")
|
||||
exit(1)
|
||||
print("Verbindung zur Wärmepumpe erfolgreich.")
|
||||
|
||||
while True:
|
||||
print(f"\n--- Neue Abfrage --- {time.strftime('%Y-%m-%d %H:%M:%S')} ---")
|
||||
for address, info in registers.items():
|
||||
reg_type = info['type']
|
||||
result = client.read_holding_registers(address, count=2 if reg_type == 'REAL' else 1)#, unit=unit_id)
|
||||
|
||||
if result.isError():
|
||||
print(f"Fehler beim Lesen von Adresse {address}: {result}")
|
||||
continue
|
||||
|
||||
if reg_type == 'REAL':
|
||||
decoder = struct.pack('>HH', result.registers[0], result.registers[1])
|
||||
value = struct.unpack('>f', decoder)[0]
|
||||
else:
|
||||
value = result.registers[0]
|
||||
|
||||
print(f"Adresse {address} - {info['desc']}: {value}")
|
||||
|
||||
time.sleep(10)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("Beendet durch Benutzer (Ctrl+C).")
|
||||
finally:
|
||||
client.close()
|
||||
Reference in New Issue
Block a user