diff --git a/ground-station.py b/ground-station.py index e218ea7..04c3f1c 100644 --- a/ground-station.py +++ b/ground-station.py @@ -2,8 +2,10 @@ import asyncio from websockets.server import serve +from datetime import datetime ADMIN_ID = "1234" +BOAT_DATA_INTERVAL_MAX = 0.1 # seconds BOAT_STATE_INCTRL = 2 BOAT_STATE_AVAILABLE = 1 @@ -113,7 +115,9 @@ async def on_message(message, client): print("WARN: controll cmd (" + client['id'] + ") to None: " + data[2]) else: print("INFO: controll cmd (" + client['id'] + ") to " + client['boat']['name'] + ": " + data[2]) - await client['boat']['ws'].send("d:" + data[2] + "\n") + if client['boat']['lastMsg'] + BOAT_DATA_INTERVAL_MAX < datetime.timestamp(datetime.now()): + await client['boat']['ws'].send("d:" + data[2] + "\n") + client['boat']['lastMsg'] = datetime.timestamp(datetime.now()) else: print("WARN: invalid command (" + client['id'] + "): '" + data[1] + "'") @@ -133,7 +137,7 @@ async def new_client(clientId, ws): async def new_boat(boatId, name, ws): """handler for every new boat connection""" - boat = { "id": boatId, "name": name, "ws": ws, "state": BOAT_STATE_AVAILABLE } + boat = { "id": boatId, "name": name, "ws": ws, "state": BOAT_STATE_AVAILABLE, "lastMsg": 0 } print("new boat connected: " + boatId) for bo in Boats: if bo['id'] == boat['id']: