Variable over http and push message

[code]local command = “wget -q -T=30 -t 10 -O /dev/null ‘http://IP/arduino/sensor/1’”
local tempString = io.popen(command)
local temp=tonumber(tempString)

if temp > 20.5
luup.call_action(“urn:intvelt-com:serviceId:HWPush1”, “SendMessage”, {Msg = … tempString … }, 274)

It always fails. The reading seems to be good but the “if” is always false. Furthermore the message won’t send the actual value.

Thanks for any help

I think you should investigate just what is being returned in tempString. You could try logging it:

luup.log("tempString: " .. tostring(tempString))

Also I have noticed that Vera has an issue with the way you have written your if statement. Try:

if temp > 20.5 then luup.call_action("urn:intvelt-com:serviceId:HWPush1", "SendMessage", {Msg = .. tempString .. }, 274) end

Thanks I will have to check a lot of code for if…then.

What do you think about this:

luup.log("tempString: " .. tostring(tempString)) <0x31dc9680>

What do you think about this: Code: [Select] luup.log("tempString: " .. tostring(tempString)) <0x31dc9680>

What was the actual log message? Did it include the word table?

I just used scp to copy the log and this was the last line, so yes.

If the log entry looked like this:

50 04/06/14 11:31:11.701 luup_log:0: tempString: table: 0x1da8498 <0x31feb680>

Then you will need to figure-out the structure of the table so you can extract the data you want. If it was me, I would do it using LuaTest and print(pretty(tempString))

No idea what do do now.

It always worked with this:

local http = require("socket.http") http.TIMEOUT = 5 local status, result = http.request("")

But since Vera crashes because of that command ::slight_smile: I choose this way. But I need the content of the page (int or string).

But since Vera crashes because of that command..

That command will not cause Vera to crash - but - it adds another ongoing activity and may well tip an overloaded system into a deadlock. This can easily happen when there are multiple simultaneous run actions in progress.

Ok, but what should I do? I have 24 MB of free memory…

Seriously my computer doesn’t crash just because it is using 100 % of the CPU.

Looking at the log for the two minutes before a crash should show you what is happening. Problems will occur if there are plugins using run actions that take longer than a few milliseconds. The run queue is limited and, if Vera is unable to execute actions, it can gridlock and force a restart. Plugin actions that go beyond setting a few variables should use job processing.

Scenes that suspend waiting for I/O just add to the probability of gridlock.

If you want to use [tt]io.popen[/tt], it works like this:

[code]local handle = io.popen(‘ls -l /’)
local result = handle:read("*a")

print (result)


This will work, freestanding, in a .lua file. In my case, I wrote it in test.lua, and ran it with the command line version of Lua (since it has no Vera dependencies)


root@MiOS_3000eieio:~# lua test.lua drwxr-xr-x 2 root root 757 Feb 22 2013 bin drwxr-xr-x 4 root root 1420 Apr 6 08:41 dev drwxr-xr-x 1 root root 0 Apr 6 06:00 etc -rw-r--r-- 1 root root 136369 Apr 6 08:42 foo drwxr-xr-x 1 root root 0 Feb 22 2013 lib ...

I’m using “[tt]ls[/tt]” instead of your “[tt]wget[/tt]” command, but the Lua code is the same, since they’re both just processes.

Ok, looks promising, but how could I include this in a scene?

local handle = io.popen(“wget -q -T=30 -t 10 -O /dev/null ‘http://IP/arduino/sensor/1’”)
local result = handle:read("*a") --???

print (result)


Could I use handle in the scene? And is handle in my case the temperature 22.0?

This is the snippet of code that fetches the value, just to show you how to use [tt]io.popen()[/tt]. The “result” of that call is put into a variable called result, which is a string value of whatever the OS command returned (in this case, a directory listing, but you’d call [tt]wget[/tt] instead)

It’s written in pure Lua, so it can be run from the command line so you can test/try/understand it independently of Vera. You will need to merge the snippet with the rest of your scene-logic.

Since that’s trivial, I didn’t bother with that part.

The [tt]handle:read()[/tt] call that’s in there is the bit that’s pulling in the output of the command that’s executed. The parameter, [tt]"*a"[/tt], simply tells read to pull in all the data into one [string] response.

There are loads of snippet-based examples like this on, and on

These cover every generic topic you can imagine for learning Lua as a language. This is generally a first step before trying to understand the nuances of the Luup extensions that Vera adds.