diff --git a/dist/iotAmak-0.0.7-py3-none-any.whl b/dist/iotAmak-0.0.7-py3-none-any.whl index 6b8729469c70282fe1274145a88acef11cfe9f1a..744cb9dfed1ef86c93b444d4867458e6f5593247 100644 Binary files a/dist/iotAmak-0.0.7-py3-none-any.whl and b/dist/iotAmak-0.0.7-py3-none-any.whl differ diff --git a/iotAmak/agent/agent.py b/iotAmak/agent/agent.py index 4af7fb9e13b14583ade030d795f85664a4d72f49..9cbf8c53977fa257f3385508d807b0fd176ee8ea 100644 --- a/iotAmak/agent/agent.py +++ b/iotAmak/agent/agent.py @@ -64,5 +64,6 @@ class Agent(Schedulable, BaseAgent): self.on_cycle_end() self.publish("metric", str(self.send_metric())) + self.publish("canvas", str(self.to_canvas())) self.publish("cycle_done", "") self.nbr_cycle += 1 diff --git a/iotAmak/agent/async_agent.py b/iotAmak/agent/async_agent.py index a2653d552e6e29ca63e450d1a5103fe6dafeb169..58543c0b4ec1ce9ed9f3641dfb1edd9928e76ee8 100644 --- a/iotAmak/agent/async_agent.py +++ b/iotAmak/agent/async_agent.py @@ -54,4 +54,5 @@ class AsyncAgent(AsyncControlable, BaseAgent): self.on_act() self.on_cycle_end() self.publish("metric", str(self.send_metric())) + self.publish("canvas", str(self.to_canvas())) diff --git a/iotAmak/agent/base_agent.py b/iotAmak/agent/base_agent.py index 4d31dd2b8c7a1f3aefa598139eaf385604cf6749..3bdd006f52b9dc4db6e191ec7a206f61e9307def 100644 --- a/iotAmak/agent/base_agent.py +++ b/iotAmak/agent/base_agent.py @@ -74,6 +74,17 @@ class BaseAgent: "[AGENT] " + str(self.id) + " : " + message ) + def to_canvas(self) -> dict: + """ + To override if the canvas is used, automatically called each cycle + the dict must contains : + * 'x', 'y' keys -> int values + * 'id' of the agent (self.id) -> int value + * 'color' in hex -> str (e.g. '#FF0000') + * 'cycle' self.nbr_cycle -> int + """ + return {} + def send_metric(self) -> Dict: """ Should be override if the neighbor need to be aware of any other info, should be a dict diff --git a/iotAmak/amas/base_amas.py b/iotAmak/amas/base_amas.py index c3da4e0e80706e5ed92560374f6ce4f0a9987ccf..7b34bd2633942abd176eac7fe392b9d82babc7d8 100644 --- a/iotAmak/amas/base_amas.py +++ b/iotAmak/amas/base_amas.py @@ -92,19 +92,21 @@ class BaseAmas(SSHClient): if len(self.agents_cmd[i_min]) > len(self.agents_cmd[elem]): i_min = elem self.agents_cmd[i_min].append(Cmd(command)) + self.client.publish("amas/agent/new", str({"id": self.next_id, "ip": i_min})) else: have_found = False for i_client in range(len(self.clients)): if self.clients[i_client].hostname == client_ip: self.agents_cmd[i_client].append(Cmd(command)) + self.client.publish("amas/agent/new", str({"id": self.next_id, "ip": i_client})) have_found = True break if not have_found: self.agents_cmd[0].append(Cmd(command)) + self.client.publish("amas/agent/new", str({"id": self.next_id, "ip": 0})) self.subscribe("agent/" + str(self.next_id) + "/metric", self.agent_metric) - self.client.publish("amas/agent/new", self.next_id) self.next_id += 1 def push_agent(self) -> None: diff --git a/iotAmak/scheduler/scheduler.py b/iotAmak/scheduler/scheduler.py index d5f22374b54becec8fafe7c8fb8cb96e23852200..df01367b4e64095ff551db8261fb5a0771893cff 100644 --- a/iotAmak/scheduler/scheduler.py +++ b/iotAmak/scheduler/scheduler.py @@ -1,6 +1,7 @@ """ Scheduler class file """ +from ast import literal_eval from threading import Semaphore from time import sleep, time @@ -67,7 +68,10 @@ class Scheduler(Schedulable): param message: id of the new agent """ self.nbr_agent += 1 - self.subscribe("agent/" + str(message.payload.decode("utf-8")) + "/cycle_done", self.agent_done) + self.subscribe( + "agent/" + literal_eval(message.payload.decode("utf-8")).get("id") + "/cycle_done", + self.agent_done) + # print("__Update agent : ", self.nbr_agent, str(message.payload.decode("utf-8"))) def agent_done(self, client, userdata, message) -> None: