Skip to content

Commit

Permalink
Merge pull request #1166 from openWB/cloudclient
Browse files Browse the repository at this point in the history
Cloud Client
  • Loading branch information
kevinwieland authored Oct 16, 2023
2 parents 3bb99d7 + 2736f7f commit 726ec51
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Binary file added runs/lt-armv7l_ELF
Binary file not shown.
Binary file added runs/lt-x86_64_ELF
Binary file not shown.
47 changes: 46 additions & 1 deletion runs/remoteSupport/remoteSupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
from subprocess import Popen
from pathlib import Path
import paho.mqtt.client as mqtt
import platform

BASE_PATH = Path(__file__).resolve().parents[2]
RAMDISK_PATH = BASE_PATH / "ramdisk"
RUNS_PATH = BASE_PATH / "runs"
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 +54,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 Down Expand Up @@ -101,6 +105,47 @@ 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:
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]
cloud_node = splitted[1]
user = splitted[2]

machine = platform.machine()
bits, linkage = platform.architecture()
lt_executable = f"lt-{machine}_{linkage}"

log.info("System Info:")
log.info(f"Architecture: ({(bits, linkage)})")
log.info(f"Machine: {machine}")
log.info(f"Node: {platform.node()}")
log.info(f"Platform: {platform.platform()}")
log.info(f"System: {platform.system()}")
log.info(f"Release: {platform.release()}")
log.info(f"using binary: '{lt_executable}'")

log.info("start cloud tunnel" + token + cloud_node)
try:
cloud_tunnel = Popen([f"{RUNS_PATH}/{lt_executable}", "-h",
"https://" + cloud_node + ".openwb.de/", "-p", "80", "-s", token])
log.info(f"cloud tunnel running with pid {cloud_tunnel.pid}")
except FileNotFoundError:
log.exception(f"executable '{lt_executable}' does not exist!")
else:
log.info("unknown message: " + payload)
# clear topic
client.publish(msg.topic, "", qos=2, retain=True)

Expand Down

0 comments on commit 726ec51

Please sign in to comment.