jbuehl / solaredge

SolarEdge inverter logging data capture
GNU General Public License v3.0
288 stars 60 forks source link

semonitor.py does not always produce valid JSON #166

Open ocaj-nl opened 2 years ago

ocaj-nl commented 2 years ago

This week both of my inverters were replaced (turns out the old ones couldn't handle a brief <1sec. encounter with 230V on the RS485-lines, don't ask how I know :-( ).

I have been using your code since 2016 with my pre-HD inverters. The new inverters are of the HD-type with no display ("SetApp"-series). I configured them to communicate monitoring information over the RS485-1 and fired up semonitor.py with the new serial-numbers, expecting it to "just work".

At first this seemed to be the case. However, shortly after I ran into a problem that the JSON-output couldn't be parsed and is said to be malformed. I pipe the JSON-output into a Perl-script of my own making that makes sure everything is logged in MySQL.

Diving into the issue it appears that while my old inverters always reported Pmax as 6000, my current inverter has no value for PMax and Python outputs NaN. Although NaN is valid Javascript, it is not valid JSON. I found it hard to beleive, but the standard Python JSON-encoder does not seem to generate valid JSON (see https://stackoverflow.com/questions/28639953/python-json-encoder-convert-nans-to-null-instead for some discussion on this topic). This NaN-value seems to only occur for the inital data of the first few hours, perhaps this was data generated before the intaller had completed the commissioning? After that it always reports a fixed value of 11000. As it is a fixed value anyway, I don't care to log it.

I have implemented a workaround by converting the JSON-output before parsing it, but the correct thing to do would be for semonitor.py to produce valid JSON as output, for which I make this issue.

As a side-note: In the output of the new inverters I see a lot of "Unknown_device"-data. I started reading the README.ParseDevice, but that's "slightly" over my head, starting with the fact that I'm no Python-expert. For now I am receiving the inverter-data as well as the optimizers-data, which are my main priorities. If anyone is interested in figuring out what additional information is now available I'm happy to share some recordings. I did a quick look at some of the Unciphered data and there are quite some readable strings with some kind of status-information of the OS running on the inverter (Memory Free, Data Partition free, Cell signal, Wifi-MAC-address, stuff like that).