From bd5eb656e69a6f7a4527482887a0137d00b6db7d Mon Sep 17 00:00:00 2001 From: Arthur Golubtsov Date: Thu, 17 Oct 2019 12:16:11 +0100 Subject: [PATCH] Client: modify set new id function --- Drone/copter_client.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Drone/copter_client.py b/Drone/copter_client.py index 558bcb4..74a4f69 100644 --- a/Drone/copter_client.py +++ b/Drone/copter_client.py @@ -21,6 +21,8 @@ import tf2_ros static_bloadcaster = tf2_ros.StaticTransformBroadcaster() +import threading + # logging.basicConfig( # TODO all prints as logs # level=logging.DEBUG, # INFO # format="%(asctime)s [%(name)-7.7s] [%(threadName)-12.12s] [%(levelname)-5.5s] %(message)s", @@ -99,6 +101,9 @@ class CopterClient(client.Client): def restart_service(name): os.system("systemctl restart {}".format(name)) +def execute_command(command): + os.system(command) + def configure_chrony_ip(ip, path="/etc/chrony/chrony.conf", ip_index=1): try: @@ -182,7 +187,7 @@ def configure_hosts(hostname): def configure_bashrc(hostname): - path = "~/.bashrc" + path = "/home/pi/.bashrc" try: with open(path, 'r') as f: raw_content = f.read() @@ -206,7 +211,7 @@ def configure_bashrc(hostname): return True -@messaging.request_callback("id") +@messaging.message_callback("id") def _response_id(*args, **kwargs): new_id = kwargs.get("new_id", None) if new_id is not None: @@ -219,10 +224,14 @@ def _response_id(*args, **kwargs): configure_hostname(hostname) configure_hosts(hostname) configure_bashrc(hostname) + execute_command("hostname {}".format(hostname)) if client.active_client.RESTART_DHCPCD: + # client.active_client.server_connection._send_response("new_id") restart_service("dhcpcd") - - return client.active_client.client_id + time.sleep(1.) + restart_service("clever") + restart_service("smbd") + restart_service("clever-show") @messaging.request_callback("selfcheck")