From 910c22554272136948b1166478dc771c656e5410 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Sun, 18 May 2025 22:10:14 +1200 Subject: [PATCH] Inital working version --- main.py | 5 ++++- networking.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 276c6b8..67faaae 100644 --- a/main.py +++ b/main.py @@ -6,13 +6,15 @@ from async_tkinter_loop import async_handler, async_mainloop from networking import send_to_server import color_utils +bg_color="#2e2e2e" + class App: def __init__(self) -> None: self.root = tk.Tk() self.root.attributes('-fullscreen', True) # List of servers (IP, Port) - self.servers = [("192.168.0.206", 80), ("192.168.0.208", 80)] + self.servers = [("192.168.0.208", 80),("192.168.0.201", 80), ("192.168.0.202", 80), ("192.168.0.203", 80), ("192.168.0.206", 80)] # Create Notebook for tabs self.notebook = ttk.Notebook(self.root) @@ -25,6 +27,7 @@ class App: self.notebook.add(tab, text=f"{server[0]}:{server[1]}") self.create_sliders(tab) self.tabs[server] = tab + #self.root.configure(bg=bg_color) async_mainloop(self.root) diff --git a/networking.py b/networking.py index 4a6065a..e0fabcc 100644 --- a/networking.py +++ b/networking.py @@ -1,5 +1,7 @@ import socket import asyncio +import httpx +from websockets import connect async def send_color_data(color_data, servers): """Send color data to all configured servers.""" @@ -18,3 +20,34 @@ async def send_to_server(color_data, server): print(f"Sent data to {server_ip}:{server_port}") except (socket.error, ConnectionError) as e: print(f"Error sending to {server_ip}:{server_port}: {e}") + + +async def post(server, endpoint, data=""): + async with httpx.AsyncClient() as client: + r = await client.post(f"http://{server}/{endpoint}", data=data) + print(server, r) + + + +async def main(): + + b = bytearray(180) + try: + ws1 = await connect("ws://10.1.1.200/external") + await asyncio.gather(post("10.1.1.200", "pattern", "external")) + while True: + print("sync") + + for i in range(len(b)): + b[i] = 128 + await asyncio.gather(ws1.send(b)) + await asyncio.sleep(5) + finally: + await ws1.close() + await asyncio.gather(post("10.1.1.200", "pattern", "off")) + + + + +if __name__ == "__main__": + asyncio.run(main())