Parking Finder
The Parking Finder system is a smart parking solution designed to help drivers efficiently locate available
Loading...
Searching...
No Matches
server.py
1import asyncio
2import websockets
3import csv
4import json
5
6PORT = 8765
7CSV_FILE = "./src/Dashboard/src/backend/coordinates.csv"
8
9async def send_coordinates(websocket):
10 print("Client connected")
11
12 while True:
13 with open(CSV_FILE, newline='') as csvfile:
14 reader = csv.DictReader(csvfile)
15
16 for row in reader:
17 data = {
18 "lat": float(row["lat"]),
19 "long": float(row["long"])
20 }
21
22 await websocket.send(json.dumps(data))
23 print("Sent:", data)
24
25 await asyncio.sleep(0.6) # 0.5 second timer
26
27 # Loop back to beginning of file
28
29async def main():
30 async with websockets.serve(send_coordinates, "localhost", PORT):
31 print(f"WebSocket server running on ws://localhost:{PORT}")
32 await asyncio.Future() # run forever
33
34asyncio.run(main())