From 147a2d739af1bac8c3ef6863da9ae1d441b077f8 Mon Sep 17 00:00:00 2001 From: okaegi Date: Tue, 3 Jan 2023 12:52:42 +0100 Subject: [PATCH 1/6] E3DC Driver... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Für Openwb 2.0 muss offensichtlich der die type Variable dem Verzeichnissnamen entsprechen , sonst Absturz im Online beim konfigurieren Bei der Verarbeitung des Befehls 'addDevice' mit den Parametern '[object Object]' ist ein Fehler aufgetreten: Es ist ein interner Fehler aufgetreten: Traceback (most recent call last): File "/var/www/html/openWB/packages/helpermodules/command.py", line 112, in on_message func(connection_id, payload) File "/var/www/html/openWB/packages/helpermodules/command.py", line 123, in addDevice dev = importlib.import_module(".devices."+payload["data"]["type"]+".device", "modules") File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 972, in _find_and_load_unlocked File "", line 228, in _call_with_frames_removed File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 984, in _find_and_load_unlocked ModuleNotFoundError: No module named 'modules.devices.E3DC' Für openwb 1.9 keine Auswirkungen --- packages/modules/devices/e3dc/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/modules/devices/e3dc/config.py b/packages/modules/devices/e3dc/config.py index f249addb2b..d238903697 100644 --- a/packages/modules/devices/e3dc/config.py +++ b/packages/modules/devices/e3dc/config.py @@ -12,7 +12,7 @@ def __init__(self, address: str = None): class E3dc: def __init__(self, name: str = "E3DC", - type: str = "E3DC", + type: str = "e3dc", id: int = 0, configuration: E3dcConfiguration = None) -> None: self.name = name From afb4a8b2b1d50ad5402f3f50d2db78b6f752bce8 Mon Sep 17 00:00:00 2001 From: LKuemmel <76958050+LKuemmel@users.noreply.github.com> Date: Wed, 4 Jan 2023 10:31:14 +0100 Subject: [PATCH 2/6] new isss for buchse master (#2550) * new isss for daemon * review * renaming --- .../chargepoints/internal_openwb/socket.py | 13 +- runs/buchse.py | 440 ------------------ runs/initRamdisk.sh | 1 + runs/isss.py | 41 +- runs/services.sh | 51 +- 5 files changed, 56 insertions(+), 490 deletions(-) delete mode 100755 runs/buchse.py diff --git a/packages/modules/chargepoints/internal_openwb/socket.py b/packages/modules/chargepoints/internal_openwb/socket.py index d02b23dd9d..0762db6481 100644 --- a/packages/modules/chargepoints/internal_openwb/socket.py +++ b/packages/modules/chargepoints/internal_openwb/socket.py @@ -48,8 +48,9 @@ class ActorState(IntEnum): class Socket(ChargepointModule): - def __init__(self, max_current: int, config: InternalOpenWB) -> None: - self.max_current = max_current + def __init__(self, socket_max_current: int, config: InternalOpenWB) -> None: + log.debug("Konfiguration als Buchse.") + self.socket_max_current = socket_max_current super().__init__(config) def set_current(self, current: float) -> None: @@ -60,12 +61,12 @@ def set_current(self, current: float) -> None: log.error("Error getting actor status! Using default 'opened'.") actor = ActorState.OPENED - if actor == ActorState.CLOSED: - if current == self.set_current_evse or self.chargepoint_state.plug_state is False: + if actor == ActorState.CLOSED or self.chargepoint_state.plug_state is False: + if current == self.set_current_evse: return else: current = 0 - super().set_current(min(current, self.max_current)) + super().set_current(min(current, self.socket_max_current)) def get_values(self, phase_switch_cp_active: bool) -> Tuple[ChargepointState, float]: try: @@ -94,6 +95,6 @@ def __close_actor(self): def __set_actor(self, open: bool): GPIO.output(23, GPIO.LOW if open else GPIO.HIGH) GPIO.output(26, GPIO.HIGH) - time.sleep(2 if open else 3) + time.sleep(1) GPIO.output(26, GPIO.LOW) log.debug("Actor opened" if open else "Actor closed") diff --git a/runs/buchse.py b/runs/buchse.py deleted file mode 100755 index 1552b4989b..0000000000 --- a/runs/buchse.py +++ /dev/null @@ -1,440 +0,0 @@ -#!/usr/bin/python -import os -import time -import struct -import traceback -from typing import Tuple -import RPi.GPIO as GPIO -from pymodbus.client.sync import ModbusSerialClient -import paho.mqtt.client as mqtt - -basePath = "/var/www/html/openWB" -ramdiskPath = basePath + "/ramdisk" -logFilename = ramdiskPath + "/buchse.log" - -DeviceValues = {} -Values = {} - - -# handling of all logging statements -def log_debug(level: int, msg: str, traceback_str: str = None) -> None: - if level >= loglevel: - with open(logFilename, 'a') as log_file: - log_file.write(time.ctime() + ': ' + msg + '\n') - if traceback_str is not None: - log_file.write(traceback_str + '\n') - - -# write value to file in ramdisk -def write_to_ramdisk(filename: str, content: str) -> None: - with open(ramdiskPath + "/" + filename, "w") as file: - file.write(content) - - -# read value from file in ramdisk -def read_from_ramdisk(filename: str) -> str: - try: - with open(ramdiskPath + "/" + filename, 'r') as file: - return file.read() - except FileNotFoundError: - log_debug(2, "Error reading file '" + filename + "' from ramdisk!", traceback.format_exc()) - return "" - - -def init_gpio() -> None: - GPIO.setwarnings(False) - GPIO.setmode(GPIO.BOARD) - GPIO.setup(37, GPIO.OUT) - GPIO.setup(13, GPIO.OUT) - GPIO.setup(22, GPIO.OUT) - GPIO.setup(29, GPIO.OUT) - GPIO.setup(11, GPIO.OUT) - # GPIOs for socket - GPIO.setup(23, GPIO.OUT) - GPIO.setup(26, GPIO.OUT) - GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_UP) - - -def init_values() -> None: - global DeviceValues - global Values - # values LP1 - DeviceValues.update({'lp1voltage1': str(5)}) - DeviceValues.update({'lp1voltage2': str(5)}) - DeviceValues.update({'lp1voltage3': str(5)}) - DeviceValues.update({'lp1lla1': str(5)}) - DeviceValues.update({'lp1lla2': str(5)}) - DeviceValues.update({'lp1lla3': str(5)}) - DeviceValues.update({'lp1llkwh': str(5)}) - DeviceValues.update({'lp1watt': str(5)}) - DeviceValues.update({'lp1chargestat': str(5)}) - DeviceValues.update({'lp1plugstat': str(5)}) - DeviceValues.update({'lp1readerror': str(0)}) - Values.update({'lp1plugstat': str(5)}) - Values.update({'lp1chargestat': str(5)}) - Values.update({'lp1evsell': str(1)}) - - -# read all meter values and publish to mqtt broker -def read_meter(): - global evsefailure - global client - global llmeterconfiglp1 - global sdmid - - if (llmeterconfiglp1 == 0): - log_debug(2, "Erkenne verbauten Zaehler.") - # check sdm - try: - resp = client.read_input_registers(0x00, 2, unit=105) - voltage = struct.unpack('>f', struct.pack('>HH', *resp.registers))[0] - if int(voltage) > 20: - llmeterconfiglp1 = 105 - sdmid = 105 - log_debug(2, "SDM Zaehler erkannt") - except AttributeError: - log_debug(2, "SDM check failed", traceback.format_exc()) - # check B23 - try: - resp = client.read_holding_registers(0x5B00, 2, unit=201) - voltage = resp.registers[1] - if int(voltage) > 20: - llmeterconfiglp1 = 201 - sdmid = 201 - log_debug(2, "B23 Zaehler erkannt") - except AttributeError: - log_debug(2, "B23 check failed", traceback.format_exc()) - else: - sdmid = llmeterconfiglp1 - try: - if sdmid < 200: - # SDM - resp = client.read_input_registers(0x0C, 2, unit=sdmid) - lp1llw1 = struct.unpack('>f', struct.pack('>HH', *resp.registers))[0] - lp1llw1 = int(lp1llw1) - resp = client.read_input_registers(0x0E, 2, unit=sdmid) - lp1llw2 = struct.unpack('>f', struct.pack('>HH', *resp.registers))[0] - lp1llw2 = int(lp1llw2) - resp = client.read_input_registers(0x10, 2, unit=sdmid) - lp1llw3 = struct.unpack('>f', struct.pack('>HH', *resp.registers))[0] - lp1llw3 = int(lp1llw3) - lp1llg = lp1llw1 + lp1llw2 + lp1llw3 - if lp1llg < 10: - lp1llg = 0 - write_to_ramdisk("llaktuell", str(lp1llg)) - resp = client.read_input_registers(0x00, 2, unit=sdmid) - voltage = struct.unpack('>f', struct.pack('>HH', *resp.registers))[0] - lp1voltage1 = float("%.1f" % voltage) - write_to_ramdisk("llv1", str(lp1voltage1)) - resp = client.read_input_registers(0x02, 2, unit=sdmid) - voltage = struct.unpack('>f', struct.pack('>HH', *resp.registers))[0] - lp1voltage2 = float("%.1f" % voltage) - write_to_ramdisk("llv2", str(lp1voltage2)) - resp = client.read_input_registers(0x04, 2, unit=sdmid) - voltage = struct.unpack('>f', struct.pack('>HH', *resp.registers))[0] - lp1voltage3 = float("%.1f" % voltage) - write_to_ramdisk("llv3", str(lp1voltage3)) - resp = client.read_input_registers(0x06, 2, unit=sdmid) - lp1lla1 = float(struct.unpack('>f', struct.pack('>HH', *resp.registers))[0]) - lp1lla1 = float("%.1f" % lp1lla1) - write_to_ramdisk("lla1", str(lp1lla1)) - resp = client.read_input_registers(0x08, 2, unit=sdmid) - lp1lla2 = float(struct.unpack('>f', struct.pack('>HH', *resp.registers))[0]) - lp1lla2 = float("%.1f" % lp1lla2) - write_to_ramdisk("lla2", str(lp1lla2)) - resp = client.read_input_registers(0x0A, 2, unit=sdmid) - lp1lla3 = struct.unpack('>f', struct.pack('>HH', *resp.registers))[0] - lp1lla3 = float("%.1f" % lp1lla3) - write_to_ramdisk("lla3", str(lp1lla3)) - resp = client.read_input_registers(0x0156, 2, unit=sdmid) - lp1llkwh = struct.unpack('>f', struct.pack('>HH', *resp.registers))[0] - lp1llkwh = float("%.3f" % lp1llkwh) - write_to_ramdisk("llkwh", str(lp1llkwh)) - resp = client.read_input_registers(0x46, 2, unit=sdmid) - hz = struct.unpack('>f', struct.pack('>HH', *resp.registers))[0] - hz = float("%.2f" % hz) - write_to_ramdisk("llhz", str(hz)) - else: - # B23 - # llkwh - resp = client.read_holding_registers(0x5000, 4, unit=sdmid) - lp1llkwh = struct.unpack('>Q', struct.pack('>HHHH', *resp.registers))[0]/100 - write_to_ramdisk("llkwh", str(lp1llkwh)) - # Voltage - resp = client.read_holding_registers(0x5B00, 2, unit=sdmid) - voltage = resp.registers[1] - lp1voltage1 = float(voltage) / 10 - write_to_ramdisk("llv1", str(lp1voltage1)) - resp = client.read_holding_registers(0x5B02, 2, unit=sdmid) - lp1voltage2 = resp.registers[1] - lp1voltage2 = float(lp1voltage2) / 10 - write_to_ramdisk("llv2", str(lp1voltage2)) - resp = client.read_holding_registers(0x5B04, 2, unit=sdmid) - voltage = resp.registers[1] - lp1voltage3 = float(voltage) / 10 - write_to_ramdisk("llv3", str(lp1voltage3)) - # Ampere - resp = client.read_holding_registers(0x5B0C, 2, unit=sdmid) - amp = resp.registers[1] - lp1lla1 = float(amp) / 100 - write_to_ramdisk("lla1", str(lp1lla1)) - resp = client.read_holding_registers(0x5B0E, 2, unit=sdmid) - amp = resp.registers[1] - lp1lla2 = float(amp) / 100 - write_to_ramdisk("lla2", str(lp1lla2)) - resp = client.read_holding_registers(0x5B10, 2, unit=sdmid) - amp = resp.registers[1] - lp1lla3 = float(amp) / 100 - write_to_ramdisk("lla3", str(lp1lla3)) - # Gesamt watt - resp = client.read_holding_registers(0x5B14, 2, unit=sdmid) - lp1llg = int(struct.unpack('>i', struct.pack('>HH', *resp.registers))[0]/100) - write_to_ramdisk("llaktuell", str(lp1llg)) - # LL Hz - resp = client.read_holding_registers(0x5B2C, 2, unit=sdmid) - hz = float(resp.registers[0]) / 100 - write_to_ramdisk("llhz", str(hz)) - - try: - time.sleep(0.1) - rq = client.read_holding_registers(1000, 1, unit=1) - lp1ll = rq.registers[0] - evsefailure = 0 - except: - lp1ll = 0 - evsefailure = 1 - try: - time.sleep(0.1) - rq = client.read_holding_registers(1002, 1, unit=1) - lp1var = rq.registers[0] - evsefailure = 0 - DeviceValues.update({'lp1readerror': str(0)}) - except: - DeviceValues.update({'lp1readerror': str(int(DeviceValues['lp1readerror'])+1)}) - log_debug(2, "Fehler!", traceback.format_exc()) - lp1var = 5 - evsefailure = 1 - if (lp1var == 5 and int(DeviceValues['lp1readerror']) > MaxEvseError): - log_debug(2, "Anhaltender Fehler beim Auslesen der EVSE von lp1! (" + - str(DeviceValues['lp1readerror']) + ")") - log_debug(2, "Plugstat und Chargestat werden zurückgesetzt.") - Values.update({'lp1plugstat': 0}) - Values.update({'lp1chargestat': 0}) - elif (lp1var == 1): - Values.update({'lp1plugstat': 0}) - Values.update({'lp1chargestat': 0}) - elif (lp1var == 2): - Values.update({'lp1plugstat': 1}) - Values.update({'lp1chargestat': 0}) - elif (lp1var == 3 and lp1ll > 0): - Values.update({'lp1plugstat': 1}) - Values.update({'lp1chargestat': 1}) - elif (lp1var == 3 and lp1ll == 0): - Values.update({'lp1plugstat': 1}) - Values.update({'lp1chargestat': 0}) - write_to_ramdisk("plugstat", str(Values["lp1plugstat"])) - write_to_ramdisk("chargestat", str(Values["lp1chargestat"])) - Values.update({'lp1evsell': lp1ll}) - log_debug(0, "EVSE lp1plugstat: " + str(lp1var) + " EVSE lp1LL: " + str(lp1ll)) - - mclient = mqtt.Client("openWB-buchse-bulkpublisher-" + str(os.getpid())) - mclient.connect("localhost") - mclient.loop(timeout=2.0) - for key in DeviceValues: - if ("lp1watt" in key): - if (DeviceValues[str(key)] != str(lp1llg)): - mclient.publish("openWB/lp/1/W", payload=str(lp1llg), qos=0, retain=True) - mclient.loop(timeout=2.0) - DeviceValues.update({'lp1watt': str(lp1llg)}) - if ("lp1voltage1" in key): - if (DeviceValues[str(key)] != str(lp1voltage1)): - mclient.publish("openWB/lp/1/VPhase1", payload=str(lp1voltage1), qos=0, retain=True) - mclient.loop(timeout=2.0) - DeviceValues.update({'lp1voltage1': str(lp1voltage1)}) - if ("lp1voltage2" in key): - if (DeviceValues[str(key)] != str(lp1voltage2)): - mclient.publish("openWB/lp/1/VPhase2", payload=str(lp1voltage2), qos=0, retain=True) - mclient.loop(timeout=2.0) - DeviceValues.update({'lp1voltage2': str(lp1voltage2)}) - if ("lp1voltage3" in key): - if (DeviceValues[str(key)] != str(lp1voltage3)): - mclient.publish("openWB/lp/1/VPhase3", payload=str(lp1voltage3), qos=0, retain=True) - mclient.loop(timeout=2.0) - DeviceValues.update({'lp1voltage3': str(lp1voltage3)}) - if ("lp1lla1" in key): - if (DeviceValues[str(key)] != str(lp1lla1)): - mclient.publish("openWB/lp/1/APhase1", payload=str(lp1lla1), qos=0, retain=True) - mclient.loop(timeout=2.0) - DeviceValues.update({'lp1lla1': str(lp1lla1)}) - if ("lp1lla2" in key): - if (DeviceValues[str(key)] != str(lp1lla2)): - mclient.publish("openWB/lp/1/APhase2", payload=str(lp1lla2), qos=0, retain=True) - mclient.loop(timeout=2.0) - DeviceValues.update({'lp1lla2': str(lp1lla2)}) - if ("lp1lla3" in key): - if (DeviceValues[str(key)] != str(lp1lla3)): - mclient.publish("openWB/lp/1/APhase3", payload=str(lp1lla3), qos=0, retain=True) - mclient.loop(timeout=2.0) - DeviceValues.update({'lp1lla3': str(lp1lla3)}) - if ("lp1llkwh" in key): - if (DeviceValues[str(key)] != str(lp1llkwh)): - mclient.publish("openWB/lp/1/kWhCounter", payload=str(lp1llkwh), qos=0, retain=True) - mclient.loop(timeout=2.0) - DeviceValues.update({'lp1llkwh': str(lp1llkwh)}) - if ("lp1plugstat" in key): - if (DeviceValues[str(key)] != Values["lp1plugstat"]): - mclient.publish("openWB/lp/1/boolPlugStat", payload=Values["lp1plugstat"], qos=0, retain=True) - mclient.loop(timeout=2.0) - DeviceValues.update({'lp1plugstat': Values["lp1plugstat"]}) - if ("lp1chargestat" in key): - if (DeviceValues[str(key)] != Values["lp1chargestat"]): - mclient.publish("openWB/lp/1/boolChargeStat", payload=Values["lp1chargestat"], qos=0, retain=True) - mclient.loop(timeout=2.0) - DeviceValues.update({'lp1chargestat': Values["lp1chargestat"]}) - mclient.disconnect() - except Exception: - log_debug(2, "Get meter Fehler!", traceback.format_exc()) - - -# control of socket lock -# GPIO 23: control direction of lock motor -# GPIO 26: power to lock motor -def set_socket_actuator(action): - if action == "auf": - GPIO.output(23, GPIO.LOW) - GPIO.output(26, GPIO.HIGH) - time.sleep(2) - GPIO.output(26, GPIO.LOW) - log_debug(1, "Aktor auf") - if action == "zu": - GPIO.output(23, GPIO.HIGH) - GPIO.output(26, GPIO.HIGH) - time.sleep(3) - GPIO.output(26, GPIO.LOW) - log_debug(1, "Aktor zu") - - -# get actual socket lock state -def get_socket_state() -> int: - actorstat_tmp = GPIO.input(19) - if actorstat_tmp == GPIO.LOW: - return 1 - else: - return 0 - - -# get all values to control our chargepoint -def load_control_values(): - global actorstat - global lp1solla - global u1p3pstat - global u1p3ptmpstat - global evsefailure - - actorstat = get_socket_state() - try: - lp1solla = int(read_from_ramdisk("llsoll")) - except ValueError: - lp1solla = 0 - log_debug(0, "LL Soll: " + str(lp1solla) + " ActorStatus: " + str(actorstat)) - if socket_configured: - if (evsefailure == 0): - if (Values["lp1plugstat"] == 1): - if (actorstat == 0): - set_socket_actuator("zu") - if (Values["lp1plugstat"] == 0): - if (actorstat == 1): - writelp1evse(0) - set_socket_actuator("auf") - if (actorstat == 1): - if (Values["lp1evsell"] != lp1solla and Values["lp1plugstat"] == 1): - writelp1evse(lp1solla) - else: - if (Values["lp1evsell"] != 0): - writelp1evse(0) - else: - if (Values["lp1evsell"] != lp1solla): - writelp1evse(lp1solla) - try: - u1p3ptmpstat = int(read_from_ramdisk("u1p3pstat")) - except ValueError: - u1p3ptmpstat = 3 - try: - u1p3pstat - except: - u1p3pstat = 3 - u1p3pstat = switch_phases_cp1(u1p3ptmpstat, u1p3pstat) - - -def __switch_phases(gpio_cp: int, gpio_relay: int): - GPIO.output(gpio_cp, GPIO.HIGH) # CP on - GPIO.output(gpio_relay, GPIO.HIGH) # 3 on/off - time.sleep(2) - GPIO.output(gpio_relay, GPIO.LOW) # 3 on/off - time.sleep(5) - GPIO.output(gpio_cp, GPIO.LOW) # CP off - time.sleep(1) - - -def switch_phases_cp1(new_phases: int, old_phases: int) -> int: - if (new_phases != old_phases): - log_debug(1, "switching phases on cp1: old=" + str(old_phases) + " new=" + str(new_phases)) - gpio_cp = 22 - if (new_phases == 1): - gpio_relay = 29 - else: - gpio_relay = 37 - __switch_phases(gpio_cp, gpio_relay) - else: - log_debug(0, "no need to switch phases on cp1: old=" + str(old_phases) + " new=" + str(new_phases)) - return new_phases - - -def writelp1evse(lla): - if (lla > pp): - lla = pp - client.write_registers(1000, lla, unit=1) - log_debug(1, "Write to EVSE lp1 " + str(lla)) - - -# check for "openWB Buchse" -def check_for_socket() -> Tuple[bool, int]: - try: - with open('/home/pi/ppbuchse', 'r') as value: - pp_value = int(value.read()) - except (FileNotFoundError, ValueError): - pp_value = 32 - # here we always have a socket - socket_is_configured = True - log_debug(1, "check for socket: " + str(socket_is_configured) + " " + str(pp_value)) - return [socket_is_configured, pp_value] - - -# guess USB/modbus device name -def detect_modbus_usb_port() -> str: - try: - with open("/dev/ttyUSB0"): - return "/dev/ttyUSB0" - except FileNotFoundError: - return "/dev/serial0" - - -loglevel = 1 - -MaxEvseError = 5 -sdmid = 105 -actorstat = 0 -evsefailure = 0 -llmeterconfiglp1 = 0 - -init_gpio() -init_values() -socket_configured, pp = check_for_socket() -seradd = detect_modbus_usb_port() -# connect with USB/modbus device -with ModbusSerialClient(method="rtu", port=seradd, baudrate=9600, stopbits=1, bytesize=8, timeout=1) as client: - # start our control loop - while True: - read_meter() - load_control_values() - time.sleep(1) diff --git a/runs/initRamdisk.sh b/runs/initRamdisk.sh index c3fc53f58b..ffe5f85d89 100755 --- a/runs/initRamdisk.sh +++ b/runs/initRamdisk.sh @@ -373,6 +373,7 @@ initRamdisk(){ echo 0 > $RamdiskPath/socketApproved echo 0 > $RamdiskPath/socketActivated echo 0 > $RamdiskPath/socketActivationRequested + echo "unknown" > $RamdiskPath/prev_isss_mode # diverse Dateien echo 0 > $RamdiskPath/AllowedTotalCurrentPerPhase diff --git a/runs/isss.py b/runs/isss.py index 84c7aa7401..e0fa579027 100755 --- a/runs/isss.py +++ b/runs/isss.py @@ -1,20 +1,22 @@ #!/usr/bin/python +from enum import Enum import logging import os import re +import sys import threading import time -from typing import Dict, List, Optional +from typing import List, Optional import RPi.GPIO as GPIO from helpermodules.pub import pub_single -from helpermodules import compatibility from modules.common.store import ramdisk_read, ramdisk_write from modules.common.store._util import get_rounding_function_by_digits from modules.common.fault_state import FaultState from modules.common.component_state import ChargepointState from modules.common.modbus import ModbusSerialClient_ -from modules.chargepoints.internal_openwb import chargepoint_module, socket +from modules.chargepoints.internal_openwb import chargepoint_module +from modules.chargepoints.internal_openwb.socket import Socket from modules.chargepoints.internal_openwb.chargepoint_module import InternalOpenWB basePath = "/var/www/html/openWB" @@ -23,6 +25,12 @@ MAP_LOG_LEVEL = [logging.ERROR, logging.WARNING, logging.DEBUG] +class IsssMode(Enum): + SOCKET = "socket" + DUO = "duo" + DAEMON = "daemon" + + logging.basicConfig(filename=ramdiskPath+'/isss.log', format='%(asctime)s - {%(name)s:%(lineno)s} - %(levelname)s - %(message)s', level=MAP_LOG_LEVEL[int(os.environ.get('debug'))]) @@ -193,17 +201,14 @@ def __thread_cp_interruption(self, duration: int) -> None: class Isss: - def __init__(self) -> None: + def __init__(self, mode: IsssMode, socket_max_current: int) -> None: log.debug("Init isss") self.serial_client = ModbusSerialClient_(self.detect_modbus_usb_port()) - self.cp0 = IsssChargepoint(self.serial_client, 0) - try: - if int(ramdisk_read("issslp2act")) == 1: - self.cp1 = IsssChargepoint(self.serial_client, 1) - else: - self.cp1 = None - except (FileNotFoundError, ValueError) as e: - log.error("Error reading issslp2act! Guessing cp2 is not configured.") + self.cp0 = IsssChargepoint(self.serial_client, 0, mode, socket_max_current) + if mode == IsssMode.DUO: + log.debug("Zweiter Ladepunkt für Duo konfiguriert.") + self.cp1 = IsssChargepoint(self.serial_client, 1, mode, socket_max_current) + else: self.cp1 = None self.init_gpio() @@ -263,14 +268,12 @@ def get_parent_wb() -> str: class IsssChargepoint: - def __init__(self, serial_client: ModbusSerialClient_, local_charge_point_num: int) -> None: + def __init__(self, serial_client: ModbusSerialClient_, local_charge_point_num: int, mode: IsssMode, socket_max_current: int) -> None: self.local_charge_point_num = local_charge_point_num if local_charge_point_num == 0: - try: - with open('/home/pi/ppbuchse', 'r') as f: - max_current = int(f.read()) - self.module = socket.Socket(max_current, InternalOpenWB(0, serial_client)) - except (FileNotFoundError, ValueError): + if mode == IsssMode.SOCKET: + self.module = Socket(socket_max_current, InternalOpenWB(0, serial_client)) + else: self.module = chargepoint_module.ChargepointModule(InternalOpenWB(0, serial_client)) else: self.module = chargepoint_module.ChargepointModule(InternalOpenWB(1, serial_client)) @@ -297,4 +300,4 @@ def __thread_active(thread: Optional[threading.Thread]) -> bool: log.exception("Fehler bei Ladepunkt "+str(self.local_charge_point_num)) -Isss().loop() +Isss(IsssMode(sys.argv[1]), int(sys.argv[2])).loop() diff --git a/runs/services.sh b/runs/services.sh index c64db615f3..c8492e6ac0 100755 --- a/runs/services.sh +++ b/runs/services.sh @@ -63,18 +63,37 @@ start() { fi - if (( isss == 1 )) || [[ "$evsecon" == "daemon" ]]; then - openwbDebugLog "MAIN" 1 "external openWB or daemon mode configured" - if pgrep -f '^python.*/isss.py' > /dev/null + if (( isss == 1 )) || [[ "$evsecon" == "daemon" ]] || [[ "$evsecon" == "buchse" ]]; then + if [[ "$evsecon" == "buchse" ]]; then + isss_mode="socket" + elif [[ $lastmanagement == 1 ]]; then + isss_mode="duo" + else + isss_mode="daemon" + fi + prev_isss_mode=$(< $OPENWBBASEDIR/ramdisk/isss_mode) + + openwbDebugLog "MAIN" 1 "external openWB, daemon mode or socket mode configured" + if pgrep -f '^python.*/isss.py' > /dev/null && [[ $prev_isss_mode == $isss_mode ]]; then openwbDebugLog "MAIN" 1 "isss handler already running" else - openwbDebugLog "MAIN" 0 "isss handler not running! restarting process" - echo "$lastmanagement" > "$OPENWBBASEDIR/ramdisk/issslp2act" - nohup python3 "$OPENWBBASEDIR/runs/isss.py" >>"$OPENWBBASEDIR/ramdisk/isss.log" 2>&1 & + openwbDebugLog "MAIN" 0 "Start/restart isss handler in mode $isss_mode." + if [ -f /home/pi/ppbuchse ]; then + ppbuchse=$(< /home/pi/ppbuchse) + re='^[0-9]+$' + if ! [[ $ppbuchse =~ $re ]] ; then + openwbDebugLog "MAIN" 0 "Invalid value in ppbuchse. Set ppbuchse to 32." + ppbuchse=32 + fi + else + ppbuchse=32 + fi + nohup python3 "$OPENWBBASEDIR/runs/isss.py" "$isss_mode" "$ppbuchse">>"$OPENWBBASEDIR/ramdisk/isss.log" 2>&1 & fi + echo "$isss_mode" > $OPENWBBASEDIR/ramdisk/isss_mode else - openwbDebugLog "MAIN" 1 "external openWB or daemon mode not configured; checking network setup" + openwbDebugLog "MAIN" 1 "external openWB, daemon mode or socket mode not configured; checking network setup" local ethstate=$( /home/pi/ppbuchse - - if pgrep -f '^python.*/buchse.py' > /dev/null - then - openwbDebugLog "MAIN" 1 "socket handler already running" - else - openwbDebugLog "MAIN" 0 "socket handler not running! restarting process" - nohup python3 "$OPENWBBASEDIR/runs/buchse.py" >> "$OPENWBBASEDIR/ramdisk/openWB.log" 2>&1 & - fi - else - sudo pkill -f '^python.*/buchse.py' - fi - rseSetup "$rseenabled" 0 pushButtonsSetup "$ladetaster" 0 From 691fafdab79923200127106da02181f71487c21f Mon Sep 17 00:00:00 2001 From: LKuemmel <76958050+LKuemmel@users.noreply.github.com> Date: Wed, 4 Jan 2023 12:09:10 +0100 Subject: [PATCH 3/6] Bump version 1.9.290 --- web/version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/version b/web/version index cbf5776325..47d6740bf5 100644 --- a/web/version +++ b/web/version @@ -1 +1 @@ -1.9.289 +1.9.290 From 2d92eb59ee2af3ad8e93ac4bf4c5172cf58114a9 Mon Sep 17 00:00:00 2001 From: LKuemmel <76958050+LKuemmel@users.noreply.github.com> Date: Wed, 4 Jan 2023 12:13:06 +0100 Subject: [PATCH 4/6] Bump version 1.9.291 --- web/version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/version b/web/version index 47d6740bf5..68d05d0d27 100644 --- a/web/version +++ b/web/version @@ -1 +1 @@ -1.9.290 +1.9.291 From 487722b472e5412c8bea55742ee51a5af3caf11e Mon Sep 17 00:00:00 2001 From: LKuemmel Date: Fri, 6 Jan 2023 14:36:52 +0100 Subject: [PATCH 5/6] batterx: fix ids --- packages/modules/common/fault_state.py | 3 ++- packages/modules/devices/batterx/device.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/modules/common/fault_state.py b/packages/modules/common/fault_state.py index e87fd7d93d..8f5c36096a 100644 --- a/packages/modules/common/fault_state.py +++ b/packages/modules/common/fault_state.py @@ -45,13 +45,14 @@ def store_error(self, component_info: ComponentInfo) -> None: if ramdisk: topic = component_type.type_topic_mapping_comp(component_info.type) prefix = "openWB/set/" + topic + "/" - if component_info.id is not None: + if component_info.type != "counter" and component_info.type != "bat": if component_type == "vehicle": prefix += str(component_info.id) + "/socFault" else: prefix += str(component_info.id) + "/fault" else: prefix += "fault" + log.debug(prefix + "Str") pub.pub_single(prefix + "Str", self.fault_str, hostname=component_info.hostname) pub.pub_single(prefix + "State", self.fault_state.value, hostname=component_info.hostname) if "chargepoint" in component_info.type: diff --git a/packages/modules/devices/batterx/device.py b/packages/modules/devices/batterx/device.py index 178daa7d05..99566e2bf0 100644 --- a/packages/modules/devices/batterx/device.py +++ b/packages/modules/devices/batterx/device.py @@ -87,9 +87,9 @@ def read_legacy( dev = Device(device_config) dev = _add_component(dev, component_type, num) if evu_counter == "bezug_batterx": - dev = _add_component(dev, "counter", None) + dev = _add_component(dev, "counter", 0) if bat == "speicher_batterx": - dev = _add_component(dev, "bat", None) + dev = _add_component(dev, "bat", 3) log.debug('BatterX IP-Adresse: ' + ip_address) From 4092831f5c8a878de248d0182b0bacbe442ea8f8 Mon Sep 17 00:00:00 2001 From: LKuemmel Date: Fri, 6 Jan 2023 15:46:04 +0100 Subject: [PATCH 6/6] remove unneccessary log msg --- packages/modules/common/fault_state.py | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/modules/common/fault_state.py b/packages/modules/common/fault_state.py index 8f5c36096a..c45c25243e 100644 --- a/packages/modules/common/fault_state.py +++ b/packages/modules/common/fault_state.py @@ -52,7 +52,6 @@ def store_error(self, component_info: ComponentInfo) -> None: prefix += str(component_info.id) + "/fault" else: prefix += "fault" - log.debug(prefix + "Str") pub.pub_single(prefix + "Str", self.fault_str, hostname=component_info.hostname) pub.pub_single(prefix + "State", self.fault_state.value, hostname=component_info.hostname) if "chargepoint" in component_info.type: