Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloud Client #1166

Merged
merged 8 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Binary file added runs/lt
kevinwieland marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
28 changes: 27 additions & 1 deletion runs/remoteSupport/remoteSupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
BASE_TOPIC = "openWB-remote/"
REMOTE_SUPPORT_TOPIC = BASE_TOPIC + "support"
REMOTE_PARTNER_TOPIC = BASE_TOPIC + "partner"
CLOUD_TOPIC = BASE_TOPIC + "cloud"
support_tunnel: Popen = None
partner_tunnel: Popen = None

Expand Down Expand Up @@ -51,6 +52,7 @@ def is_tunnel_closed(tunnel: Popen) -> bool:

global support_tunnel
global partner_tunnel
global cloud_tunnel
payload = msg.payload.decode("utf-8")
if len(payload) > 0:
log.debug("Topic: %s, Message: %s", msg.topic, payload)
Expand All @@ -75,7 +77,6 @@ def is_tunnel_closed(tunnel: Popen) -> bool:
f"{port}:localhost:22", f"{user}@remotesupport.openwb.de"])
log.info(f"tunnel running with pid {support_tunnel.pid}")
else:
log.info("unknown message: " + payload)
kevinwieland marked this conversation as resolved.
Show resolved Hide resolved
elif msg.topic == REMOTE_PARTNER_TOPIC:
if payload == 'stop':
if partner_tunnel is None:
Expand All @@ -101,6 +102,31 @@ def is_tunnel_closed(tunnel: Popen) -> bool:
log.info(f"tunnel running with pid {partner_tunnel.pid}")
else:
log.info("unknown message: " + payload)
elif msg.topic == CLOUD_TOPIC:
log.info("1")
kevinwieland marked this conversation as resolved.
Show resolved Hide resolved
if payload == 'stop':
if cloud_tunnel is None:
log.error("received stop cloud message but tunnel is not running")
else:
log.info("stop cloud tunnel")
cloud_tunnel.terminate()
cloud_tunnel.wait(timeout=3)
cloud_tunnel = None
elif re.match(r'^([^;]+)(?:;([a-zA-Z0-9]+)(?:;([a-zA-Z0-9]+))?)?$', payload):
#elif payload != 'stio':
kevinwieland marked this conversation as resolved.
Show resolved Hide resolved
if is_tunnel_closed(partner_tunnel):
kevinwieland marked this conversation as resolved.
Show resolved Hide resolved
splitted = payload.split(";")
if len(splitted) != 3:
log.error("invalid number of settings received!")
else:
token = splitted[0]
cloudnode = splitted[1]
user = splitted[2]
log.info("start cloud tunnel" + token + cloudnode)
cloud_tunnel = Popen(["/var/www/html/openWB/runs/lt", "-h", "https://" + cloudnode + ".openwb.de/", "-p", "80", "-s", token])
kevinwieland marked this conversation as resolved.
Show resolved Hide resolved
log.info(f"cloud tunnel running with pid {cloud_tunnel.pid}")
else:
log.info("unknown message: " + payload)
# clear topic
client.publish(msg.topic, "", qos=2, retain=True)

Expand Down