39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
import sseclient
|
|
import time
|
|
import requests
|
|
|
|
# Direct internal network address
|
|
TELL_URL = "http://PC17488:22222/events"
|
|
|
|
|
|
def listen_to_events():
|
|
print(f"Connecting to SSE on internal network: {TELL_URL}")
|
|
|
|
while True:
|
|
try:
|
|
# We use stream=True for the persistent SSE connection
|
|
response = requests.get(TELL_URL, stream=True, timeout=None)
|
|
response.raise_for_status()
|
|
|
|
client = sseclient.SSEClient(response)
|
|
|
|
print("Successfully connected to TELL. Waiting for events...")
|
|
|
|
for event in client.events():
|
|
timestamp = time.strftime("%H:%M:%S")
|
|
print(f"[{timestamp}] {event.event}: {event.data}")
|
|
|
|
except requests.exceptions.ConnectionError:
|
|
print(f"Error: Could not reach {TELL_URL}. Check if PC17488 is online.")
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
|
|
print("Retrying in 5 seconds...")
|
|
time.sleep(5)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
listen_to_events()
|
|
except KeyboardInterrupt:
|
|
print("\nStopped.") |