Using Curl (HTTP request) to get some data from other application (DomotiGa).

3,938 views
Skip to first unread message

Alco van Neck

unread,
Jul 9, 2015, 5:49:48 AM7/9/15
to node...@googlegroups.com

Hi,

I'm starting to use Node-Red and already made some fancy flows from my local EmonCMS Server (Energy monitor) to Twitter by using JSON strings.

Now I have an other great application, DomotiGa and I can get data with CURL from this. Like this command line example:
curl -X POST -d '{"jsonrpc": "2.0", "method": "astro.get", "id": 1}' -H "Content-Type: application/json" -H "Accept: application/json"   http://localhost:9090

It returns some local astro and location data, nicely at an JSON string.
But now I want to use it in Node-Red.

I made a simplistic flow with 3 objects, a time stamp, a http IN and a debugnode : flow export >

[{"id":"efad9064.10527","type":"http request","name":"test","method":"POST","ret":"obj","url":"curl -d '{\"jsonrpc\": \"2.0\", \"method\": \"astro.get\", \"id\": 1}' -H \"Content-Type: application/json\" -H \"Accept: application/json\"   http://localhost:9090","x":318,"y":238,"z":"216dbbe9.de9244","wires":[["7948c48.f86b73c"]]}]

I can't get it working ?  I get this ENOTFOUND error back. (node-red is on one server with the DomotiGa application..)
Error: getaddrinfo ENOTFOUND : http://curl -d '{"jsonrpc": "2.0", "method": "astro.get", "id": 1}' -H "Content-Type: application/json" -H "Accept: application/json" http://192.168.1.115:9090


something wrong in the command box? I tried several things (removing, the -X and POST in the string..) but no luck...

Do you know whats wrong?

Thanks!

Nicholas O'Leary

unread,
Jul 9, 2015, 6:07:50 AM7/9/15
to Node-RED Mailing LIst
HI,

the 'url' box of the HTTP Request node isn't a 'command box' for you to specify a random command for the node to run (we have the Exec node for that sort of thing) - it is where you provide the url you want to send a request to.

Here's a flow that I think does what you want:

[{"id":"9adcce24.65233","type":"inject","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":126,"y":71,"z":"6af0c717.950f38","wires":[["e1b33f63.1e4cc"]]},{"id":"e1b33f63.1e4cc","type":"function","name":"","func":"msg.payload = {\n    \"jsonrpc\": \"2.0\",\n    \"method\":\n    \"astro.get\",\n    \"id\": 1\n};\n\nmsg.headers = {\n    Accept: \"application/json\"\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":271,"y":89,"z":"6af0c717.950f38","wires":[["178423e4.e87bdc"]]},{"id":"178423e4.e87bdc","type":"http request","name":"","method":"POST","ret":"obj","url":"http://192.168.1.115:9090","x":446,"y":95,"z":"6af0c717.950f38","wires":[["70d01c46.8f2fe4"]]},{"id":"70d01c46.8f2fe4","type":"debug","name":"","active":true,"console":"false","complete":"false","x":643,"y":85,"z":"6af0c717.950f38","wires":[]}]


--
http://nodered.org
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alco van Neck

unread,
Jul 9, 2015, 7:14:00 AM7/9/15
to node...@googlegroups.com
Nicely done,

Your function works out of the box, I'm really happy because DomotiGa can put almost every thing to a JSON-RPC string and now I'm able to get it to Node-Red and do some analytics and logics with it.
Thanks!

msg.payload = {

   
"jsonrpc": "2.0",
   
"method":
   
"astro.get",
   
"id": 1
};

msg
.headers = {
   
Accept: "application/json"
}

return msg;




Op donderdag 9 juli 2015 12:07:50 UTC+2 schreef Nicholas O'Leary:
Reply all
Reply to author
Forward
0 new messages