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 2 commits
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 @@ -7,12 +7,14 @@

kevinwieland marked this conversation as resolved.
Show resolved Hide resolved
BASE_PATH = Path(__file__).resolve().parents[2]
RAMDISK_PATH = BASE_PATH / "ramdisk"
LT_PATH = BASE_PATH / "runs/lt"
kevinwieland marked this conversation as resolved.
Show resolved Hide resolved
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

cloud_tunnel: Popen = None
logging.basicConfig(
filename=str(RAMDISK_PATH / "remote_support.log"),
level=logging.INFO, format='%(asctime)s: %(message)s'
Expand Down Expand Up @@ -51,6 +53,7 @@

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 Down Expand Up @@ -101,6 +104,29 @@
log.info(f"tunnel running with pid {partner_tunnel.pid}")
else:
log.info("unknown message: " + payload)
elif msg.topic == CLOUD_TOPIC:
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):
if is_tunnel_closed(cloud_tunnel):
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([LT_PATH, "-h", "https://" + cloudnode + ".openwb.de/", "-p", "80", "-s", token])

Check failure on line 126 in runs/remoteSupport/remoteSupport.py

View workflow job for this annotation

GitHub Actions / build

line too long (126 > 120 characters)
log.info(f"cloud tunnel running with pid {cloud_tunnel.pid}")
kevinwieland marked this conversation as resolved.
Show resolved Hide resolved
else:
log.info("unknown message: " + payload)
# clear topic
client.publish(msg.topic, "", qos=2, retain=True)

Expand Down
Loading