Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions data/config/mosquitto/local/openwb_local.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# openwb-version:19
# openwb-version:23
listener 1886 localhost
allow_anonymous true

Expand Down Expand Up @@ -28,6 +28,15 @@ topic openWB/chargepoint/+/get/# out 2
topic openWB/chargepoint/+/config/# out 2
topic openWB/chargepoint/template/# out 2

topic openWB/consumer/get/# out 2

topic openWB/consumer/+/module out 2
topic openWB/consumer/+/config out 2
topic openWB/consumer/+/extra_meter out 2
topic openWB/consumer/+/usage out 2
topic openWB/consumer/+/get/# out 2
topic openWB/consumer/+/set/# out 2

topic openWB/internal_chargepoint/# out 2

topic openWB/io/# out 2
Expand All @@ -52,7 +61,7 @@ topic openWB/optional/# out 2

topic openWB/counter/config/# out 2
topic openWB/counter/set/# out 2
topic openWB/counter/get/hierarchy out 2
topic openWB/counter/get/# out 2
topic openWB/counter/+/module/# out 2
topic openWB/counter/+/config/# out 2
topic openWB/counter/+/get/# out 2
Expand Down
128 changes: 125 additions & 3 deletions data/config/mosquitto/public/default-dynamic-security.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"anonymousGroup": "anonymous",
"roles": [
{
"rolename": "openwb-version:8",
"rolename": "openwb-version:9",
"textname": "openWB Versionsnummer",
"textdescription": "Diese Rolle ist ein Platzhalter für die openWB Versionsnummer und wird automatisch aktualisiert. Sie hat keine direkten Berechtigungen.",
"acls": []
Expand Down Expand Up @@ -1051,7 +1051,13 @@
},
{
"acltype": "publishClientSend",
"topic": "openWB/set/general/chargemode_config/pv_charging/feed_in_yield",
"topic": "openWB/set/general/chargemode_config/pv_charging/feed_in_limit",
"priority": 0,
"allow": true
},
{
"acltype": "publishClientSend",
"topic": "openWB/general/chargemode_config/feed_in_yield",
"priority": 0,
"allow": true
},
Expand Down Expand Up @@ -1091,6 +1097,24 @@
"priority": 0,
"allow": true
},
{
"acltype": "publishClientSend",
"topic": "openWB/set/general/consumer/config/switch_on_delay",
"priority": 0,
"allow": true
},
{
"acltype": "publishClientSend",
"topic": "openWB/set/general/consumer/config/switch_off_delay",
"priority": 0,
"allow": true
},
{
"acltype": "publishClientSend",
"topic": "openWB/set/general/consumer/config/switch_off_threshold",
"priority": 0,
"allow": true
},
{
"acltype": "publishClientReceive",
"topic": "openWB/system/security/access/SurplusChargeConfiguration",
Expand All @@ -1105,7 +1129,13 @@
},
{
"acltype": "publishClientReceive",
"topic": "openWB/general/chargemode_config/pv_charging/feed_in_yield",
"topic": "openWB/general/chargemode_config/pv_charging/feed_in_limit",
"priority": 0,
"allow": true
},
{
"acltype": "publishClientReceive",
"topic": "openWB/general/chargemode_config/feed_in_yield",
"priority": 0,
"allow": true
},
Expand Down Expand Up @@ -1144,6 +1174,24 @@
"topic": "openWB/general/chargemode_config/pv_charging/switch_off_delay",
"priority": 0,
"allow": true
},
{
"acltype": "publishClientReceive",
"topic": "openWB/general/consumer/config/switch_on_delay",
"priority": 0,
"allow": true
},
{
"acltype": "publishClientReceive",
"topic": "openWB/general/consumer/config/switch_off_delay",
"priority": 0,
"allow": true
},
{
"acltype": "publishClientReceive",
"topic": "openWB/general/consumer/config/switch_off_threshold",
"priority": 0,
"allow": true
}
]
},
Expand Down Expand Up @@ -1508,6 +1556,12 @@
"priority": 0,
"allow": true
},
{
"acltype": "publishClientSend",
"topic": "openWB/set/counter/get/loadmanagement_prios",
"priority": 0,
"allow": true
},
{
"acltype": "publishClientSend",
"topic": "openWB/set/counter/+/config/max_power_errorcase",
Expand Down Expand Up @@ -1562,6 +1616,12 @@
"priority": 0,
"allow": true
},
{
"acltype": "publishClientReceive",
"topic": "openWB/counter/get/loadmanagement_prios",
"priority": 0,
"allow": true
},
{
"acltype": "publishClientReceive",
"topic": "openWB/system/device/+/component/+/config",
Expand Down Expand Up @@ -1703,6 +1763,55 @@
}
]
},
{
"rolename": "consumer-configuration-access",
"textname": "Zugang zu den Verbrauchereinstellungen",
"textdescription": "Erlaubt den Zugang zu den Verbrauchereinstellungen.",
"acls": [
{
"acltype": "publishClientSend",
"topic": "openWB/consumer/+/config",
"priority": 0,
"allow": true
},
{
"acltype": "publishClientSend",
"topic": "openWB/consumer/+/module",
"priority": 0,
"allow": true
},
{
"acltype": "publishClientSend",
"topic": "openWB/consumer/+/usage",
"priority": 0,
"allow": true
},
{
"acltype": "publishClientReceive",
"topic": "openWB/consumer/+/config",
"priority": 0,
"allow": true
},
{
"acltype": "publishClientReceive",
"topic": "openWB/consumer/+/module",
"priority": 0,
"allow": true
},
{
"acltype": "publishClientReceive",
"topic": "openWB/consumer/+/usage",
"priority": 0,
"allow": true
},
{
"acltype": "publishClientReceive",
"topic": "openWB/system/configurable/consumers",
"priority": 0,
"allow": true
}
]
},
{
"rolename": "vehicle-configuration-access",
"textname": "Zugang zu den Fahrzeugeinstellungen",
Expand Down Expand Up @@ -2807,6 +2916,19 @@
}
]
},
{
"rolename": "consumer-sum-access",
"textname": "Leserechte für Verbrauchersummendaten",
"textdescription": "Erlaubt das Empfangen von Daten für die Summe aller Verbraucher.",
"acls": [
{
"acltype": "publishClientReceive",
"topic": "openWB/consumer/get/+",
"priority": 0,
"allow": true
}
]
},
{
"rolename": "tenant-energy-configuration-access",
"textname": "Leserechte für Mieterstromdaten",
Expand Down
56 changes: 56 additions & 0 deletions data/config/mosquitto/public/role-templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,62 @@
"allow": true
}
]
},
{
"rolename": "consumer-<id>-access",
"textname": "Leserechte für Verbraucher <id>",
"textdescription": "Erlaubt das Empfangen von Daten für Verbraucher <id>.",
"acls": [
{
"acltype": "publishClientSend",
"topic": "openWB/set/consumer/<id>/usage",
"priority": 0,
"allow": true
},
{
"acltype": "publishClientSend",
"topic": "openWB/set/command/+/todo/addConsumerSchedulePlan",
"priority": 0,
"allow": true
},
{
"acltype": "publishClientSend",
"topic": "openWB/set/command/+/todo/addConsumerTimePlan",
"priority": 0,
"allow": true
},
{
"acltype": "publishClientReceive",
"topic": "openWB/consumer/<id>/#",
"priority": 0,
"allow": true
}
]
},
{
"rolename": "consumer-<id>-write-access",
"textname": "Schreibrechte für MQTT-Verbraucher <id>",
"textdescription": "Erlaubt das Senden von Daten für Verbraucher <id>.",
"acls": [
{
"acltype": "publishClientSend",
"topic": "openWB/set/mqtt/consumer/<id>/get/#",
"priority": 0,
"allow": true
},
{
"acltype": "publishClientReceive",
"topic": "openWB/set/mqtt/consumer/<id>/get/#",
"priority": 0,
"allow": true
},
{
"acltype": "publishClientReceive",
"topic": "openWB/mqtt/consumer/<id>/#",
"priority": 0,
"allow": true
}
]
},
{
"rolename": "vehicle-<id>-access",
Expand Down
Empty file.
Empty file.
30 changes: 30 additions & 0 deletions docs/samples/sample_consumer/sample_consumer/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from typing import List, Optional

from control.consumer.consumer_data import ConsumerUsage
from helpermodules.auto_str import auto_str
from modules.common.consumer_setup import ConsumerSetup
from ..vendor import vendor_descriptor


@auto_str
class SampleConsumerConfiguration:
def __init__(self,
ip_address: Optional[str] = None,
port: Optional[int] = 502,
modbus_id: Optional[int] = 1):
self.ip_address = ip_address
self.port = port
self.modbus_id = modbus_id


@auto_str
class SampleConsumer(ConsumerSetup[SampleConsumerConfiguration]):
def __init__(self,
name: str = "Sample Consumer",
type: str = "sample_consumer",
id: int = 0,
configuration: SampleConsumerConfiguration = None,
usage: List[ConsumerUsage] = [ConsumerUsage.SUSPENDABLE_TUNABLE,
ConsumerUsage.METER_ONLY]) -> None:
super().__init__(name, type, id, vendor=vendor_descriptor.configuration_factory(
).type, configuration=configuration or SampleConsumerConfiguration(), usage=usage)
77 changes: 77 additions & 0 deletions docs/samples/sample_consumer/sample_consumer/consumer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env python3
from enum import IntEnum
import logging
from modules.common.abstract_device import DeviceDescriptor
from modules.common.component_state import ConsumerState
from modules.common.configurable_consumer import ConfigurableConsumer
from modules.common.modbus import ModbusDataType, ModbusTcpClient_
from modules.common.simcount._simcounter import SimCounterConsumer
from modules.consumers.askoma.askoheat.config import SampleConsumer

log = logging.getLogger(__name__)


class Register(IntEnum):
POWER = 1000
TEMP0 = 1001
TEMP1 = 1030
TEMP2 = 1031
STATUS = 1003


REG_MAPPING = (
(Register.POWER, [ModbusDataType.INT_16]),
(Register.TEMP0, [ModbusDataType.INT_16]),
(Register.TEMP1, [ModbusDataType.INT_16]),
(Register.TEMP2, [ModbusDataType.INT_16]),
(Register.STATUS, ModbusDataType.INT_16),
)


def create_consumer(config: SampleConsumer):
client = None
sim_counter = None

def initializer():
nonlocal client, sim_counter
client = ModbusTcpClient_(config.configuration.ip_address, config.configuration.port)
sim_counter = SimCounterConsumer(config.id, ComponentType.CONSUMER)

def error_handler() -> None:
initializer()

def update() -> ConsumerState:
nonlocal client, sim_counter
resp = client.read_holding_registers_bulk(
Register.POWER, 35, mapping=REG_MAPPING, unit=config.configuration.modbus_id)
imported, exported = sim_counter.sim_count(resp[Register.POWER])
return ConsumerState(
power=resp[Register.POWER],
imported=imported,
exported=exported,
temperatures=[resp[Register.TEMP0]/10, resp[Register.TEMP1]/10, resp[Register.TEMP2]/10]
)

def set_limit(power_limit: float) -> None:
nonlocal client
client.write_registers(1000, power_limit, unit=config.configuration.modbus_id)

# ODER

def switch_on() -> None:
nonlocal client
client.write_registers(1000, 1, unit=config.configuration.modbus_id)

def switch_off() -> None:
nonlocal client
client.write_registers(1000, 0, unit=config.configuration.modbus_id)
return ConfigurableConsumer(consumer_config=config,
initializer=initializer,
error_handler=error_handler,
update=update,
set_power_limit=set_limit,
switch_on=switch_on,
switch_off=switch_off)


device_descriptor = DeviceDescriptor(configuration_factory=SampleConsumer)
Loading