Can't get HTTP commands working from a lua script to vera

Hi all,

I search informations but don’t find.

I want to get a device variable from a lua script launch on my ubuntu server.

"http://XX.XX.X.X:49451/data_request?id=lu_variableget&outputformat=xml&DeviceNum=41&serviceId=urn:micasaverde-com:serviceId:EnergyMetering1&Variable=Watts"

the command line works in firefox whereas in my script I got null. so vera isn’t ok with my script.

Here is the code:

local http = require ("socket.http")
local req = "http://XX.XX.X.X:49451/data_request?id=lu_variableget&outputformat=xml&DeviceNum=41&serviceId=urn:micasaverde-com:serviceId:EnergyMetering1&Variable=Watts"
local result, status, content = socket.http.request(req)
print (result)
print (status)
print (content)

I got result nil, status is closed, content is nil

I try to send with “&” and “&” it doesn’t work.

What I know is if I don’t use & in other http request it’s working.

Someone have got an idea, please.

Gilles.

Perhaps it doesn’t really answer the question, but why not use luup.inet.wget ?

Using that function works fine on my Veras and you use an & rather than &

Hi mtf,

Thank you for your answer, but I don’t want to launch my script from vera2, I want to launch the lua script from my ubuntu server.

So luup.inet.wget could not be use as I’m not on vera.

Ooh, that’s weird. I needed Wireshark to figure that out.

Your request is going through fine. But the response is coming back as Chunked Transfer Encoding and it seems that luasocket doesn’t know how to decode it.

You can probably prevent Vera from using chunked transfer encoding with appropriate request header, bet that’s going to force you to use the messy LTN12 interface. Ick.

Maybe time to rethink the language you use? Perl, Python, shell script?

(Use & not & by the way. Ampersand encoding is for HTML, which this isn’t.)

[quote=“futzle, post:4, topic:170309”]Ooh, that’s weird. I needed Wireshark to figure that out.

Your request is going through fine. But the response is coming back as Chunked Transfer Encoding and it seems that luasocket doesn’t know how to decode it.[/quote]

I understand that vera don’t get the right message. Unfortunatly, I’m not the king of http interface.

I’m not sure to use it correctly, but I could try . I think ap15e do an example in the forum.

I prefer not use many languages. In my project, I already use lamp on ubuntu for my onewire temperature. As I do some lua code on my vera, I would use lua in ubuntu.

Do you think it’s a bad idea ? I prefer limit language as I’m not a developper. I know a little bit shell.

Your right I just see my error the output format isn’t xml.

Do you know how to procede ? As it’s linux shell could be cool.

Gilles.

As Usually Futzle you open my eyes.

I use this in bash script and it works:

#!/bin/bash

URL='http://XX.XX.XX.XX:49451/data_request?id=lu_variableget&DeviceNum=41&serviceId=urn:micasaverde-com:serviceId:EnergyMetering1&Variable=Watts'
RESULT=$(curl -sG $URL)
echo $RESULT

If you got better , I take.

Gilles.

Perfect. A shell script calling curl is probably what I would have done too.

Hi Futzle,
It’s cool, my bash evolved in a munin plugin. So I can monitor my home energy for years.

Thank you.

Gilles

Envoyé depuis mon GT-I9000 avec Tapatalk