Skip to content
Snippets Groups Projects
Commit 16fe7a33 authored by shinedday's avatar shinedday
Browse files

Add ping to the ihm to check if the raspberry's are available

parent 12d638cd
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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)
......
......@@ -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)
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment