36 lines
970 B
Python
36 lines
970 B
Python
from pythonosc.dispatcher import Dispatcher
|
|
from pythonosc.osc_server import BlockingOSCUDPServer
|
|
import threading
|
|
import time
|
|
|
|
latest_value = None
|
|
lock = threading.Lock()
|
|
|
|
def handle_value(address, *args):
|
|
global latest_value
|
|
with lock:
|
|
latest_value = args
|
|
|
|
def printer_loop():
|
|
global latest_value
|
|
while True:
|
|
time.sleep(1)
|
|
with lock:
|
|
if latest_value is not None:
|
|
print(f"Latest value: {latest_value}")
|
|
latest_value = None # Clear after printing
|
|
|
|
if __name__ == "__main__":
|
|
dispatcher = Dispatcher()
|
|
dispatcher.map("/tcp_coordinates", handle_value)
|
|
|
|
ip = "0.0.0.0" # Listen on all interfaces
|
|
port = 7000 # Adjust if needed
|
|
server = BlockingOSCUDPServer((ip, port), dispatcher)
|
|
|
|
# Start printing thread
|
|
threading.Thread(target=printer_loop, daemon=True).start()
|
|
|
|
print(f"Listening for OSC messages on {ip}:{port} ...")
|
|
server.serve_forever()
|