# How to get data with JSON from inverter

**URL:** <https://discourse.nodered.org/t/how-to-get-data-with-json-from-inverter/31984>\
**Category:** General\
**Created:** [25 August 2020 11:04 UTC](https://discourse.nodered.org/t/how-to-get-data-with-json-from-inverter/31984 "2020-08-25T11:04:53Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![rguita](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@rguita](https://discourse.nodered.org/u/rguita)\
**Post date:** [25 August 2020 11:04 UTC](https://discourse.nodered.org/t/how-to-get-data-with-json-from-inverter/31984/1 "2020-08-25T11:04:53Z")

</div>

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](http://discourse.nodered.org/t/how-to-send-a-post-request-with-content/15537)) post. The "Manufacturer" realesed a guide ([http://files.sma.de/dl/2585/SWebBoxRPC-BA-en-14.pdf](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

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [25 August 2020 12:12 UTC](https://discourse.nodered.org/t/how-to-get-data-with-json-from-inverter/31984/2 "2020-08-25T12:12:07Z")

</div>

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.

 ![Screenshot_2020-08-25 Node-RED 192 168 1 160](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/e/1eca6654acd92c24ba003defc7d57aa447e5c64c.png)

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![rguita](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@rguita](https://discourse.nodered.org/u/rguita)\
**Post date:** [25 August 2020 12:40 UTC](https://discourse.nodered.org/t/how-to-get-data-with-json-from-inverter/31984/3 "2020-08-25T12:40:02Z")

</div>

Hi UnborN,

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

regards,

Ricardo Guita

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [25 August 2020 12:45 UTC](https://discourse.nodered.org/t/how-to-get-data-with-json-from-inverter/31984/4 "2020-08-25T12:45:13Z")

</div>

You have to import the flow in Node-red  
Details on how to do that can be found [here](https://nodered.org/docs/user-guide/editor/workspace/import-export)

The inject node is there just to trigger the http request

---

<div class="post-metadata">

**Author:** ![rguita](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@rguita](https://discourse.nodered.org/u/rguita)\
**Post date:** [25 August 2020 12:46 UTC](https://discourse.nodered.org/t/how-to-get-data-with-json-from-inverter/31984/5 "2020-08-25T12:46:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [25 August 2020 12:55 UTC](https://discourse.nodered.org/t/how-to-get-data-with-json-from-inverter/31984/6 "2020-08-25T12:55:11Z")

</div>

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](https://www.youtube.com/watch?v=ksGeUD26Mw0&list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6)

Can you send us a screenshot of the error ?

---

<div class="post-metadata">

**Author:** ![rguita](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@rguita](https://discourse.nodered.org/u/rguita)\
**Post date:** [25 August 2020 13:06 UTC](https://discourse.nodered.org/t/how-to-get-data-with-json-from-inverter/31984/7 "2020-08-25T13:06:53Z")

</div>

![imagem](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/1/21366f1b6215537c2c5a9317e9bd899bf71e0bf4.png)

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

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [25 August 2020 13:37 UTC](https://discourse.nodered.org/t/how-to-get-data-with-json-from-inverter/31984/8 "2020-08-25T13:37:13Z")

</div>

Try replacing the **function node** code with this :

```auto
//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;

```

---

<div class="post-metadata">

**Author:** ![rguita](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@rguita](https://discourse.nodered.org/u/rguita)\
**Post date:** [25 August 2020 17:13 UTC](https://discourse.nodered.org/t/how-to-get-data-with-json-from-inverter/31984/9 "2020-08-25T17:13:14Z")

</div>

Hi,

Here the working code:

```auto
[
    {
        "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]

---

<div class="post-metadata">

**Author:** ![rguita](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@rguita](https://discourse.nodered.org/u/rguita)\
**Post date:** [25 August 2020 17:14 UTC](https://discourse.nodered.org/t/how-to-get-data-with-json-from-inverter/31984/10 "2020-08-25T17:14:02Z")

</div>

Thanks for your help UnborN.

regards,

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [25 August 2020 17:43 UTC](https://discourse.nodered.org/t/how-to-get-data-with-json-from-inverter/31984/11 "2020-08-25T17:43:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [24 October 2020 17:43 UTC](https://discourse.nodered.org/t/how-to-get-data-with-json-from-inverter/31984/12 "2020-10-24T17:43:25Z")

</div>

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