From 16fe7a33800344d3c4128157afcb276d9d9cfb15 Mon Sep 17 00:00:00 2001 From: shinedday <shinedday@gmail.com> Date: Mon, 9 May 2022 11:40:12 +0200 Subject: [PATCH] Add ping to the ihm to check if the raspberry's are available --- README.md | 5 ----- ihm.py | 18 +++++++++++++++++- philosophers/amas.py | 5 +++-- tool/config.json | 15 +++++++++++++++ 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index eb44f40..5f8af0f 100644 --- a/README.md +++ b/README.md @@ -40,11 +40,6 @@ WSL (pour pouvoir démarer l'amas) # Random note -Programme de la semaine : - * Surcouche mqtt pour le framework - * décision dela forme du framewor (module python ?) - * Implementation d'un 2nd example - Start procédure : 1. start broker diff --git a/ihm.py b/ihm.py index ef306fc..2447346 100644 --- a/ihm.py +++ b/ihm.py @@ -3,9 +3,14 @@ from subprocess import Popen from os import path from time import sleep +import platform # For getting the operating system name +import subprocess # For executing a shell command + +import pathlib + +from tool.confi_reader import read_ssh from tool.mqtt_client import MqttClient from tool.ssh_client import SSHClient, Cmd -from tool.remote_client import RemoteClient from tool.update import VersionManager class Ihm(MqttClient, SSHClient): @@ -116,6 +121,17 @@ class Ihm(MqttClient, SSHClient): if cmd.lower() in ["s", "step"]: self.client.publish("ihm/step") + if cmd.lower() == "ping": + + for client in read_ssh(str(pathlib.Path(__file__).parent.resolve())+"/tool/config.json") : + + param = '-n' if platform.system().lower() == 'windows' else '-c' + command = ['ping', param, '1', client.hostname] + + result = subprocess.call(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0 + + print("Hostname :", client.hostname, " Responded : ", result) + self.client.publish("ihm/step") sleep(2) diff --git a/philosophers/amas.py b/philosophers/amas.py index 5422fc3..060ace3 100644 --- a/philosophers/amas.py +++ b/philosophers/amas.py @@ -29,8 +29,9 @@ class PhiAmas(Amas): self.client.publish("amas/agent/new", self.next_id) self.next_id += 1 - self.run_cmd(0, agents) - # self.run_cmd(1, agents[2:]) + self.run_cmd(0, [agents[0]]) + self.run_cmd(1, [agents[1]]) + self.run_cmd(2, [agents[2]]) if __name__ == '__main__': s = PhiAmas(3) diff --git a/tool/config.json b/tool/config.json index 3d54d65..a8df663 100644 --- a/tool/config.json +++ b/tool/config.json @@ -5,6 +5,21 @@ "hostname" : "192.168.24.18", "user" : "pi", "password" : "raspberry" + }, + { + "hostname" : "192.168.24.61", + "user" : "pi", + "password" : "raspberry" + }, + { + "hostname" : "192.168.24.227", + "user" : "pi", + "password" : "raspberry" + }, + { + "hostname" : "192.168.24.75", + "user" : "pi", + "password" : "raspberry" } ] } \ No newline at end of file -- GitLab