The Vera Community forums have moved!

Advanced => Programming => General => Topic started by: avalon on April 13, 2018, 05:46:17 am

Title: Sending data through HTTP protocol
Post by: avalon on April 13, 2018, 05:46:17 am
Hello, I'm new to lua language so I'm having a lot of trouble for something that can be done easily maybe.
I have a Vera Plus controller and I want to send data of my power consumption from the controller to a web platform (Node-Red) through HTTP protocol.
I read some posts, and basically I know how to get a variable but I don't understand how can I send the data to the other platform. Can someone help me?

(I'm not a native speaker, so I'm sorry for my bad english)
Title: Re: Sending data through HTTP protocol
Post by: tinman on April 13, 2018, 10:40:08 am
I'm not well versed in http but it seems to me that it might be easier to pull the data you want instead of sending it from Vera. Take a look at the variableget information here: http://wiki.micasaverde.com/index.php/Luup_Requests
Title: Re: Sending data through HTTP protocol
Post by: jswim788 on April 13, 2018, 11:57:09 am
If you want to push the data from Vera to your server over http, you need to know how the server wants to receive the data.  Probably it wants a POST request?  You can do GET or POST from Lua fairly easily (GET is the easiest).  But you need to know what your server expects, then it is probably not too hard to get Vera to accommodate it.

Or pull the data as @tinman suggested.
Title: Re: Sending data through HTTP protocol
Post by: avalon on April 17, 2018, 03:37:51 am
Sorry for being silent, I was sick this weekend, but thanks for the reply.

I want to do a project for my home school and for security reasons they don't want more items connected on their own lan. (And I could not know the ip address of the Vera controller)
For the live demo I'm gonna use a 4G modem and push the data on Node-Red, so POST or GET requests are fine for me.
I've searched some post regarding this, but I'm not able to do POST or GET requests, so if someone can help me I really appreciate it.

Thanks in advance and have a nice day.
Title: Re: Sending data through HTTP protocol
Post by: jswim788 on April 17, 2018, 11:43:32 am
Do you have a sample of the http request you want to make?  This page documents the call for the GET request: http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_wget

What have you tried and how did it fail?
Title: Re: Sending data through HTTP protocol
Post by: avalon on April 18, 2018, 04:59:15 am
I was trying something like this

luup.inet.wget("ip?Status=0&usr=usr&pwd=pwd")

But doesn't work.
I'm sure it's my fault since i don't know much, but I'm not able to solve this alone, so thanks for the help.
Title: Re: Sending data through HTTP protocol
Post by: reneboer on April 18, 2018, 05:36:24 am
Hi,

For the wget command you need to specify the complete URL. I.e. something like "http://ip?Status=0..."

And as it's name implies it only supports a HTTP Get request. If you need Post request you will need to write that in LUA using the http library. You can find an example here https://github.com/reneboer/openLuup-CarNet/blob/master/src/L_CarNet1.lua (https://github.com/reneboer/openLuup-CarNet/blob/master/src/L_CarNet1.lua).

Cheers Rene