How to get data with JSON from inverter

I~m pretty new with programming languages, Nod red and JSON.
I want to get data from a SMA Webbox with "JSON". I already created a couple of nodes (inject node -> change node -> http request node -> debug) has per [Cybertron](https : // How to send a post request with content) post. The "Manufacturer" realesed a guide (http://files.sma.de/dl/2585/SWebBoxRPC-BA-en-14.pdf) where it says that teh request should be in the following form:

RPC={
"version": "1.0",
"proc": "GetPlantOverview",
"id": "1",
"format": "JSON" }

Also the URL for all requests is: http : // IP address/rpcThe IP address in each case is the currently configured IP address of the Sunny WebBox. The default setting is 192.168.0.168.Hence, the default URL is the following: http: // 192.168.0.168/rpcThe request is transmitted via HTTP POST in the body of the HTTP request as a serialized JSON object according to the conventions established in Section 4.1.

Can somebody give me some light? Any clues how to achieve the goals...

Appreciate for some help.

Ricardo

Hi Ricardo,

Try this .. we use an inject node .. to triger a function node that sets up a http post request node .. and we get the result in debug.

[{"id":"5650b8fb.a434","type":"http request","z":"9f2f6aea.6d2be","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":630,"y":900,"wires":[["e576fd9b.022f98"]]},{"id":"e576fd9b.022f98","type":"debug","z":"9f2f6aea.6d2be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":850,"y":900,"wires":[]},{"id":"10c5cdd5.0cf0da","type":"inject","z":"9f2f6aea.6d2be","name":"read","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"","payloadType":"date","x":250,"y":900,"wires":[["6cff2930.174fe8"]]},{"id":"6cff2930.174fe8","type":"function","z":"9f2f6aea.6d2be","name":"http post config","func":"\nmsg.headers = {}\nmsg.method = \"POST\"\nmsg.url = \"http://192.168.0.168/rcp\";\nmsg.headers[\"content-type\"] = \"application/json\"\n\nmsg.payload = {\n\"version\": \"1.0\",\n\"proc\": \"GetPlantOverview\",\n\"id\": \"1\",\n\"format\": \"JSON\" }\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":430,"y":900,"wires":[["5650b8fb.a434"]]}]

Hi UnborN,

Thanks for the quick reply. Where should try the code, in the inject node? Sorry for my nobby question.

regards,

Ricardo Guita

You have to import the flow in Node-red
Details on how to do that can be found here

The inject node is there just to trigger the http request

Did the import but some errors poped up

Sunny WebBox




File ExpectationFailed

BuildAndSendResponse
file: temp\wwwroot\
BuildAndSendResponse failed


ERROR

The actual value didn came up

Thanks

You imported the flow and then you 'Deploy' ?

If you are just starting Node-red i would recommend going through some really good video tutorials HERE

Can you send us a screenshot of the error ?

imagem

Hi UnborN,

Yes I did the Deploy, but it seems that the connection didn´t worked has it should. I alsow changed the IP address of my device (Webbox).

regards,

Ricardo

Try replacing the function node code with this :

//msg.headers = {}
msg.method = "POST"
msg.url = "http://192.168.0.168/rcp";
//msg.headers["content-type"] = "application/json"

msg.payload = 'RPC={"version": "1.0","proc": "GetPlantOverview","id": "1","format": "JSON" }'

return msg;

Hi,

Here the working code:

[
    {
        "id": "f85209eb.14f638",
        "type": "function",
        "z": "6ca02d32.524864",
        "name": "http post config",
        "func": "\n//msg.headers = {}\nmsg.method = \"POST\"\nmsg.url = \"http://192.168.60.14/rpc\";\n//msg.headers[\"content-type\"] = \"application/json\"\n\nmsg.payload = 'RPC={\"version\": \"1.0\",\"proc\": \"GetPlantOverview\",\"id\": \"1\",\"format\": \"JSON\" }'\n\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 380,
        "y": 260,
        "wires": [
            [
                "5c7994b4.af895c"
            ]
        ]
    }
]

[Edited to format correctly]

Thanks for your help UnborN.

regards,

You are welcome .. so im guessing it worked ?

by the way when you paste code in the forum .. paste it using the < / > icon so it gets formatted correctly. As it is now i cannot import your flow

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.