Skip to content
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

nrg / Json Ouput does not work! #6

Open
Lightning1984 opened this issue Nov 7, 2021 · 2 comments
Open

nrg / Json Ouput does not work! #6

Lightning1984 opened this issue Nov 7, 2021 · 2 comments

Comments

@Lightning1984
Copy link

Lightning1984 commented Nov 7, 2021

Hi @En3rGy,

I imported release 0.5 but that seemingly did not have JSON output for the "nrg" field enabled yet as mentioned here:
#4
So i downloaded and built the latest source version from github.

The JSON field was available in the Logic Module but was not populated with any data.
When looking at the code I found that the function to set the output field was not there:

if 'nrg' in json_state:
nrg = json_state['nrg']
nrg_curr = (int(nrg[4]) + int(nrg[5]) + int(nrg[6])) / 10
self._set_output_value(self.PIN_O_N_NRG_CURR, nrg_curr)
nrg_json = {"V L1": nrg[0], "V L2": nrg[1], "V L3": nrg[2], "V N": nrg[3], "A L1": nrg[4] / 10.0, "A L2": nrg[5] / 10.0,
"A L3": nrg[6] / 10.0, "kW L1": nrg[7] / 10.0, "kW L2": nrg[8] / 10.0, "kW L3": nrg[9] / 10.0, "kW N": nrg[10] / 10.0,
"kW Sum": nrg[11] / 100.0, "P% L1": nrg[12], "P% L2": nrg[13], "P% L3": nrg[14], "P% N": nrg[15]}
if 'fwv' in json_state:

after line 253 one would need
self._set_output_value(self.PIN_O_NRG_JSON, json.dumps(nrg_json))

Unfortunately it looks like the string fields are limited in length in the Module so the data gets cut short. To overcome this issue I split the field into 3 individual Fields:
https://github.com/En3rGy/14105_go-eCharger/compare/main...Lightning1984:patch-1?expand=1

Now the data is correctly exported in JSON format and can be further evaluated with e.g. the JSON Parser.

regards

@En3rGy
Copy link
Owner

En3rGy commented Nov 8, 2021

What did you to to figure out that the output json is truncated?
As far as I know: If you put the output to an 14-Byte text variable, it'll be tuncated after 14 byte but if you directly forward it into an other logic module, it should be processed completely.

@Lightning1984
Copy link
Author

Lightning1984 commented Nov 11, 2021

Hi,

I'm feeding the json data directly into JSON-Parser(11087).
In the logic editor I used the worksheet monitoring function to debug the module.
Initially as mentioned the Output "nrg / json" was completely empty, then I tried to insert
self._set_output_value(self.PIN_O_NRG_JSON, str(nrg_json)), the output did now show values but was truncated in the worksheet monitor in the ouput as well as in the input of the JSON Parser module, but showed more than 14 Byte. Additionally the JSON parser module did not successfully parse any data even if I used a key which i could see in the truncated data.

I assumed that it was due to the truncated output, so split the data into 3 separate fields. But the JSON-Parser still wasn't working. I noticed that instead of double quotes (") single quotes (') where put out which is not according to JSON specification. (e.g. {'V L1': 230.0})

Only after replacing the string with the json.dumps function in the output it started to work.
self._set_output_value(self.PIN_O_NRG_JSON_POWERFACTOR, json.dumps(nrg_json_powerfactor))

What i did not test anymore is if the truncated output would be processed correctly internally using the json.dumps() function instead of the str() function.

regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants