Problem with multiple clients use pyroon to connect with the same Roon server
If i use multiple clients (in this case multiple raspberry zero 2w in same local network) to get a connection to a roon server, I get errors like this from roonapi:
ERROR Error while parsing message '<websocket._app.WebSocketApp object at 0x700e0b98>' Traceback (most recent call last): File "/usr/local/lib/python3.9/dist-packages/roonapi/roonapisocket.py", line 127, in on_message message = message.decode("utf-8") AttributeError: 'WebSocketApp' object has no attribute 'decode'
With only one client it's working fine.
Is this a known bug? Do you have a solution or any idea to fix this?
Kind regards
Can you explain a bit more what you’re doing, this is something I haven’t come across before.
I have 8 Roon endpoints on 4 raspberry Pis (running Ropieee) attached to my Roon core, and they all show up and work without issue in Home Assistant.
I also attach two instances of Home Assistant to my Roon core when developing (and so have two instances of the api running) - and that works fine too.
If you are re-using the token between instances of the api, it would be worth trying with a second token. It wouldn’t surprise me if there is an assumption that each connection to the api has its own token.
Maybe I use it wrong. I describe now what I've tested and the results.
The devices had send the same appInfo object with RoonApi call. but i think this is not ok, and every device needs his own appInfo with unique extension_id and/or display_name. Is this right?
I must activate every device in the Roon settings / Extension tab for the first call.
I've changed this so, that every device generates his own appInfo:
appinfo = { "extension_id": "roonmatrix_" + socket.gethostname(), "display_name": "RoonMatrix [" + socket.gethostname() + "]", "display_version": scriptVersion, "publisher": "Stephan Wilhelm", "email": "[email protected]", "website": "https://github.com/eventcatcher/roonmatrix", "unique_id": socket.gethostname(), }
After this change, the error 'while parsing message '<websocket._app.WebSocketApp' is gone.
I've changed the python script so, that on first authentication, the core id and token is saved, and check if this files are exist, read this back into variables on next starts, and send this core_id with token if exist on next RoonApi calls.
But I have observed an inexplicable behavior in connection check with RoonDiscovery. When starting the first device, everything is ok. The server ip and port are always found. When starting the second device, on this 2nd device the ip and port are often only found after several attempts. At some point it works. If i called RoonDiscovery again and again at intervals of e.g. 20 seconds, i actually always get an empty result, i.e. no servers are found. It doesn't matter whether I find the servers with discover.all(), discover.first(), or with RoonDiscovery(None) or RoonDiscovery(core_id).
What kind of problem can this be? Am I doing something wrong?
Previously I had used RoonDiscovery to check whether the server was still accessible. I have now replaced this with a socket connect, where the port is checked on an ip. This would of course be more elegant with RoonDiscovery, because I need to know the ip and port for socket connect.