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 all 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-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

kevinwieland marked this conversation as resolved.
Show resolved Hide resolved
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