-
Notifications
You must be signed in to change notification settings - Fork 36
solarman_rtu_proxy.py: improve runtime stability #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Hi, The problem is caused by the Pysolarman initialization for each new client/connection which at some point leads to semaphore exhaustion (according to the linked posts). Modification of the proxy to use a single instance of Pysolarman should fix it. |
Hi, Can you try this version of the proxy on |
Hi @githubDante,
I got slightly further with f889e55, but the reconnect does not work:
|
evcc supports the Solarman protocol? |
No, it uses Modbus RTU over TCP which is why I am running |
Ah, I mixed up the proxy "type", my bad. :) |
This doesn't sounds good. Maybe I missed something. I will check and update when I have more info. |
Yup, can confirm:
Edit: And wireshark doesn't show any comm proxy <-> logger, only client <-> proxy. |
The connect call was missing. The branch has been updated. I will try to test in docker as well. |
👍 |
Also a fix for the reconnect issue has been added. @ngehrsitz can you try again. Thank you in advance. |
asyncio.run(run_proxy(args.bind, args.port, args.logger, args.serial)) | ||
except Exception as e: | ||
print(f"Exception: {e}") | ||
sys.exit(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is completely unnecessary call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also thaught that an expection should cause a crash of the script with a non-zero exit code.
But that was not the case, instead it kept prinitng the exception. I suspect this has something to do with how these scripts are made executable
Lines 18 to 22 in 8b60764
[project.scripts] | |
solarman-decoder = "utils.solarman_decoder:main" | |
solarman-rtu-proxy = "utils.solarman_rtu_proxy:main" | |
solarman-scan = "utils.solarman_scan:main" | |
solarman-uni-scan = "utils.solarman_uni_scan:main" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm.. 🤔
It starts now. Let´s see if it is stable. Usually crashes occur after one or two days of runtime |
@githubDante There is still some sort of locking issue. The client can only get data on the first connection. As soon as you reconnect, it stops working. |
Hi, I don't see it locked in my test environment, but I have to admit that I'm using a simple echo server simulating the datalogger socket. Just added lower socket timeout during the initialization and extra exception handling to avoid locking by a real datalogger while the proxy is waiting for a response from it (the lock can be held for too long with the default settings).
Don't know, it's just a habbit, I guess.
For control over the PySolarman instance. Since the handle_client method is the main driving force of the proxy we can check the state of PySolarman when a new client is connected and prepare it to serve the requests which the client will start issuing in the next moment, otherwise extra effort should be made elsewhere (extra methods or tasks in the asyncio loop that need to check its state)
It's basically the same at runtime - single connect (_solarman_init is like a singleton) and then state condition checks via _solarman_connect. |
When running
solarman_rtu_proxy.py
from the docker container contineously I encountered a crash loop:This PR:
https://gitlab.alpinelinux.org/alpine/aports/-/issues/15651