dirigera icon indicating copy to clipboard operation
dirigera copied to clipboard

Event Listener eventually dies due to inactivity

Open vaylvn opened this issue 1 year ago • 1 comments

Hello there,

I've been tinkering trying to figure out why my script was dying out on me after a few hours, which while the script hadn't terminated it was no longer printing anything from prompts to the hub from my controllers, sensors, etc.

I've a timer that periodically checks the status of the sensors which I assume is still functioning, however it seems the event listener stops being active after some time.

I see a previous post regarding a similar issue though it's since closed, is there any particular thing I should be doing to keep this event listener active?

vaylvn avatar Sep 17 '24 21:09 vaylvn

Hey @ValonVN0 sorry that you are having issues. Can you try the following code and verify if that also has the issue of silently disconnecting?


import os
import ssl
import websocket


token = "dirigera-token"
ip_address = "ip-address"

websocket_base_url = f"wss://{ip_address}:8443/v1"

def on_message(ws, message):
    print(message)

wsapp = websocket.WebSocketApp(
    websocket_base_url,
    header={"Authorization": f"Bearer {token}"},
    on_message=on_message,  # whatever you need here
)

wsapp.run_forever(
    sslopt={"cert_reqs": ssl.CERT_NONE},
    ping_interval=60,
    reconnect=1,  # this is the interesting parameter for you
)

My hopes are that by setting reconnect to 1, it should try to reconnect after 1 second if it loses the connection.

Leggin avatar Sep 18 '24 19:09 Leggin