ned-kelly / docker-voltronic-homeassistant

Programmatically read data from your Voltronic, Axpert, Mppsolar PIP, Voltacon, Effekta etc Inverter and send it to Home Assistant via MQTT - Works with RS232 & USB!
GNU General Public License v3.0
257 stars 140 forks source link

inverter.cpp: avoid mess with simultaneous read/write operations #77

Open dilyanpalauzov opened 2 years ago

dilyanpalauzov commented 2 years ago

When many inverter_poller at the same time send commands, the result is undefined.

This locks exclusively the configuration file, while the process is running, so that simultaneous instances have to wait until the file is released.

For some reason locking the device /dev/hidraw0 does not work for me, I get sometimes the output from previous runs. I suspect that when cInverter::query() does exceed the 2s timeout, it quits, and leaves the response of its commands on the wire. For fd = /dev/hidraw0: tcflush(fd, TCOFLUSH); has no effect.

As a matter of fact, on my system I have increased the timeout in cInverter::query() to 15s and now it does always work correctly.

Also the program, when called with -1, could exit, while the thread is receiving data, this leaves the next invocation with some ready-data, which it is not expecting.

ned-kelly commented 1 year ago

HI @dilyanpalauzov is there any chance you could add all your fixes and improvements as one PR and i'll approve it.

Unfortunately I don't have an inverter to test on anymore (Am getting another one soon - the last one died (again)) so if anyone else is also able to test that would be appreciated.

Cheers,