I am trying to extract information from my Fronius solar inverter. I can issue an HTTP request using by PV System ID, and it returns a single-line string as such:
I am trying to manipulate this string so I can break out the relevant components into individual variables.
In SharpTools, I can issue the HTTP GET request successfully, but I canât work out how to get the whole string (or the components) into a variable.
$context.response.status returns 200 showing that the command executed successfully.
When I select Variable->Context Variable->Response->HTTP->Response Data, it then asks me to input an object.property. Typing the variable names in the string (e.g. âP_PVâ) doesnât work, and I canât seem to just ask for the whole thing. How do I get the whole string?
I have tried using (), ââ, #, * and any other version of a null I can think of.
As a test, I just took the payload from your first post and put it into a GitHub Gist to simulate the response (intentionally causing it to have an incorrect âtextâ content type to test that too) and the rule executed as expected:
(I used a random numeric variable I had tested with in the past to store the P_PV value. $AATmp is a text variable to store the raw response.)
If youâre still having difficulty, feel free to send a note to support@sharptools.io with the Rule ID and I would be happy to take a closer look with you.
Thank you Josh. I have worked it out. Using the expression $context.response.data I was able to see that it was not, in fact, returning the XML string, rather the default Fronius webpage.
I needed to add a cookie from my login as a header in the GET request so it new it was me. Now working as expected.
Hi Josh, is it possible to extract the values from the text variable once you have stored the http response there? In your example above, how would you parse the P_PV value form variable $AATmp?
I have managed to do it with a nested round(mid($TmpResponse,indexOf($TmpResponse,âP_PVâ)+7,6)) expression. Was just wondering if there were a simpler way to parse out the variables.
Hi Mike - thanks for sharing your solution. Another approach would be to parse the stored data back into an object so you can reference the value directly using parseJson().
The challenge with using substrings is the position and length of the content might change. It looks like you solved the position part of things with the indexOf() method (nice move!) which leaves you with the potential for the length of the content to change.