Files
flucto-heisskleber/heisskleber/mqtt/forwarder.py
Felix Weiler 774e0d8496 Breaking: Change signatures of Publisher.send and Subscriber.__init__.
This commit is a lot and adds breaking changes.
Also adds a UDP subscriber and publisher.
2023-11-07 12:41:07 +01:00

24 lines
610 B
Python

from heisskleber import get_publisher, get_subscriber
from heisskleber.config import load_config
from .config import MqttConf
def map_topic(zmq_topic: str, mapping: str) -> str:
return mapping + zmq_topic
def main() -> None:
config: MqttConf = load_config(MqttConf(), "mqtt")
sub = get_subscriber("zmq", config.topics)
pub = get_publisher("mqtt")
pub.pack = lambda x: x # type: ignore
sub.unpack = lambda x: x # type: ignore
while True:
(zmq_topic, data) = sub.receive()
mqtt_topic = map_topic(zmq_topic, config.mapping)
pub.send(data, mqtt_topic)