konstantinblaesi / sma-yasdi-logger

Read the channels of SMA inverters using the SMA YASDI SDK and publish their values to an MQTT broker.
GNU General Public License v3.0
0 stars 0 forks source link

Execution stucks after device detection #1

Closed pkwagner closed 4 years ago

pkwagner commented 4 years ago

I'm currently trying to set up this project using Docker on a Raspberry Pi. Unfortunately, after finishing the device discovery nothing happens. For me this seems like a missed callback, but I didn't deep-dive into the yasdi library yet.

Is this a known bug and if, is there any workaround? yasdishell works properly inside the container and lists all devices, channels and values correctly.

SMA Logger --- Data logger for SMA inverters starting.
SMA Logger --- Configuration: Expected devices '2'.
SMA Logger --- Configuration: Restart device detection if online devices count '1'.
SMA Logger --- Configuration: Channel max value age in seconds '20'.
SMA Logger --- Configuration: Channel update interval in seconds '20'.
SMA Logger --- Configuration: YASDI ini path '/etc/sma_logger/sma.ini'.
SMA Logger --- Configuration: MQTT host 'mos'.
SMA Logger --- Configuration: MQTT port '1883'.
SMA Logger --- Configuration: MQTT username 'xxx'.
SMA Logger --- Configuration: MQTT password 'xxx'.
SMA Logger --- Configuration: MQTT keep alive seconds '10'.
SMA Logger --- Configuration: MQTT topic prefix 'Solar/Inverters'.
SMA Logger --- MqttClient: trying to connect, waiting ...
SMA Logger --- MQTT client init: Success.
SMA Logger --- MQTT client connect: Success.
SMA Logger --- Master: Detecting devices.
SMA Logger --- YASDI Master start: Success.
SMA Logger --- Master: Discovered device 'WR34MS03 SN:xxx'.
SMA Logger --- Master: Updating 1 devices requesting a max channel value age of 20 seconds.
SMA Logger --- Master: Discovered device 'WR34MS03 SN:xxx'.
SMA Logger --- Master: Device detection finished.
pkwagner commented 4 years ago

Solved the issue by myself. The process starves if the device detection duration exceeds the update interval, which is the case when running the tool for the first time (downloading channel lists takes up to several minutes). Therefore fixing it shouldn't be that hard.

I'm currently preparing a MR addressing the bug (and a few other) so that I can close this issue.

konstantinblaesi commented 4 years ago

Cool, thanks! There are most likely bugs and other shortcomings that I'd like to fix, but haven't gotten around to or had the knowledge to do myself so far. I also want to add some level testing in the future. I have other open topics/questions like

In my current setup I restart the docker container each night as a quick fix, because it would otherwise fail to resume it's work the next morning. This bug is most likely related to the way I deal with offline devices as well.

pkwagner commented 4 years ago

Thanks for sharing! From what I've seen, the whole YASDI library is a big mess - lots of dated documentation and unpredictable behaviour.

I'm still not sure if it's easier for me to fix issues here or to start over with a completely new project - not because your implementation was bad, but I found it very hard to get into such a undocumented library like YASDI without writing code myself. Either way, I'll let you know!

konstantinblaesi commented 4 years ago

Right, but wouldn't that project again depend on YASDI? I don't know any other option besides replacing the inverters with ones that have more modern interfaces :D Have you seen these YASDI docs? YASDI API-Documentation (german) YASDI Documentation (english) I am wondering if I it would have been any better if I used the synchronous YASDI API instead of the asynchronous one. Other projects out there using the YASDI sdk use the synchronous API.

pkwagner commented 4 years ago

Sorry for the late answer! The linked documentation is definitely newer than what I've found on the official SMA page.

Nevertheless I used the last few days to implement an own solution called yasdi2mqtt[1]. The container now runs for 3 days including devices going online/offline without crashing or any other problems, so I think the main work is done now.

Regarding your device removal problem I found out, that at least for the serial driver YASDI_EVENT_DEVICE_REMOVED[2] only fires after invoking RemoveDevice(...) manually. Therefore you have to detect device disconnections by your own, the best solution I've found is to remove a device whenever value fetch returns a YE_TIMEOUT[3].

[1] https://github.com/pkwagner/yasdi2mqtt [2] https://github.com/pkwagner/yasdi2mqtt/blob/master/src/yasdi_handler.c#L278 [3] https://github.com/pkwagner/yasdi2mqtt/blob/master/src/yasdi_handler.c#L205