Hi all,
below is a trace ( I do not know if this is the correct name because in principle I have no clue about programming with Linux, Perl, Curl and so on and, in addition, English is not my native language... ) of some curl commands used to login to my EV Charger (type SMA EV Charger) and to read out some data. This trace is copied from my Rasperry Pi 2B shell running with Raspberry Pi OS Bullseye.
The code for these commands is based on devices / modules created for FHEM (fhem.de), a GPL'd perl server for house automation.
One problem for me is, that PERL is an anathema for me!
My goal is to achieve this (connect to the SMA EV Charger and get data) with Node-RED where I am already using the sma-webconnect node to get data from my SMA PV (solar) inverter.
Actually I am only interested in getting a few data (like the value of "Measurement.ChaSess.WhIn", "Measurement.Operation.EVeh.Health", "Measurement.Operation.Health" and "Measurement.Operation.Evt.Msg") and to use it for a chart or a pushover notification on my smartphone.
Can somebody help me to implement this in Node-RED?
Is it in general possible to use a function node with some JavaScript code?
And can somebody help me in writing this code?
Or do I need a HTTP request node?
And can somebody help me to configuring this node?
I wish you all a Happy New Year and I hope for some helpful feedback!
Kind regards
Thomas
CURL COMMAND LOGIN:
curl -i -s -k -X 'POST' -H 'Host: 192.168.178.87' -H 'Connection: close' -H 'Accept: application/json, text/plain, */*' -H 'User-Agent: okhttp/3.10.0' -H 'Sec-Fetch-Site: same-origin' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Dest: empty' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7' -H 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8' -H 'Content-Length: 56' -H 'Origin: https://192.168.178.87' -H 'Referer: https://192.168.178.87/webui/login' --data-binary 'grant_type=password&username=<USERNAME>&password=<PASSWORD>' https://192.168.178.87/api/v1/token
CURL RESPONSE TOKEN:
HTTP/1.1 200 OK
Connection: close
Date: Sat, 08 Jan 2022 19:55:36 GMT
Access-Control-Allow-Origin: https://192.168.178.87
Access-Control-Allow-Credentials: true
Cache-Control: no-cache,no-store,must-revalidate
Pragma: no-cache
Cache-Control: no-store
Set-Cookie: JSESSIONID=node0vpbqavqu641o1v3a9s5pe7qbi509.node0;Path=/;Secure;HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: application/json
{"access_token":"eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2NDE2NzE3MzYsInN1YiI6IldCQWRtaW4iLCJ1aWQiOiJkYThmNzMxNi1kZmUxLTQzNjMtODU2Yi0yZmI5YjMwNzJkNTAiLCJleHAiOjE2NDE2NzUzMzZ9.EOUQkXk9Fw7vhZeFE-2TFxHqoNv5fJZo7CXs7H-be6o","expires_in":3600,"refresh_token":"eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2NDE2NzE3MzYsInN1YiI6IldCQWRtaW4iLCJ1aWQiOiJkYThmNzMxNi1kZmUxLTQzNjMtODU2Yi0yZmI5YjMwNzJkNTAiLCJleHAiOjE2NDE3NTgxMzYsInR5cGUiOiJyZWZyZXNoIn0.v4OPHTvTHy050-PTVtKhBFWkKahYTtCHOUN2iRcyEKs","token_type":"bearer","uiIdleTime":"60"}
CURL COMMAND LIVE DATA
curl -i -s -k -X 'POST' -H 'Host: 192.168.178.87' -H 'Connection: close' -H 'Accept: application/json, text/plain, */*' -H 'User-Agent: okhttp/3.10.0' -H 'Sec-Fetch-Site: same-origin' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Dest: empty' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7' -H 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8' -H 'Content-Length: 30' -H 'Referer: https://192.168.178.87/webui/login' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2NDE2NzE3MzYsInN1YiI6IldCQWRtaW4iLCJ1aWQiOiJkYThmNzMxNi1kZmUxLTQzNjMtODU2Yi0yZmI5YjMwNzJkNTAiLCJleHAiOjE2NDE2NzUzMzZ9.EOUQkXk9Fw7vhZeFE-2TFxHqoNv5fJZo7CXs7H-be6o' -b 'node03v08nb30tz041fqxrsfye75cv502.node0' --data-binary '[{"componentId":"IGULD:SELF"}]' https://192.168.178.87/api/v1/measurements/live/
CURL RESPONSE LIVE DATA:
HTTP/1.1 200 OK
Connection: close
Date: Sat, 08 Jan 2022 19:58:08 GMT
Cache-Control: no-cache,no-store,must-revalidate
Content-Type: application/json
[{"channelId":"Measurement.ChaSess.WhIn","componentId":"IGULD:SELF","values":[{"time":"2021-12-31T11:49:35.404Z","value":0}]},{"channelId":"Measurement.Chrg.ModSw","componentId":"IGULD:SELF","values":[{"time":"2021-12-30T12:02:15.161Z","value":4950}]},{"channelId":"Measurement.GridMs.A.phsA","componentId":"IGULD:SELF","values":[{"time":"2022-01-08T19:58:08.460Z","value":0}]},{"channelId":"Measurement.GridMs.A.phsB","componentId":"IGULD:SELF","values":[{"time":"2022-01-08T19:58:08.461Z","value":0}]},{"channelId":"Measurement.GridMs.A.phsC","componentId":"IGULD:SELF","values":[{"time":"2022-01-08T19:58:08.461Z","value":0}]},{"channelId":"Measurement.GridMs.Hz","componentId":"IGULD:SELF","values":[{"time":"2022-01-08T19:58:04.369Z","value":50}]},{"channelId":"Measurement.GridMs.PhV.phsA","componentId":"IGULD:SELF","values":[{"time":"2022-01-08T19:58:04.368Z","value":230.839}]},{"channelId":"Measurement.GridMs.PhV.phsB","componentId":"IGULD:SELF","values":[{"time":"2022-01-08T19:58:04.369Z","value":231.695}]},{"channelId":"Measurement.GridMs.PhV.phsC","componentId":"IGULD:SELF","values":[{"time":"2022-01-08T19:58:04.369Z","value":231.074}]},{"channelId":"Measurement.GridMs.TotPF","componentId":"IGULD:SELF","values":[{"time":"2022-01-08T19:58:04.370Z","value":0}]},{"channelId":"Measurement.GridMs.TotVA","componentId":"IGULD:SELF","values":[{"time":"2022-01-08T19:58:04.369Z","value":0}]},{"channelId":"Measurement.GridMs.TotVAr","componentId":"IGULD:SELF","values":[{"time":"2022-01-08T19:58:04.369Z","value":0}]},{"channelId":"Measurement.InOut.GI1","componentId":"IGULD:SELF","values":[{"time":"2021-12-22T08:52:34.801Z","value":0}]},{"channelId":"Measurement.Metering.GridMs.TotWIn","componentId":"IGULD:SELF","values":[{"time":"2022-01-08T19:58:04.369Z","value":0}]},{"channelId":"Measurement.Metering.GridMs.TotWIn.ChaSta","componentId":"IGULD:SELF","values":[{"time":"2022-01-08T19:58:04.369Z","value":0}]},{"channelId":"Measurement.Metering.GridMs.TotWhIn","componentId":"IGULD:SELF","values":[{"time":"2022-01-08T19:58:04.316Z","value":505470}]},{"channelId":"Measurement.Metering.GridMs.TotWhIn.ChaSta","componentId":"IGULD:SELF","values":[{"time":"2022-01-08T19:58:04.316Z","value":505470}]},{"channelId":"Measurement.Operation.EVeh.ChaStt","componentId":"IGULD:SELF","values":[{"time":"2022-01-08T19:58:08.381Z","value":200111}]},{"channelId":"Measurement.Operation.EVeh.Health","componentId":"IGULD:SELF","values":[{"time":"2021-12-22T08:53:06.007Z","value":307}]},{"channelId":"Measurement.Operation.Evt.Msg","componentId":"IGULD:SELF","values":[{"time":"2021-12-31T11:49:35.466Z","value":302}]},{"channelId":"Measurement.Operation.Health","componentId":"IGULD:SELF","values":[{"time":"2021-12-31T11:49:35.466Z","value":307}]},{"channelId":"Measurement.Operation.WMaxLimSrc","componentId":"IGULD:SELF","values":[{"time":"2021-12-22T08:52:16.233Z","value":2608}]},{"channelId":"Measurement.Wl.ConnStt","componentId":"IGULD:SELF","values":[{"time":"2021-12-22T08:52:45.955Z","value":303}]},{"channelId":"Measurement.Wl.SigPwr","componentId":"IGULD:SELF","values":[{"time":"2021-12-22T08:52:45.956Z","value":0}]},{"channelId":"Setpoint.PlantControl.Inverter.FstStop","componentId":"IGULD:SELF","values":[{"time":"2021-12-28T22:23:30.583Z","value":1467}]}]