initial commit
This commit is contained in:
commit
c6961c03c3
33 changed files with 1782 additions and 0 deletions
62
stratoflights_api/ws_client.py
Normal file
62
stratoflights_api/ws_client.py
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import asyncio
|
||||
import json
|
||||
import websockets
|
||||
import uuid
|
||||
import time
|
||||
|
||||
BASE_URL = "ws://localhost:8000/api/ws"
|
||||
TOKEN = "ae397229f9ca50cd6320cb0416671ecc780671ac"
|
||||
PK = "cf1e36ff-c5ce-4852-8b90-046737974b97"
|
||||
|
||||
async def satellite_mode():
|
||||
"""
|
||||
Клиент для отправки данных телеметрии.
|
||||
"""
|
||||
url = f"{BASE_URL}/satellite/{PK}/telemetry/?token={TOKEN}"
|
||||
async with websockets.connect(url) as ws:
|
||||
print(f"[satellite] Connected to {url}")
|
||||
|
||||
while True:
|
||||
telemetry_data = {
|
||||
"timestamp": int(time.time()),
|
||||
"lat": 55.75,
|
||||
"lon": 37.61,
|
||||
"alt": 200.0,
|
||||
"payload": {"temp": 22.5, "status": "OK"},
|
||||
"raw_data": {"sensor": "gps", "accuracy": "high"}
|
||||
}
|
||||
await ws.send(json.dumps(telemetry_data))
|
||||
print(f"[satellite] Sent: {telemetry_data}")
|
||||
|
||||
try:
|
||||
response = await asyncio.wait_for(ws.recv(), timeout=2)
|
||||
print(f"[satellite] Received: {response}")
|
||||
except asyncio.TimeoutError:
|
||||
print("[satellite] No response yet")
|
||||
|
||||
await asyncio.sleep(5)
|
||||
|
||||
|
||||
async def station_mode():
|
||||
"""
|
||||
Клиент для приёма данных телеметрии.
|
||||
"""
|
||||
url = f"{BASE_URL}/station/{PK}/telemetry/?token={TOKEN}"
|
||||
async with websockets.connect(url) as ws:
|
||||
print(f"[station] Connected to {url}")
|
||||
|
||||
while True:
|
||||
try:
|
||||
message = await ws.recv()
|
||||
print(f"[station] Received: {message}")
|
||||
except websockets.ConnectionClosed:
|
||||
print("[station] Connection closed")
|
||||
break
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
mode = input("Enter mode (satellite/station): ").strip().lower()
|
||||
if mode == "satellite":
|
||||
asyncio.run(satellite_mode())
|
||||
else:
|
||||
asyncio.run(station_mode())
|
||||
Loading…
Add table
Add a link
Reference in a new issue